Commit bdd4f93f by 李伟康

refactor(sales): 优化销售合同底部条件组件逻辑

- 将 changeCondition 事件改为 updateCondition 事件
- 移除 includesConditionList 状态变量,改用计算属性动态生成
- 在 ConditionItem 组件中添加 visible-change 监听器
- 为 select 组件添加 disabled 属性控制选项禁用状态
- 更新组件数据初始化逻辑,将 componentData 设为 null
- 在添加、删除和修改条件时触发验证流程
- 优化事件触发时机,确保数据同步准确性
1 parent 8704cbbe
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<div class="condition-list"> <div class="condition-list">
<template v-for="(item, index) in guaranteeConfigs"> <template v-for="(item, index) in guaranteeConfigs">
<conditionItem :key="index" :includesList="includesConditionList" :item="item" :num="index" <conditionItem :key="index" :includesList="includesConditionList" :item="item" :num="index"
@delete="deleteCondition(index)" @changeCondition="changeCondition($event, index)" @delete="deleteCondition(index)" @updateCondition="updateCondition($event, index)"
:listLength="guaranteeConfigs.length" :ref="`conditionItem${index}`" :metricConfigs="metricConfigs" /> :listLength="guaranteeConfigs.length" :ref="`conditionItem${index}`" :metricConfigs="metricConfigs" />
</template> </template>
</div> </div>
...@@ -88,8 +88,7 @@ export default { ...@@ -88,8 +88,7 @@ export default {
return { return {
data: '', data: '',
guaranteeConfigs: [], guaranteeConfigs: [],
includesConditionList: [], metricConfigs: []
metricConfigs: []
} }
}, },
watch: { watch: {
...@@ -105,21 +104,29 @@ export default { ...@@ -105,21 +104,29 @@ export default {
this.storeApproveQueryMetricConfigs() this.storeApproveQueryMetricConfigs()
if (val && val.length) { if (val && val.length) {
this.guaranteeConfigs = val this.guaranteeConfigs = val
this.includesConditionList = val.map(item => item.guaranteeIndex)
} else { } else {
this.guaranteeConfigs = [{ this.guaranteeConfigs = [{
guaranteeIndex: '', guaranteeIndex: '',
guaranteeStandard: null, guaranteeStandard: null,
compensationMode: 0 compensationMode: 0
}] }]
this.includesConditionList = []
} }
}, },
immediate: true, immediate: true,
deep: true deep: true
} },
},
computed: {
includesConditionList() {
let includesConditionList = [],
{guaranteeConfigs } = this
guaranteeConfigs.map(item => {
if(item.guaranteeIndex) includesConditionList.push(item.guaranteeIndex)
})
console.log(includesConditionList)
return includesConditionList
},
}, },
computed: {},
mounted() { mounted() {
}, },
...@@ -140,24 +147,30 @@ export default { ...@@ -140,24 +147,30 @@ export default {
} else this.metricConfigs = metricConfigs[baseSceneCode] } else this.metricConfigs = metricConfigs[baseSceneCode]
}, },
addCondition() { addCondition() {
this.guaranteeConfigs.push({ this.validate(guaranteeConfigs => {
this.guaranteeConfigs = guaranteeConfigs
this.guaranteeConfigs.push({
guaranteeIndex: '', guaranteeIndex: '',
guaranteeStandard: null, guaranteeStandard: null,
compensationMode: '0' compensationMode: 0
})
}) })
}, },
deleteCondition(index) { deleteCondition(index) {
this.includesConditionList.splice(index, 1) this.validate(guaranteeConfigs => {
this.guaranteeConfigs.splice(index, 1) this.guaranteeConfigs = guaranteeConfigs
this.guaranteeConfigs.splice(index, 1)
})
}, },
changeData(val) { changeData(val) {
this.$emit('update:value', val) this.$emit('update:value', val)
this.includesConditionList = []
if (val == 1 && this.guaranteeConfigs.length == 0) this.addCondition() if (val == 1 && this.guaranteeConfigs.length == 0) this.addCondition()
if (val == 0) this.guaranteeConfigs = [] if (val == 0) this.guaranteeConfigs = []
}, },
changeCondition(val, index) { updateCondition() {
this.$set(this.includesConditionList, index, val) this.validate(guaranteeConfigs => {
this.guaranteeConfigs = [...guaranteeConfigs]
})
}, },
validate(callback) { validate(callback) {
try { try {
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
</template> </template>
<template v-else-if="i.type == 'select'"> <template v-else-if="i.type == 'select'">
<el-select v-model="componentData[i.key]" class="select" :placeholder="`请选择${i.label}`" <el-select v-model="componentData[i.key]" class="select" :placeholder="`请选择${i.label}`"
:filterable="i.filterable" @change="selectionChange"> :filterable="i.filterable" @change="selectionChange" @visible-change="visibleChange">
<el-option v-for="item in indicatorOptions()" :key="item.metricCode" :label="item.metricName" <el-option v-for="item in options" :key="item.metricCode" :label="item.metricName"
:value="item.metricCode" :filterable="i.filterable" :disabled="item.disabled" /> :value="item.metricCode" :filterable="i.filterable" :disabled="includesList.includes(item.metricCode)" />
</el-select> </el-select>
</template> </template>
<template v-else-if="i.type == 'radio'"> <template v-else-if="i.type == 'radio'">
...@@ -111,7 +111,8 @@ export default { ...@@ -111,7 +111,8 @@ export default {
}, },
data() { data() {
return { return {
componentData: {}, guaranteeOptions:[],
componentData: null,
ladderConditions: [], ladderConditions: [],
rules: { rules: {
guaranteeIndex: [{ required: true, message: '请选择兜底指标', trigger: 'change' }], guaranteeIndex: [{ required: true, message: '请选择兜底指标', trigger: 'change' }],
...@@ -225,12 +226,13 @@ export default { ...@@ -225,12 +226,13 @@ export default {
if (clear) this.$set(this.componentData, 'guaranteeStandard', '') if (clear) this.$set(this.componentData, 'guaranteeStandard', '')
this.$set(this, 'conditionStartConfig', conditionStartConfig) this.$set(this, 'conditionStartConfig', conditionStartConfig)
this.$set(this, 'conditionEndConfig', conditionEndConfig) this.$set(this, 'conditionEndConfig', conditionEndConfig)
this.$emit('changeCondition', val) if(clear) this.$emit('updateCondition')
}, },
deleteList(index) { deleteList(index) {
this.ladderConditions.splice(index, 1) this.ladderConditions.splice(index, 1)
this.$forceUpdate() this.$forceUpdate()
this.$emit('updateCondition')
}, },
addList() { addList() {
this.ladderConditions.push({ this.ladderConditions.push({
...@@ -239,6 +241,7 @@ export default { ...@@ -239,6 +241,7 @@ export default {
compensationAmount: '' compensationAmount: ''
}) })
this.$forceUpdate() this.$forceUpdate()
this.$emit('updateCondition')
}, },
indicatorText(val) { indicatorText(val) {
return this.indicatorOptions().find(item => item.metricCode == val)?.metricName || '选中的指标值' return this.indicatorOptions().find(item => item.metricCode == val)?.metricName || '选中的指标值'
...@@ -321,7 +324,7 @@ export default { ...@@ -321,7 +324,7 @@ export default {
}, },
disabled(val) { disabled(val) {
return val === '' || val === null || val === undefined return val === '' || val === null || val === undefined
}, }
} }
} }
</script> </script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!