Files
laws_chery_client/src/views/documentTool/documentSplit/modules/SplitDetailBatchEditDrawer.vue
T

498 lines
22 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<a-drawer
:title="title"
placement="right"
:visible="visible"
@close="handleCancel"
width="900"
destroyOnClose
class="custom-drawer-style">
<div class="custom-drawer-style-scroll">
<a-spin :spinning="confirmLoading">
<a-form-model :model="formInline" v-if="isFormInline" class="form-add" :rules="rules" ref="ruleForm">
<div class="form-flex-box">
<template v-for="(item, index) in dataList">
<div :key="index"
class="box-title-text form-flex-item"
:class="{'form-flex-item-line': item.fieldShowType === FieldType.STANDARD_MORE.value}"
v-if="!hiddenFieldList.includes(item.dbFieldName)">
<div class="title-text">
<span class="required" v-if="item.fieldMustInput === '1'">*</span>
<span class="title-text-text" :title="item.dbFieldTxt">{{ item.dbFieldTxt }}</span>
</div>
<a-form-model-item class="item-model" :prop="item.dbFieldName">
<!--条文解读-->
<!--<template v-if="item.dbFieldName === 'interpretation_articles'">-->
<!-- <div class="unscramble-item"-->
<!-- v-for="(unscramble, unscrambleIndex) in interpretationArticlesList"-->
<!-- :key="unscrambleIndex + 'interpretation_articles'">-->
<!-- <div class="unscramble-item-content">-->
<!-- &lt;!&ndash;文本&ndash;&gt;-->
<!-- <a-input type="textarea" :maxLength="500" v-model="unscramble.itemContent"/>-->
<!-- </div>-->
<!-- <div class="unscramble-item-operate">-->
<!-- <a-button @click="handleAddUnscramble(unscrambleIndex)">{{ $t('newlyAdded') }}</a-button>-->
<!-- <a-button @click="handleDeleteUnscramble(unscrambleIndex, unscramble)">{{ $t('delete') }}</a-button>-->
<!-- </div>-->
<!-- </div>-->
<!--</template>-->
<!-- 1, 日期单选 -->
<a-date-picker v-if="item.fieldShowType === FieldType.DATE_SINGLE.value"
class="box-input"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt + getPlaceholderSuffix(item)"
:getCalendarContainer="(trigger) => trigger.parentNode"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
v-model="formInline[item.dbFieldName]"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)"
style="width: 100%" />
<!-- 2, 单选用户 -->
<user-selection v-else-if="item.fieldShowType === FieldType.USER_SINGLE.value"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt + getPlaceholderSuffix(item)"
v-model="formInline[item.dbFieldName]"
:filedName="item.dbFieldName"
@nameChange="userSelectNameChange"
:nameStr="formInline[item.dbFieldName + '_dictText']"
type="radio"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)" />
<!-- 3, 单选组织机构 -->
<j-select-depart v-else-if="item.fieldShowType === FieldType.ORGAN_SINGLE.value"
v-model="formInline[item.dbFieldName]"
:backDepart="true" />
<!-- 4, 日期多选 -->
<j-multiple-date-picker v-else-if="item.fieldShowType === FieldType.DATE_MORE.value"
class="box-input"
v-model="formInline[item.dbFieldName]"
:fieldName="item.dbFieldName"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)" />
<!-- 5, 多行文本 -->
<a-textarea v-else-if="item.fieldShowType === FieldType.TEXTAREA.value"
:placeholder="$t('pleaseEnter')+item.dbFieldTxt + getPlaceholderSuffix(item)"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)"
:maxLength="item.dbLength || 500"
v-model="formInline[item.dbFieldName]" :rows="4" />
<!-- 6, 标准多选 -->
<standard-selection v-else-if="item.fieldShowType === FieldType.STANDARD_MORE.value"
:source="flag"
:disabledSourceSearch="true"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)"
v-model="formInline[item.dbFieldName]" />
<!-- 7, 多选组织机构 -->
<j-select-depart v-else-if="item.fieldShowType === FieldType.ORGAN_MORE.value"
v-model="formInline[item.dbFieldName]"
:multi="true"
:backDepart="true"
:treeOpera="true" />
<!-- 8, 上传文件 -->
<a-button v-else-if="item.fieldShowType === FieldType.FILE_UP.value" type="primary" class="button-text"
@click="clickButtonToUpload(item)">
{{
(formInline[item.dbFieldName] === 'null' || formInline[item.dbFieldName] === ''
|| formInline[item.dbFieldName] === null || formInline[item.dbFieldName] === undefined)
? $t('uploadFile.clickUpload')
: $t('uploadFile.viewUploadedFiles')
}}
</a-button>
<!-- 9, 文本框 -->
<a-input v-else-if="item.fieldShowType === FieldType.TEXT_BOX.value"
class="box-input"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)"
v-model="formInline[item.dbFieldName]"
:maxLength="item.dbLength || 50"
:placeholder="(specialPlaceholder[item.dbFieldName] || $t('pleaseEnter')+item.dbFieldTxt) + getPlaceholderSuffix(item)" />
<!-- 10, 下拉单选数据字典 -->
<j-dict-select-tag v-else-if="item.fieldShowType === FieldType.OPTION_SINGLE.value"
class="box-input"
v-model="formInline[item.dbFieldName]"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt + getPlaceholderSuffix(item)"
:type="radioDictSelect.includes(item.dbFieldName)? 'radio' : 'select'"
:triggerChange="false"
:dictCode="item.dictField" />
<!-- 11, 下拉多选数据字典 -->
<j-multi-select-tag v-else-if="item.fieldShowType === FieldType.OPTION_MORE.value"
class="box-input"
v-model="formInline[item.dbFieldName]"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt + getPlaceholderSuffix(item)"
:type="'select'"
:triggerChange="false"
:dictCode="item.dictField" />
<!-- 12, 树选择 -->
<s-tree-select
v-else-if="item.fieldShowType === FieldType.TREE.value"
v-model="formInline[item.dbFieldName]"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)"
:tree-data="optionsData[item.dbFieldName]"
tree-checkable
treeCheckStrictly
:label-in-value="false"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt + getPlaceholderSuffix(item)" />
<!-- 14, 年份选择 -->
<j-date v-else-if="item.fieldShowType === FieldType.YEAR_PICKER.value"
show-type="year"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)"
v-model="formInline[item.dbFieldName]"
:default-value="defaultValue[item.dbFieldName]"
date-format="YYYY"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt + getPlaceholderSuffix(item)" />
<!-- 15, 树选择单选 -->
<s-tree-select v-else-if="item.fieldShowType === FieldType.TREE_SINGLE.value"
v-model="formInline[item.dbFieldName]"
:getPopupContainer="triggerNode=> triggerNode.parentNode"
style="width: 100%"
:disabled="disabled || disabledFieldList.includes(item.dbFieldName)"
:tree-data="optionsData[item.dbFieldName]"
:label-in-value="false"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt + getPlaceholderSuffix(item)" />
<!--16树形弹框选择-->
<!--<tree-selection v-else-if="item.fieldShowType === FieldType.TREE_MODAL_SELECT.value || item.fieldShowType === FieldType.TREE_MODAL_SELECT_SEARCH_DIFF.value"-->
<!-- :placeholder="$t('pleaseSelect')+item.dbFieldTxt + getPlaceholderSuffix(item)"-->
<!-- v-model="formInline[item.dbFieldName]"-->
<!-- :filedName="item.dbFieldName"-->
<!-- type="checkbox"-->
<!-- :options-href="item.fieldHref"-->
<!-- :nameStr="formInline[item.dbFieldName + '_dictText']"-->
<!-- :dict-id="item.dictId"-->
<!-- :disabled="disabled || disabledFieldList.includes(item.dbFieldName)"-->
<!-- :children-column-name="getTreeSelectionChildrenColumnName(item)"-->
<!-- :is-tag-library-restriction="item.dbFieldName === 'property_tag'"-->
<!-- :search-field-name="item.dbFieldName === 'property_tag' ? 'firstNodeName' : null" />-->
<tree-data-selection v-else-if="item.fieldShowType === FieldType.TREE_MODAL_SELECT.value || item.fieldShowType === FieldType.TREE_MODAL_SELECT_SEARCH_DIFF.value"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"
v-model="formInline[item.dbFieldName]"
:fieldName="item.dbFieldName"
:nameStr="formInline[item.dbFieldName + '_dictText']"
@nameChange="treeDataSelectNameChange"
:optionsHref="item.treeFirstHref"
:dict-id="item.dictId"/>
</a-form-model-item>
</div>
</template>
</div>
<upload-file ref="uploadFile" @change="uploadFileChange" :return-url="false"></upload-file>
</a-form-model>
</a-spin>
</div>
<div class="custom-drawer-style-bottom-btn">
<!--取消-->
<a-button @click="handleCancel">{{ $t('cancel') }}</a-button>
<!--保存-->
<a-button type="primary" class="footer-btn-save" @click="handleSave">{{ $t('preservation') }}</a-button>
</div>
</a-drawer>
</template>
<script>
import JMultipleDatePicker from '../../../../components/JMultipleDatePicker.vue'
import UploadFile from '../../../../components/UploadFile.vue'
import StandardSelection from '../../../../components/selection/StandardSelection.vue'
import UserSelection from '../../../../components/selection/UserSelection.vue'
import { getDocSplitEditForm, editBatchEditClause } from '../../../../api/documentToolApi'
import { FieldType, YesOrNoEnum } from '../../../../enums/commonEnums'
import { getFormDictTreeList } from '../../../../api/api'
import { getAction } from '../../../../api/manage'
import STreeSelect from '../../../../components/STreeSelect'
import TreeSelection from '../../../../components/selection/TreeSelection'
import TreeDataSelection from '@comp/selection/TreeDataSelection'
export default {
name: 'SplitDetailBatchEditDrawer',
components: { TreeDataSelection, TreeSelection, UserSelection, StandardSelection, UploadFile, JMultipleDatePicker, STreeSelect },
data () {
return {
FieldType,
defaultValue: {},
title: this.$t('docTool.split.batchEdit'),
visible: false,
confirmLoading: false,
disabled: false,
formInline: {},
isFormInline: false,
dataList: [],
ruleList: [],
rules: {},
uploadName: '',
type: 'add',
hiddenFieldList: ['item_num', 'item_title', 'item_content', 'interpretation_articles', 'translation'], // 隐藏的字段
radioDictSelect: [], // 使用radio样式的数据字典单选
disabledFieldList: [], // 禁用的字段
specialPlaceholder: {}, // 特殊的placeholder
optionsData: {} // 通过接口获取的下拉数据
// interpretationArticlesList: [] // 条文解读数据
}
},
methods: {
open (ids) {
this.visible = true
this.formInline = {}
this.formInline.ids = ids
this.getForm()
},
/**
* 获取表单字段
* @param callBack
*/
getForm (callBack) {
this.loading = true
const params = {
flag: this.flag,
type: this.type
}
getDocSplitEditForm(params).then((res) => {
if (res.success) {
const indexArr = []
// 新认证实施日期
indexArr[0] = res.result.findIndex(tt => tt.dbFieldName === 'new_cer_implement_date')
// 已认证实施日期
indexArr[1] = res.result.findIndex(tt => tt.dbFieldName === 'cer_implement_date')
// 新注册实施日期
indexArr[2] = res.result.findIndex(tt => tt.dbFieldName === 'new_register_implement_date')
// 条文解读数据处理
// this.interpretationArticlesList = [
// { id: '', itemContent: null }
// ]
this.dataList = res.result
this.ruleList = res.result
this.integrateData()
this.getOptionsData()
callBack && callBack()
}
}).finally(() => {
this.loading = false
})
},
/**
* 处理需要通过接口获取的下拉数据
*/
getOptionsData () {
const formList = Object.values(this.dataList).reduce((acc, cur) => acc.concat(cur), [])
formList.forEach(item => {
if (item.fieldShowType === FieldType.TREE.value || item.fieldShowType === FieldType.TREE_SINGLE.value) {
// 展示类型是树选择,且有接口的
if (item.fieldHref) {
getAction(item.fieldHref).then(res => {
if (res.success) {
this.$set(this.optionsData, item.dbFieldName, res.result)
}
})
} else if (item.dictId) {
getFormDictTreeList({ dictId: item.dictId }).then(res => {
if (res.success) {
this.$set(this.optionsData, item.dbFieldName, res.result)
}
})
}
}
})
},
/**
* 设置表单校验信息
*/
integrateData () {
this.isFormInline = false
const rules = {}
this.ruleList.forEach((res, index) => {
const rule = []
if (res.field_must_input === 1) {
if (res.field_show_type === '1') {
rule.push({
required: true,
message: res.db_field_txt + this.$t('cannotEmpty'),
trigger: 'blur'
})
} else if (res.field_show_type === '4' || res.field_show_type === '6' ||
res.field_show_type === '5' || res.field_show_type === '7'
) {
rule.push({
required: true,
message: res.db_field_txt + this.$t('cannotEmpty'),
trigger: 'change'
})
} else if (res.field_show_type === '2') {
rule.push({
required: true,
message: res.db_field_txt + this.$t('cannotEmpty'),
trigger: 'blur'
})
} else if (res.field_show_type === '8' || res.field_show_type === '9' || res.field_show_type === '10' || res.field_show_type === '11') {
rule.push({
required: true,
message: res.db_field_txt + this.$t('cannotEmpty'),
trigger: 'blur'
})
} else if (res.field_show_type === '3') {
rule.push({
required: true,
message: res.db_field_txt + this.$t('cannotEmpty'),
trigger: 'change'
})
}
}
if (res.field_show_type === '1' ||
res.field_show_type === '8' || res.field_show_type === '9' || res.field_show_type === '10' ||
res.field_show_type === '11') {
rule.push({
max: res.db_length,
message: res.db_field_txt + this.$t('cantExeed') + res.db_length + this.$t('characters'),
trigger: 'blur'
})
}
if (rule.length > 0) {
rules[res.db_field_name] = rule
}
})
this.$set(this, 'rules', rules)
// console.log('rules',this.rules)
this.isFormInline = true
this.loading = false
// console.log('this.column',this.column)
},
// 点击点击上传按钮
clickButtonToUpload (item) {
this.$refs.uploadFile.open(this.formInline[item.db_field_name])
this.uploadName = item.db_field_name
},
// 文件上传改变后的回调
uploadFileChange (data) {
const attIdList = []
if (data && data.length > 0) {
data.map(item => {
attIdList.push(item.id || data.name)
})
}
/** 赋值给当前对应的表单文件 */
this.formInline[this.uploadName] = attIdList.join(',')
this.formInline = { ...this.formInline }
},
handleSave () {
if (this.confirmLoading) {
return
}
this.$refs.ruleForm.validate(valid => {
if (valid) {
this.confirmLoading = true
// 处理请求参数
const formData = JSON.parse(JSON.stringify(this.formInline))
// 处理动态表单多选的值
Object.keys(formData).forEach(res => {
if (formData[res] instanceof Array) {
if (formData[res][0] instanceof Object) {
// 说明是树选择
formData[res] = formData[res].map(item => item.value).join(',')
} else {
formData[res] = formData[res].join(',')
}
}
})
// 处理条文解读数据
// formData.interpretationArticlesList = this.interpretationArticlesList
editBatchEditClause(formData).then(res => {
if (res.success) {
this.$message.success(res.message)
this.$emit('ok')
this.close()
} else {
this.$message.warning(res.message)
}
}).finally(() => {
this.confirmLoading = false
})
}
})
},
handleCancel () {
this.close()
},
close () {
this.visible = false
this.formInline = {}
},
/**
* 新增一条条文解读
* @param index
*/
handleAddUnscramble (index) {
this.interpretationArticlesList.splice(index + 1, 0, { id: '', itemContent: null })
},
/**
* 删除条文解读
*/
handleDeleteUnscramble (index, item) {
this.interpretationArticlesList.splice(index, 1)
if (item.id) {
this.deleteIds.push(item.id)
}
},
filterTreeOption (input, option) {
const text = option.componentOptions.propsData.title || option.componentOptions.propsData.label
return text.toLowerCase().indexOf(input.toLowerCase()) >= 0
},
/**
* 属性标识的子集字段处理
* @param field
* @returns {null|string}
*/
getTreeSelectionChildrenColumnName (field) {
if (field.dbFieldName === 'property_tag') {
return 'childrenList'
}
return null
},
treeDataSelectNameChange (value, fieldName) {
this.formInline[fieldName + '_dictText'] = value
},
/**
* 如果字段中的usableRange只有一个值,那么就需要在placeholder中标识
* @param field
*/
getPlaceholderSuffix (field) {
// const fieldUsableRange = (field.usableRange || '').split(',')
// if (fieldUsableRange.length === 1) {
// return `${ClauseUsableRange.nameOfIndex(fieldUsableRange[0])}`
// }
return ''
}
}
}
</script>
<style scoped lang="less">
.form-flex-box {
display: flex;
flex-wrap: wrap;
}
.form-flex-item {
width: 100%;
}
.unscramble-item {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
&-content {
width: 0;
flex: 1;
table {
width: 100%;
}
}
&-operate {
.ant-btn {
margin-left: 15px
}
}
}
.unscramble-item:last-child {
margin-bottom: 0;
}
</style>