Commit 8704cbbe by 李伟康

refactor(sales): 优化销售合同组件的指标配置处理

- 将metricConfigs通过props传递给ConditionItem组件
- 修复localStorage数据解析的安全性检查
- 优化indicatorOptions计算逻辑并改为方法调用
- 移除不必要的GET_BASE_SCENE_CODE注入
- 使用$nextTick确保表单验证清理的时机正确
1 parent 9a30bf01
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
<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)" @changeCondition="changeCondition($event, index)"
:listLength="guaranteeConfigs.length" :ref="`conditionItem${index}`" /> :listLength="guaranteeConfigs.length" :ref="`conditionItem${index}`" :metricConfigs="metricConfigs" />
</template> </template>
</div> </div>
</div> </div>
...@@ -126,7 +126,8 @@ export default { ...@@ -126,7 +126,8 @@ export default {
methods: { methods: {
async storeApproveQueryMetricConfigs() { async storeApproveQueryMetricConfigs() {
let baseSceneCode = this.GET_BASE_SCENE_CODE(), let baseSceneCode = this.GET_BASE_SCENE_CODE(),
metricConfigs = JSON.parse(localStorage.getItem('metricConfigs')) || {} storageData = localStorage.getItem('metricConfigs'),
metricConfigs = storageData ? JSON.parse(storageData) : {}
if (!metricConfigs[baseSceneCode]) { if (!metricConfigs[baseSceneCode]) {
const data = await storeApproveQueryMetricConfigs({ const data = await storeApproveQueryMetricConfigs({
baseSceneCode baseSceneCode
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<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">
<el-option v-for="item in indicatorOptions" :key="item.metricCode" :label="item.metricName" <el-option v-for="item in indicatorOptions()" :key="item.metricCode" :label="item.metricName"
:value="item.metricCode" :filterable="i.filterable" :disabled="item.disabled" /> :value="item.metricCode" :filterable="i.filterable" :disabled="item.disabled" />
</el-select> </el-select>
</template> </template>
...@@ -87,7 +87,7 @@ const DDBZ = { label: '兜底标准', key: 'guaranteeStandard', type: 'input' }, ...@@ -87,7 +87,7 @@ const DDBZ = { label: '兜底标准', key: 'guaranteeStandard', type: 'input' },
], ],
} }
export default { export default {
inject: ['size', 'GET_BASE_SCENE_CODE'], inject: ['size'],
name: 'ConditionItem', name: 'ConditionItem',
mixins: [componentsMixin], mixins: [componentsMixin],
props: { props: {
...@@ -107,6 +107,7 @@ export default { ...@@ -107,6 +107,7 @@ export default {
type: Array, type: Array,
default: () => [] default: () => []
}, },
metricConfigs: Array
}, },
data() { data() {
return { return {
...@@ -146,7 +147,9 @@ export default { ...@@ -146,7 +147,9 @@ export default {
this.selectionChange(val.guaranteeIndex, false) this.selectionChange(val.guaranteeIndex, false)
if (val.ladderConditions) this.ladderConditions = JSON.parse(val.ladderConditions) if (val.ladderConditions) this.ladderConditions = JSON.parse(val.ladderConditions)
} }
this.formRef && this.formRef.clearValidate() this.$nextTick(() => {
this.formRef && this.formRef.clearValidate()
})
}, },
deep: true, deep: true,
immediate: true immediate: true
...@@ -170,12 +173,16 @@ export default { ...@@ -170,12 +173,16 @@ export default {
}, },
computed: { computed: {
options() { options() {
let baseSceneCode = this.GET_BASE_SCENE_CODE(), let {metricConfigs} = this
metricConfigs = localStorage.getItem('metricConfigs') || {}, return metricConfigs
options = metricConfigs ? deepClone(JSON.parse(metricConfigs)[baseSceneCode]) : []
return options
}, },
indicatorOptions() { formRef() {
return this.$refs.formRef
},
},
mounted() { },
methods: {
indicatorOptions() {
let { includesList } = this, let { includesList } = this,
options = deepClone(this.options) options = deepClone(this.options)
if (includesList.length) { if (includesList.length) {
...@@ -186,12 +193,6 @@ export default { ...@@ -186,12 +193,6 @@ export default {
} }
return options return options
}, },
formRef() {
return this.$refs.formRef
},
},
mounted() { },
methods: {
radioChange(val) { radioChange(val) {
if (val == 2) { if (val == 2) {
this.ladderConditions = [{ this.ladderConditions = [{
...@@ -240,7 +241,7 @@ export default { ...@@ -240,7 +241,7 @@ export default {
this.$forceUpdate() this.$forceUpdate()
}, },
indicatorText(val) { indicatorText(val) {
return this.indicatorOptions.find(item => item.metricCode == val)?.metricName || '选中的指标值' return this.indicatorOptions().find(item => item.metricCode == val)?.metricName || '选中的指标值'
}, },
clearValue(index, key, errorText) { clearValue(index, key, errorText) {
this.$set(this.ladderConditions[index], key, '') this.$set(this.ladderConditions[index], key, '')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!