Commit bdd4f93f by 李伟康

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

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