zhengnaiwen_citu пре 2 месеци
родитељ
комит
de1e764b1e

+ 0 - 1
src/components/TabsTemplate/index.vue

@@ -28,7 +28,6 @@ export default {
     }
   },
   mounted () {
-    console.log(11111)
     // this.$nextTick(() => {
     this.items = this.$route.meta.roles.filter(e => e.hidden === 1).sort((a, b) => a.sort - b.sort).map(e => {
       const path = `${e.component}/index.vue`

+ 1 - 1
src/views/salary/solution/salarySolution/index.vue

@@ -5,7 +5,7 @@
         <m-button type="orange" size="small" icon="el-icon-plus" @click="onOpen('salarySolutionEditRefs')" >新增</m-button>
       </template>
       <template #actions="{ row }">
-        <m-button text type="primary" size="small" @click="onOpen('salarySolutionDetailsRefs', row)">查看</m-button>
+        <m-button text type="primary" size="small" @click="onOpen('salarySolutionDetailsRefs', row)">规则详情</m-button>
         <m-button text type="primary" size="small" @click="onOpen('salarySolutionEditRefs', row)">编辑</m-button>
         <m-button text type="primary" size="small" @click="onOpen('salarySolutionRulesRefs', row)">规则配置</m-button>
         <slot name="actions" :row="row"></slot>

+ 1 - 0
src/views/salary/solution/salarySolution/salarySolutionRules.vue

@@ -149,6 +149,7 @@ export default {
           this.$message.error(error)
         }
       }).catch(error => {
+        console.log(error)
         this.editableTabsValue = error.name
         this.$message.error('请填充完整')
       })

+ 57 - 25
src/views/salary/solution/salarySolution/salarySolutionRulesEdit.vue

@@ -16,10 +16,9 @@
               { label: '参数类型', prop: 'valueCategory' },
               { label: '操作', prop: 'actions' }
             ]"
-            @expand-change="onExpandChange"
           >
-            <template #expandProp="{ row, $index }">
-              <SalarySolutionRulesEditParam :ref="`salarySolutionRulesEditParamRefs${$index}`" @assign="onAssign(row, $event)"></SalarySolutionRulesEditParam>
+            <template #expandProp="{ $index }">
+              <SalarySolutionRulesEditParam :ref="`salarySolutionRulesEditParamRefs${$index}`" v-model="items[$index]"></SalarySolutionRulesEditParam>
             </template>
             <div class="text-center mt-3">
               <m-button icon="el-icon-plus" type="orange" size="small" @click="onAdd">添加参数</m-button>
@@ -98,9 +97,6 @@ export default {
     editor.destroy() // 组件销毁时,及时销毁编辑器
   },
   methods: {
-    onAssign (row, obj) {
-      Object.assign(row, obj)
-    },
     onCreated (editor) {
       this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
     },
@@ -122,10 +118,15 @@ export default {
     valid () {
       return new Promise((resolve, reject) => {
         const check = this.items.every(e => {
-          if (!this.$refs[`salarySolutionRulesEditParamRefs${e.index}`]) {
-            return true
+          if (!e.name) {
+            return false
+          }
+          if (e.valueCategory !== 0) {
+            return e.value.every(_e => {
+              return (_e.name === null && _e.value === null) || (_e.name !== null && _e.value !== null)
+            })
           }
-          return this.$refs[`salarySolutionRulesEditParamRefs${e.index}`].valid()
+          return true
         })
         if (!check) {
           reject(this.item)
@@ -134,33 +135,64 @@ export default {
         }
       })
     },
-    onExpandChange (row, expandedRows) {
-      const open = expandedRows.find(e => e.index === row.index)
-      if (!open) {
-        return
-      }
-      this.$nextTick(() => {
-        this.$refs[`salarySolutionRulesEditParamRefs${row.index}`].setValue(row)
-      })
-    },
     setValue (data) {
       this.items = data.calculateConfigurations.map((e, index) => {
+        if (e.valueCategory !== 0) {
+          const { value, ...obj } = e
+          return {
+            index,
+            value: JSON.parse(value),
+            ...obj
+          }
+        }
         return {
           index,
           ...e
         }
       })
-      this.$nextTick(() => {
-        this.formulaData = data.calculateFormulas.length ? data.calculateFormulas[0].content : ''
-      })
+      this.formulaData = data.calculateFormulas.length ? data.calculateFormulas[0].content : ''
+      // this.$nextTick(() => {
+      //   this.formulaData = data.calculateFormulas.length ? data.calculateFormulas[0].content : ''
+      // })
     },
     getValue () {
       const calculateConfigurations = this.items.map(e => {
-        if (!this.$refs[`salarySolutionRulesEditParamRefs${e.index}`]) {
-          const { index, ...obj } = e
-          return obj
+        const {
+          name,
+          valueCategory,
+          miniValue,
+          maxValue,
+          value
+        } = e
+        if (valueCategory === 0) {
+          return {
+            name,
+            valueCategory,
+            miniValue: miniValue ?? null,
+            maxValue: maxValue ?? null,
+            value
+          }
+        }
+        const _value = JSON.stringify(value.map(_e => {
+          return {
+            name: _e.name,
+            value: _e.value
+          }
+        }))
+        if (valueCategory === 1) {
+          return {
+            name,
+            valueCategory,
+            value: _value
+          }
+        }
+        return {
+          name,
+          valueCategory,
+          miniValue: miniValue ?? null,
+          maxValue: maxValue ?? null,
+          value: _value
         }
-        return this.$refs[`salarySolutionRulesEditParamRefs${e.index}`].getValue()
       })
       return {
         category: this.item.title,

+ 46 - 69
src/views/salary/solution/salarySolution/salarySolutionRulesEditParam.vue

@@ -1,11 +1,11 @@
 <template>
   <m-form ref="form" label-width="100px" :items="formItems" v-model="formValues">
-    <template #content>
+    <template #value v-if="formValues.valueCategory !== 0">
       <m-table
         clearHeader
         shadow="never"
         :headers="headers"
-        :items="items"
+        :items="formValues.value || []"
       >
         <template #name="{ row }">
           <el-input v-model="row.name" placeholder="请输入参数名称" size="small"></el-input>
@@ -31,6 +31,12 @@ import {
 } from '../utils/Dict'
 export default {
   name: 'salarySolutionRulesEditParam',
+  props: {
+    value: {
+      type: Object,
+      default: () => ({})
+    }
+  },
   data () {
     return {
       headers: [
@@ -38,7 +44,7 @@ export default {
         { label: '参数值', prop: 'value' },
         { label: '操作', prop: 'actions' }
       ],
-      items: [],
+      // items: [],
       id: 0,
       formValues: {
         name: null,
@@ -46,7 +52,19 @@ export default {
         miniValue: null,
         maxValue: null,
         value: null
-      }
+      },
+      isStart: false
+    }
+  },
+  watch: {
+    formValues: {
+      handler (val) {
+        if (!this.isStart) {
+          return
+        }
+        this.$emit('input', val)
+      },
+      deep: true
     }
   },
   computed: {
@@ -125,7 +143,7 @@ export default {
           ...maxAndMin,
           {
             label: '数据',
-            prop: 'content',
+            prop: 'value',
             style
           }
         ]
@@ -134,15 +152,17 @@ export default {
         ...common,
         {
           label: '数据',
-          prop: 'content',
+          prop: 'value',
           style
         }
       ]
     }
   },
+  created () {
+    this.setValue(this.value)
+  },
   methods: {
     setValue (item) {
-      console.log(item)
       const {
         valueCategory,
         value,
@@ -150,86 +170,43 @@ export default {
         miniValue,
         ...obj
       } = item
+
+      this.id = 0
       this.formValues = {
         ...obj,
         maxValue: !maxValue ? undefined : Number(maxValue),
         miniValue: !miniValue ? undefined : Number(miniValue),
         valueCategory,
-        value: valueCategory === 0 ? value : JSON.parse(value)
+        value: valueCategory === 0
+          ? value
+          : value.map(e => {
+            return {
+              name: e.name,
+              value: e.value,
+              index: this.id++
+            }
+          })
       }
 
-      if (valueCategory !== 0) {
-        this.id = 0
-        this.items = JSON.parse(value).map(e => {
-          return {
-            name: e.name,
-            value: e.value,
-            index: this.id++
-          }
-        })
-      }
+      this.isStart = true
     },
     onAdd () {
-      this.items.push({
+      const item = {
         name: null,
         valueCategory: 0,
         miniValue: null,
         maxValue: null,
         value: null,
         index: this.id++
-      })
-    },
-    onRemove (index) {
-      this.items.splice(index, 1)
-    },
-    valid () {
-      if (!this.formValues.name) {
-        return
       }
-      if (this.formValues.valueCategory !== 0) {
-        return this.items.every(e => {
-          return (e.name === null && e.value === null) || (e.name !== null && e.value !== null)
-        })
+      if (!this.formValues.value) {
+        this.formValues.value = [item]
+        return
       }
-      return true
+      this.formValues.value.push(item)
     },
-    getValue () {
-      const {
-        name,
-        valueCategory,
-        miniValue,
-        maxValue,
-        value
-      } = this.formValues
-      if (valueCategory === 0) {
-        return {
-          name,
-          valueCategory,
-          miniValue: miniValue ?? null,
-          maxValue: maxValue ?? null,
-          value
-        }
-      }
-      const items = this.items.map(e => {
-        return {
-          name: e.name,
-          value: e.value
-        }
-      })
-      if (valueCategory === 1) {
-        return {
-          name,
-          valueCategory,
-          value: JSON.stringify(items)
-        }
-      }
-      return {
-        name,
-        valueCategory,
-        miniValue: miniValue ?? null,
-        maxValue: maxValue ?? null,
-        value: JSON.stringify(items)
-      }
+    onRemove (index) {
+      this.formValues.value.splice(index, 1)
     }
   }
 }