update addform回显问题

This commit is contained in:
赵霄
2023-09-18 16:13:40 +08:00
parent bae308459b
commit 7048725ae4
4 changed files with 136 additions and 44 deletions
+3
View File
@@ -38,6 +38,9 @@ export default {
this.checkedValue = [] this.checkedValue = []
document.getElementById(this.fieldName).children[0].children[0].value = '' document.getElementById(this.fieldName).children[0].children[0].value = ''
this.$emit('change', '') this.$emit('change', '')
} else {
this.checkedValue = val.split(',')
document.getElementById(this.fieldName).children[0].children[0].value = val
} }
} }
}, },
+51 -18
View File
@@ -210,13 +210,13 @@
</div> </div>
<a-form-model-item class="item-model" :prop="item.dbFieldName"> <a-form-model-item class="item-model" :prop="item.dbFieldName">
<a-tree-select <a-tree-select
tree-node-filter-prop="title"
v-model="formInline[item.dbFieldName]" v-model="formInline[item.dbFieldName]"
:getPopupContainer="triggerNode=> triggerNode.parentNode" :getPopupContainer="triggerNode=> triggerNode.parentNode"
style="width: 100%" style="width: 100%"
:tree-data="optionsData[item.dbFieldName]" :tree-data="optionsData[item.dbFieldName]"
tree-checkable tree-checkable
treeCheckStrictly treeCheckStrictly
:label-in-value="false"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt" :placeholder="$t('pleaseSelect')+item.dbFieldTxt"
/> />
</a-form-model-item> </a-form-model-item>
@@ -234,11 +234,29 @@
v-model="formInline[item.dbFieldName]" v-model="formInline[item.dbFieldName]"
:default-value="defaultValue[item.dbFieldName]" :default-value="defaultValue[item.dbFieldName]"
date-format="YYYY" date-format="YYYY"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"/> :placeholder="$t('pleaseSelect')+item.dbFieldTxt" />
</a-form-model-item>
</div>
</a-col>
<!-- 15, 树选择(单选) -->
<a-col :span="12" v-else-if="item.fieldShowType === FieldType.TREE_SINGLE.value">
<div class="box-title-text" :title="item.dbFieldTxt">
<div class="title-text">
<span class="required" v-if="item.fieldMustInput === '1'">*</span>
<span class="title-text-text">{{ item.dbFieldTxt }}</span>
</div>
<a-form-model-item class="item-model" :prop="item.dbFieldName">
<a-tree-select
v-model="formInline[item.dbFieldName]"
:getPopupContainer="triggerNode=> triggerNode.parentNode"
style="width: 100%"
:tree-data="optionsData[item.dbFieldName]"
:label-in-value="false"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"
/>
</a-form-model-item> </a-form-model-item>
</div> </div>
</a-col> </a-col>
</div> </div>
</a-row> </a-row>
</div> </div>
@@ -358,7 +376,22 @@ export default {
} }
this.getDocumentInfoFunc({ id: item.id }).then((res) => { this.getDocumentInfoFunc({ id: item.id }).then((res) => {
if (res.success) { if (res.success) {
// 处理树结构多选回显
const formList = Object.values(this.dataList).reduce((acc, cur) => acc.concat(cur), [])
const treeMultipleField = formList.filter(tt => tt.fieldShowType === FieldType.TREE.value)
this.formInline = res.result this.formInline = res.result
treeMultipleField.forEach(field => {
const valueArr = []
if (this.formInline[field.dbFieldName]) {
const values = this.formInline[field.dbFieldName].split(',')
for (let i = 0; i < values.length; i++) {
valueArr[i] = {
value: values[i]
}
}
this.formInline[field.dbFieldName] = valueArr
}
})
this.loading = false this.loading = false
} else { } else {
this.loading = false this.loading = false
@@ -381,7 +414,6 @@ export default {
this.dataList = res.result this.dataList = res.result
this.ruleList = res.result this.ruleList = res.result
this.integrateData() this.integrateData()
console.log(JSON.parse(JSON.stringify(this.dataList)))
this.getOptionsData() // 获取下拉数据 this.getOptionsData() // 获取下拉数据
callBack && callBack() callBack && callBack()
} }
@@ -391,7 +423,6 @@ export default {
integrateData () { integrateData () {
this.isFormInline = false this.isFormInline = false
const ruleList = [] const ruleList = []
console.log(this.ruleList)
for (const item in this.ruleList) { for (const item in this.ruleList) {
this.ruleList[item].forEach(ol => { this.ruleList[item].forEach(ol => {
ruleList.push(ol) ruleList.push(ol)
@@ -429,19 +460,21 @@ export default {
getOptionsData () { getOptionsData () {
const formList = Object.values(this.dataList).reduce((acc, cur) => acc.concat(cur), []) const formList = Object.values(this.dataList).reduce((acc, cur) => acc.concat(cur), [])
formList.forEach(item => { formList.forEach(item => {
// 展示类型是树选择,且有接口的 if (item.fieldShowType === FieldType.TREE.value || item.fieldShowType === FieldType.TREE_SINGLE.value) {
if (item.fieldShowType === FieldType.TREE.value && item.fieldHref) { // 展示类型是树选择,且有接口的
getAction(item.fieldHref).then(res => { if (item.fieldHref) {
if (res.success) { getAction(item.fieldHref).then(res => {
this.$set(this.optionsData, item.dbFieldName, res.result) if (res.success) {
} this.$set(this.optionsData, item.dbFieldName, res.result)
}) }
} else if (item.fieldShowType === FieldType.TREE.value && item.dictId) { })
getFormDictTreeList({ dictId: item.dictId }).then(res => { } else if (item.dictId) {
if (res.success) { getFormDictTreeList({ dictId: item.dictId }).then(res => {
this.$set(this.optionsData, item.dbFieldName, res.result) if (res.success) {
} this.$set(this.optionsData, item.dbFieldName, res.result)
}) }
})
}
} }
}) })
}, },
+79 -24
View File
@@ -1,26 +1,42 @@
<template> <template>
<a-form layout="inline" @keyup.enter.native="searchQuery"> <a-form layout="inline" @keyup.enter.native="searchQuery">
<a-row :gutter="24"> <a-row :gutter="24">
<a-col :md="(24 / (minLength + 1))" :sm="(24 / minLength)" v-for="(item) in searchList.slice(0, minLength)" :key="item.id" style="line-height: 48px"> <a-col :md="(24 / (minLength + 1))"
:sm="(24 / minLength)"
v-for="(item) in searchList.slice(0, minLength)"
:key="item.id"
style="line-height: 48px">
<!-- 树形选择器 --> <!-- 树形选择器 -->
<!-- <template v-if="item.fieldShowType === FieldType.TREE.value">--> <template v-if="item.fieldShowType === FieldType.TREE.value">
<!-- <a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">--> <a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<!-- <a-tree-select--> <a-tree-select
<!-- tree-node-filter-prop="title"--> tree-node-filter-prop="title"
<!-- v-model="queryParam[item.dbFieldName]"--> v-model="queryParam[item.dbFieldName]"
<!-- :maxTagCount="1"--> :maxTagCount="1"
<!-- :getPopupContainer="triggerNode=> triggerNode.parentNode"--> :getPopupContainer="triggerNode=> triggerNode.parentNode"
<!-- :tree-data="item.tree"--> :tree-data="item.tree"
<!-- tree-checkable--> tree-checkable
<!-- :placeholder="$t('pleaseSelect')+item.dbFieldTxt"--> :placeholder="$t('pleaseSelect')+item.dbFieldTxt"
<!-- />--> />
<!-- </a-form-item>--> </a-form-item>
<!-- </template>--> </template>
<!-- 树形选择器(单选) -->
<template v-if="item.fieldShowType === FieldType.TREE_SINGLE.value">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-tree-select
tree-node-filter-prop="title"
v-model="queryParam[item.dbFieldName]"
:maxTagCount="1"
:getPopupContainer="triggerNode=> triggerNode.parentNode"
:tree-data="item.tree"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"
/>
</a-form-item>
</template>
<!-- 输入框 --> <!-- 输入框 -->
<template <template
v-if="[FieldType.TEXT_BOX.value, FieldType.TEXTAREA.value,FieldType.USER_SINGLE.value, v-if="[FieldType.TEXT_BOX.value, FieldType.TEXTAREA.value,FieldType.USER_SINGLE.value,
FieldType.ORGAN_SINGLE.value, FieldType.STANDARD_MORE.value, FieldType.ORGAN_MORE.value, FieldType.ORGAN_SINGLE.value, FieldType.STANDARD_MORE.value, FieldType.ORGAN_MORE.value]
FieldType.YEAR_PICKER.value]
.includes(item.fieldShowType)"> .includes(item.fieldShowType)">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol"> <a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-input :placeholder="$t('pleaseEnter')+item.dbFieldTxt" <a-input :placeholder="$t('pleaseEnter')+item.dbFieldTxt"
@@ -57,7 +73,7 @@
<j-dict-select-tag v-model="queryParam[item.dbFieldName]" <j-dict-select-tag v-model="queryParam[item.dbFieldName]"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt" :placeholder="$t('pleaseSelect')+item.dbFieldTxt"
:type="'select'" :type="'select'"
:triggerChange="false" :dictCode="item.dictField"/> :triggerChange="false" :dictCode="item.dictField" />
</a-form-item> </a-form-item>
</template> </template>
<!-- 组织机构选择 --> <!-- 组织机构选择 -->
@@ -83,12 +99,16 @@
<j-date show-type="year" <j-date show-type="year"
v-model="queryParam[item.dbFieldName]" v-model="queryParam[item.dbFieldName]"
date-format="YYYY" date-format="YYYY"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"/> :placeholder="$t('pleaseSelect')+item.dbFieldTxt" />
</a-form-item> </a-form-item>
</template> </template>
</a-col> </a-col>
<template v-if="searchList.length > minLength && toggleSearchStatus"> <template v-if="searchList.length > minLength && toggleSearchStatus">
<a-col :md="(24 / (minLength + 1))" :sm="(24 / minLength)" v-for="(item) in searchList.slice(minLength)" :key="item.id" style="line-height: 48px"> <a-col :md="(24 / (minLength + 1))"
:sm="(24 / minLength)"
v-for="(item) in searchList.slice(minLength)"
:key="item.id"
style="line-height: 48px">
<!-- 树形选择器 --> <!-- 树形选择器 -->
<template v-if="item.fieldShowType === FieldType.TREE.value"> <template v-if="item.fieldShowType === FieldType.TREE.value">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol"> <a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
@@ -99,6 +119,20 @@
:getPopupContainer="triggerNode=> triggerNode.parentNode" :getPopupContainer="triggerNode=> triggerNode.parentNode"
:tree-data="item.tree" :tree-data="item.tree"
tree-checkable tree-checkable
treeCheckStrictly
:placeholder="$t('pleaseSelect')+item.dbFieldTxt"
/>
</a-form-item>
</template>
<!-- 树形选择器(单选) -->
<template v-if="item.fieldShowType === FieldType.TREE_SINGLE.value">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-tree-select
tree-node-filter-prop="title"
v-model="queryParam[item.dbFieldName]"
:maxTagCount="1"
:getPopupContainer="triggerNode=> triggerNode.parentNode"
:tree-data="item.tree"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt" :placeholder="$t('pleaseSelect')+item.dbFieldTxt"
/> />
</a-form-item> </a-form-item>
@@ -145,15 +179,25 @@
:triggerChange="false" :dictCode="item.dictField" /> :triggerChange="false" :dictCode="item.dictField" />
</a-form-item> </a-form-item>
</template> </template>
<!-- 年份选择 -->
<template
v-if="item.fieldShowType === FieldType.YEAR_PICKER.value">
<a-form-item :label="item.dbFieldTxt" :labelCol="labelCol" :wrapperCol="wrapperCol">
<j-date show-type="year"
v-model="queryParam[item.dbFieldName]"
date-format="YYYY"
:placeholder="$t('pleaseSelect')+item.dbFieldTxt" />
</a-form-item>
</template>
</a-col> </a-col>
</template> </template>
<div style="float: right;overflow: hidden;margin-right: 11px" class="table-page-search-submitButtons"> <div style="float: right;overflow: hidden;margin-right: 11px" class="table-page-search-submitButtons">
<a @click="handleToggleSearch" v-if="searchList.length > minLength"> <a @click="handleToggleSearch" v-if="searchList.length > minLength">
{{ !toggleSearchStatus ? $t('open') : $t('putAway') }} {{ !toggleSearchStatus ? $t('open') : $t('putAway') }}
<a-icon :type="toggleSearchStatus ? 'up' : 'down'"/> <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
</a> </a>
<a-button type="primary" @click="searchQuery" style="margin-left: 8px" v-has="searchHas">{{$t('query')}}</a-button> <a-button type="primary" @click="searchQuery" style="margin-left: 8px" v-has="searchHas">{{ $t('query') }}</a-button>
<a-button style="margin-left: 8px" @click="searchReset">{{$t('reset')}}</a-button> <a-button style="margin-left: 8px" @click="searchReset">{{ $t('reset') }}</a-button>
</div> </div>
</a-row> </a-row>
</a-form> </a-form>
@@ -220,7 +264,18 @@ export default {
}, },
methods: { methods: {
searchQuery () { searchQuery () {
this.$emit('search', JSON.parse(JSON.stringify(this.queryParam))) const formInline = JSON.parse(JSON.stringify(this.queryParam))
Object.keys(formInline).forEach(res => {
if (formInline[res] instanceof Array) {
if (formInline[res][0] instanceof Object) {
// 说明是树选择
formInline[res] = formInline[res].map(item => item.value).join(',')
} else {
formInline[res] = formInline[res].join(',')
}
}
})
this.$emit('search', JSON.parse(JSON.stringify(formInline)))
eventBus.$emit('searchQuery', JSON.parse(JSON.stringify(this.queryParam))) eventBus.$emit('searchQuery', JSON.parse(JSON.stringify(this.queryParam)))
}, },
searchReset () { searchReset () {
+3 -2
View File
@@ -19,9 +19,10 @@ export const FieldType = {
TEXT_BOX: { text: '文本框', value: '9' }, TEXT_BOX: { text: '文本框', value: '9' },
OPTION_SINGLE: { text: '下拉单选', value: '10' }, OPTION_SINGLE: { text: '下拉单选', value: '10' },
OPTION_MORE: { text: '下拉多选', value: '11' }, OPTION_MORE: { text: '下拉多选', value: '11' },
TREE: { text: '树形结构', value: '12' }, TREE: { text: '树形结构(多选)', value: '12' },
TEXT_LINK: { text: '输入框(链接)', value: '13' }, TEXT_LINK: { text: '输入框(链接)', value: '13' },
YEAR_PICKER: { text: '年份选择', value: '14' } YEAR_PICKER: { text: '年份选择', value: '14' },
TREE_SINGLE: { text: '树形结构(单选)', value: '15' }
} }
export const TagsTypeEnums = new EsEnums({ export const TagsTypeEnums = new EsEnums({