zhengnaiwen_citu před 4 měsíci
rodič
revize
feb4407eee

+ 10 - 0
src/api/accumulatePoint.js

@@ -69,3 +69,13 @@ export function deleteAccumulatePointRules (data) {
 export function getAccumulatePointRules (data) {
   return http.post('/employee/score/rule/detail', data)
 }
+
+// 积分规则模块 明细保存
+export function saveAccumulatePointRulesDetails (data) {
+  return http.post('/employee/score/rule/item/save', data)
+}
+
+// 积分规则模块 明细查看
+export function getAccumulatePointRulesDetails (data) {
+  return http.post('/employee/score/rule/item/detail', data)
+}

+ 133 - 0
src/views/accumulatePoints/accumulatePointsRules/accumulatePointsRulesConfig.vue

@@ -0,0 +1,133 @@
+<template>
+  <m-dialog ref="dialog" title="规则配置" @sure="onSure">
+    <m-form ref="form" :items="formItems" v-loading="loading">
+      <template #ruleCategory>
+        <el-tag>{{ itemData.ruleCategory }}</el-tag>
+      </template>
+      <template #config>
+        <m-card
+          v-for="(item) in items"
+          :key="item.key"
+          shadow="never"
+          class="mb-3"
+        >
+          <AccumulatePointsRulesConfigItem
+            ref="accumulatePointsRulesConfigItemRefs"
+            :value="item"
+          ></AccumulatePointsRulesConfigItem>
+        </m-card>
+        <div class="text-center">
+          <m-button icon="el-icon-plus" size="small" type="orange" @click="onAddItem">新增一条规则项</m-button>
+        </div>
+      </template>
+    </m-form>
+  </m-dialog>
+</template>
+
+<script>
+import {
+  getAccumulatePointRulesDetails,
+  saveAccumulatePointRulesDetails
+} from '@/api/accumulatePoint'
+import AccumulatePointsRulesConfigItem from './accumulatePointsRulesConfigItem.vue'
+export default {
+  name: 'accumulatePointsRulesConfig',
+  components: {
+    AccumulatePointsRulesConfigItem
+  },
+  data () {
+    return {
+      loading: false,
+      itemData: {},
+      formItems: [
+        {
+          label: '模块名称',
+          prop: 'ruleCategory'
+        },
+        {
+          label: '规则项',
+          prop: 'config'
+        }
+      ],
+      key: 0,
+      items: []
+    }
+  },
+  computed: {
+  },
+  methods: {
+    async open (item) {
+      this.$refs.dialog.open()
+      this.loading = true
+      this.key = 0
+      try {
+        const { data } = await getAccumulatePointRulesDetails({
+          employeeScoreRuleId: item.employeeScoreRuleId
+        })
+        this.itemData = {
+          ...data.entity,
+          items: data.items
+        }
+        this.items = data.items.map(item => {
+          return {
+            key: this.key++,
+            title: item.title,
+            calculationMethod: item.calculationMethod, // 0.添加 1.减少
+            inputType: item.inputType, // 输入类型0.多次  2.手工 3.单选
+            groupItem: item.groupItem, // { employeeScoreRuleItemId, title, score }
+            score: item.score, // 基础积分
+            maxScore: item.maxScore
+          }
+        })
+      } catch (error) {
+        this.$message.error(error)
+      } finally {
+        this.loading = false
+      }
+    },
+    // onAssign (val, obj) {
+    //   Object.assign(obj, val)
+    // },
+    onAddItem () {
+      this.items.push({
+        key: this.key++,
+        title: null,
+        calculationMethod: 0, // 0.添加 1.减少
+        inputType: 0, // 输入类型0.多次  2.手工 3.单选
+        groupItem: [], // { employeeScoreRuleItemId, title, score }
+        score: 0, // 基础积分
+        maxScore: 999
+      })
+    },
+    async onSure () {
+      if (!this.$refs.accumulatePointsRulesConfigItemRefs) {
+        this.$message.error('请先配置规则项')
+        return
+      }
+      try {
+        const data = await Promise.all(this.$refs.accumulatePointsRulesConfigItemRefs.map(item => item.valid()))
+        this.onSubmit(data)
+      } catch (error) {}
+    },
+    async onSubmit (param) {
+      this.loading = true
+      try {
+        await saveAccumulatePointRulesDetails({
+          employeeScoreRuleId: this.itemData.employeeScoreRuleId,
+          items: param
+        })
+        this.$message.success('保存成功')
+        this.$refs.dialog.close()
+      } catch (error) {
+        this.$message.error(error)
+      } finally {
+        this.loading = false
+      }
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+
+</style>

+ 182 - 0
src/views/accumulatePoints/accumulatePointsRules/accumulatePointsRulesConfigItem.vue

@@ -0,0 +1,182 @@
+<template>
+  <m-form ref="form" :items="formItems" v-model="formValues">
+    <template #groupItem>
+      <m-card shadow="never">
+        <div
+          v-for="(item, index) in formValues.groupItem"
+          :key="item.employeeScoreRuleItemId || `item${item.key}`"
+          class="d-flex m-3"
+        >
+          <el-input size="small" placeholder="选项" class="mr-3" style="width: 150px" v-model="item.title"></el-input>
+          <el-input size="small" placeholder="积分" style="width: 150px" v-model="item.score"></el-input>
+          <div class="ml-3">
+            <m-button
+              size="mini"
+              type="danger"
+              icon="el-icon-minus"
+              circle
+              @click="removeItem(index)"></m-button>
+          </div>
+        </div>
+        <div class="text-center">
+          <m-button type="orange" size="small" icon="el-icon-plus" @click="addItem">新增一条选项</m-button>
+        </div>
+      </m-card>
+    </template>
+  </m-form>
+</template>
+
+<script>
+import { cloneDeep } from 'lodash'
+
+export default {
+  name: 'accumulatePointsRulesConfigItem',
+  props: {
+    value: {
+      type: Object,
+      default: () => ({})
+    }
+  },
+  data () {
+    return {
+      formValues: cloneDeep(this.value),
+      key: 0
+    }
+  },
+  watch: {
+    value: {
+      handler (val) {
+        this.formValues = val
+      },
+      deep: true
+    }
+    // formValues: {
+    //   handler (val) {
+    //     this.$emit('assign', val)
+    //   },
+    //   deep: true
+    // }
+  },
+  computed: {
+    formItems () {
+      return [
+        {
+          label: '积分名称',
+          prop: 'title',
+          type: 'input',
+          options: {
+            size: 'small',
+            placeholder: '请输入积分名称'
+          },
+          rules: [
+            { required: true, message: '请输入积分名称', trigger: 'blur' }
+          ]
+        },
+        {
+          label: '计算方法',
+          prop: 'calculationMethod',
+          type: 'radioGroup',
+          options: {
+            size: 'small',
+            items: [
+              {
+                text: '加分',
+                label: 0
+              },
+              {
+                text: '减分',
+                label: 1
+              }
+            ]
+          }
+        },
+        {
+          label: '积分类型',
+          prop: 'inputType',
+          type: 'radioGroup',
+          options: {
+            size: 'small',
+            items: [
+              {
+                text: '多次',
+                label: 0
+              },
+              {
+                text: '手工',
+                label: 2
+              },
+              {
+                text: '单选',
+                label: 3
+              }
+            ]
+          }
+        },
+        {
+          label: '单选选项',
+          prop: 'groupItem',
+          hidden: this.formValues.inputType !== 3
+        },
+        {
+          label: '积分基数',
+          prop: 'score',
+          type: 'number',
+          hidden: this.formValues.inputType !== 0,
+          options: {
+            size: 'small'
+          }
+        },
+        {
+          label: '积分最大值',
+          prop: 'maxScore',
+          type: 'number',
+          options: {
+            size: 'small'
+          }
+        }
+      ]
+    }
+  },
+  methods: {
+    valid () {
+      return new Promise((resolve, reject) => {
+        this.$refs.form.validate(valid => {
+          if (valid) {
+            if (this.formValues.inputType === 3 && this.formValues.groupItem.length === 0) {
+              this.$message.error('请添加选项')
+              return reject(new Error('请添加选项'))
+            }
+            if (this.formValues.groupItem.some(e => !e.title || e.score === null)) {
+              this.$message.error('请填写完整选项')
+              return reject(new Error('请填写完整选项'))
+            }
+            const { score, groupItem, ...query } = this.formValues
+            resolve({
+              score: query.inputType === 0 ? score : null,
+              groupItem: query.inputType === 3 ? groupItem.map(e => ({ title: e.title, score: e.score })) : null,
+              ...query
+            })
+          } else {
+            reject(new Error('请填写完整'))
+          }
+        })
+      })
+    },
+    addItem () {
+      // debugger
+      this.formValues.groupItem.push({
+        key: this.key++,
+        title: null,
+        score: 0
+      })
+    },
+    removeItem (index) {
+      this.formValues.groupItem.splice(index, 1)
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+
+</style>

+ 42 - 0
src/views/accumulatePoints/accumulatePointsRules/accumulatePointsRulesDetails.vue

@@ -0,0 +1,42 @@
+<template>
+  <m-dialog ref="dialog" title="积分规则详情"></m-dialog>
+</template>
+
+<script>
+import {
+  getAccumulatePointRulesDetails
+} from '@/api/accumulatePoint'
+export default {
+  name: 'accumulatePointsRulesDetails',
+  data () {
+    return {
+      loading: false,
+      itemData: {}
+    }
+  },
+  methods: {
+
+    async open (item) {
+      this.$refs.dialog.open()
+      this.loading = true
+      try {
+        const { data } = await getAccumulatePointRulesDetails({
+          employeeScoreRuleId: item.employeeScoreRuleId
+        })
+        this.itemData = {
+          ...data.entity,
+          items: data.items
+        }
+      } catch (error) {
+        this.$message.error(error)
+      } finally {
+        this.loading = false
+      }
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+
+</style>

+ 62 - 3
src/views/accumulatePoints/accumulatePointsRules/accumulatePointsRulesEdit.vue

@@ -1,20 +1,79 @@
 <template>
-  <m-dialog ref="dialog" :title="`${itemData.employeeScoreRuleId ? '编辑' : '新增'}积分模块`">
-
+  <m-dialog ref="dialog" :title="`${itemData.employeeScoreRuleId ? '编辑' : '新增'}积分模块`" @sure="onSure">
+    <m-form ref="form" :items="formItems" v-model="formValues"></m-form>
   </m-dialog>
 </template>
 
 <script>
+import {
+  saveAccumulatePointRules
+} from '@/api/accumulatePoint'
 export default {
   name: 'accumulatePointsRulesEdit',
   data () {
     return {
-      itemData: {}
+      itemData: {},
+      formValues: {
+        ruleCategory: null,
+        maxScore: 0
+      },
+      formItems: [
+        {
+          label: '积分模块名称',
+          prop: 'ruleCategory',
+          type: 'input',
+          options: {
+            placeholder: '请输入积分模块名称'
+          },
+          rules: [
+            { required: true, message: '请输入积分模块名称', trigger: 'blur' }
+          ]
+        },
+        {
+          label: '积分最大值',
+          prop: 'maxScore',
+          type: 'number',
+          options: {
+            placeholder: '请输入积分最大值'
+          },
+          rules: [
+            { required: true, message: '请输入积分最大值', trigger: 'blur' }
+          ]
+        }
+      ]
     }
   },
   methods: {
     open (item) {
+      this.itemData = item ?? {}
+      if (item) {
+        this.formValues = {
+          ruleCategory: item.ruleCategory,
+          maxScore: item.maxScore
+        }
+      } else {
+        this.formValues = {
+          ruleCategory: null,
+          maxScore: 0
+        }
+      }
       this.$refs.dialog.open()
+    },
+    async onSure () {
+      this.$refs.form.validate(async valid => {
+        if (!valid) return
+        try {
+          await saveAccumulatePointRules({
+            employeeScoreRuleId: this.itemData.employeeScoreRuleId,
+            ...this.formValues
+          })
+          this.$message.success('保存成功')
+          this.$refs.dialog.close()
+          this.$emit('success')
+        } catch (error) {
+          this.$message.error(error)
+        }
+      })
     }
   }
 }

+ 18 - 5
src/views/accumulatePoints/accumulatePointsRules/index.vue

@@ -16,22 +16,30 @@
       <template #actions="{ row }">
         <m-button type="primary" text @click="onDetails(row)">查看</m-button>
         <m-button type="primary" text @click="onEdit(row)">编辑</m-button>
+        <m-button type="primary" text @click="onRules(row)">规则配置</m-button>
         <m-button type="danger" text @click="onDelete(row)">删除</m-button>
       </template>
     </m-table>
-    <AccumulatePointsRulesEdit ref="accumulatePointsRulesEditRefs"></AccumulatePointsRulesEdit>
+    <AccumulatePointsRulesEdit ref="accumulatePointsRulesEditRefs" @success="onInit"></AccumulatePointsRulesEdit>
+    <AccumulatePointsRulesConfig ref="accumulatePointsRulesConfigRefs"></AccumulatePointsRulesConfig>
+    <AccumulatePointsRulesDetails ref="accumulatePointsRulesDetailsRefs"></AccumulatePointsRulesDetails>
   </div>
 </template>
 
 <script>
 import {
-  getAccumulatePointRulesList
+  getAccumulatePointRulesList,
+  deleteAccumulatePointRules
 } from '@/api/accumulatePoint'
 import AccumulatePointsRulesEdit from './accumulatePointsRulesEdit.vue'
+import AccumulatePointsRulesConfig from './accumulatePointsRulesConfig.vue'
+import AccumulatePointsRulesDetails from './accumulatePointsRulesDetails.vue'
 export default {
   name: 'AccumulatePointRules',
   components: {
-    AccumulatePointsRulesEdit
+    AccumulatePointsRulesEdit,
+    AccumulatePointsRulesConfig,
+    AccumulatePointsRulesDetails
   },
   data () {
     return {
@@ -99,12 +107,17 @@ export default {
     onEdit (item) {
       this.$refs.accumulatePointsRulesEditRefs.open(item)
     },
-    onDetails () {},
+    onRules (item) {
+      this.$refs.accumulatePointsRulesConfigRefs.open(item)
+    },
+    onDetails (item) {
+      this.$refs.accumulatePointsRulesDetailsRefs.open(item)
+    },
     onDelete (row) {
       this.$confirm('确定删除吗?', '提示')
         .then(async () => {
           try {
-            // await deleteAccumulatePoint({ id: row.id })
+            await deleteAccumulatePointRules({ employeeScoreRuleId: row.employeeScoreRuleId })
             this.$message.success('删除成功')
             this.onInit()
           } catch (error) {