Ver código fonte

福利待遇

zhengnaiwen_citu 7 meses atrás
pai
commit
0af8f77e2d

+ 15 - 0
src/api/salary.js

@@ -42,7 +42,22 @@ export function getWelfareDetail (param) {
   return http.post('/subsidy/category/detail', param)
 }
 
+// 福利待遇 - 保存
+export function saveWelfare (param) {
+  return http.post('/subsidy/category/save', param)
+}
+
+// 福利待遇 - 删除
+export function deleteWelfare (param) {
+  return http.post('/subsidy/category/del', param)
+}
+
 // 福利待遇 - 福利类型 分页查询
 export function getWelfareCategoryPage (param) {
   return http.post('/subsidy/personnel/category/page', param)
 }
+
+// 福利待遇 - 福利类型 明细
+export function getWelfareCategoryDetails (param) {
+  return http.post('/subsidy/personnel/category/detail', param)
+}

+ 87 - 25
src/views/humanResources/welfare/welfareList.vue

@@ -26,7 +26,9 @@
 <script>
 import {
   getWelfarePage,
-  getWelfareDetail
+  getWelfareDetail,
+  getWelfareCategoryPage,
+  deleteWelfare
 } from '@/api/salary'
 import welfareListEdit from './welfareListEdit.vue'
 export default {
@@ -37,25 +39,7 @@ export default {
   data () {
     return {
       title: '',
-      searchItems: [
-        {
-          label: '福利名称',
-          name: 'name',
-          type: 'input',
-          option: {
-            placeholder: '请输入补助名称'
-          }
-        },
-        {
-          label: '福利类别',
-          name: 'subsidyPersonnelCategoryId',
-          type: 'autocomplete',
-          option: {
-            placeholder: '请输入补助分类',
-            fetchSuggestions: this.fetchSuggestions
-          }
-        }
-      ],
+      subsidyPersonnelCategoryIdItems: [],
       searchValues: {},
       headers: [
         {
@@ -86,7 +70,36 @@ export default {
         current: 1,
         size: 10
       },
-      orders: []
+      orders: [],
+      loadingSelect: false
+    }
+  },
+  computed: {
+    searchItems () {
+      return [
+        {
+          label: '福利名称',
+          prop: 'subsidyName',
+          type: 'input',
+          option: {
+            placeholder: '请输入补助名称'
+          }
+        },
+        {
+          label: '福利类别',
+          prop: 'subsidyPersonnelCategoryId',
+          type: 'select',
+          option: {
+            placeholder: '请输入补助分类',
+            filterable: true,
+            remote: true,
+            remoteMethod: this.remoteMethod,
+            defaultFirstOption: true,
+            loading: this.loadingSelect,
+            items: this.subsidyPersonnelCategoryIdItems
+          }
+        }
+      ]
     }
   },
   created () {
@@ -94,6 +107,7 @@ export default {
   },
   methods: {
     async init () {
+      this.loading = true
       try {
         const { data } = await getWelfarePage({
           entity: this.searchValues,
@@ -106,6 +120,8 @@ export default {
         this.total = data.total
       } catch (error) {
         this.$message.error(error)
+      } finally {
+        this.loading = false
       }
     },
     onSearch () {
@@ -116,21 +132,67 @@ export default {
       this.pageInfo.current = page
       this.init()
     },
-    fetchSuggestions (str, cb) {},
+    async remoteMethod (str) {
+      try {
+        this.loadingSelect = true
+        const { data } = await getWelfareCategoryPage({
+          page: {
+            current: 1,
+            size: 10
+          },
+          entity: {
+            title: str || null
+          }
+        })
+        this.subsidyPersonnelCategoryIdItems = data.records
+      } catch (error) {
+        this.subsidyPersonnelCategoryIdItems = []
+        this.$message.error(error)
+      } finally {
+        this.loadingSelect = false
+      }
+    },
     onAdd () {
       this.title = '新增福利'
-      this.$refs.welfareListEditRefs.open()
+      this.$refs.welfareListEditRefs.open({
+        subsidyPersonnelCategoryId: null,
+        subsidySalary: null,
+        subsidyTag: null,
+        subsidyCheck: 0,
+        subsidyName: null
+      })
     },
     async onEdit (item) {
       this.title = '编辑福利'
       try {
         const { data } = await getWelfareDetail({ id: item.subsidyCategoryId })
-        this.$refs.welfareListEditRefs.open(data)
+        this.$refs.welfareListEditRefs.open({
+          subsidyCategoryId: data.subsidyCategoryId,
+          subsidyPersonnelCategoryId: data.subsidyPersonnelCategoryId,
+          subsidySalary: data.subsidySalary,
+          subsidyTag: data.subsidyTag,
+          subsidyCheck: data.subsidyCheck,
+          subsidyName: data.subsidyName
+        })
       } catch (error) {
         this.$message.error(error)
       }
     },
-    onDelete () {}
+    onDelete (item) {
+      this.$confirm('确定删除?', '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(async () => {
+        try {
+          await deleteWelfare({ id: item.subsidyCategoryId })
+          this.$message.success('删除成功')
+          this.init()
+        } catch (error) {
+          this.$message.error(error)
+        }
+      })
+    }
   }
 }
 </script>

+ 47 - 16
src/views/humanResources/welfare/welfareListEdit.vue

@@ -1,11 +1,15 @@
 <template>
-  <m-dialog ref="dialog" v-bind="$attrs" v-on="$listeners">
-    <m-form :items="items" label-width="180px" v-model="values"></m-form>
+  <m-dialog ref="dialog" v-bind="$attrs" v-on="$listeners" @sure="onSure">
+    <m-form ref="form" :items="items" label-width="180px" v-model="values"></m-form>
   </m-dialog>
 </template>
 
 <script>
-import { getWelfareCategoryPage } from '@/api/salary'
+import {
+  getWelfareCategoryPage,
+  saveWelfare,
+  getWelfareCategoryDetails
+} from '@/api/salary'
 export default {
   name: 'welfare-list-edit',
   data () {
@@ -38,6 +42,8 @@ export default {
             filterable: true,
             remote: true,
             remoteMethod: this.remoteMethod,
+            valueKey: 'subsidyPersonnelCategoryId',
+            defaultFirstOption: true,
             loading: this.loading,
             items: this.subsidyPersonnelCategoryIdItems
           },
@@ -82,27 +88,52 @@ export default {
     }
   },
   methods: {
-    open () {
+    async open (item) {
+      this.values = item
       this.$refs.dialog.open()
-    },
-    async remoteMethod (query) {
-      if (query) {
-        this.loading = true
+      if (item.subsidyCategoryId) {
         try {
-          const { data } = await getWelfareCategoryPage({
-            page: {
-              size: 9999,
-              current: 1
-            }
+          const { data } = await getWelfareCategoryDetails({
+            subsidyPersonnelCategoryId: item.subsidyPersonnelCategoryId
           })
-          this.subsidyPersonnelCategoryIdItems = data.records
+          this.subsidyPersonnelCategoryIdItems = [data]
         } catch (error) {
-          this.subsidyPersonnelCategoryIdItems = []
           this.$message.error(error)
         }
-      } else {
+      }
+    },
+    async remoteMethod (query) {
+      this.loading = true
+      try {
+        const { data } = await getWelfareCategoryPage({
+          page: {
+            size: 9999,
+            current: 1
+          },
+          entity: {
+            title: query || null
+          }
+        })
+        this.subsidyPersonnelCategoryIdItems = data.records
+      } catch (error) {
         this.subsidyPersonnelCategoryIdItems = []
+        this.$message.error(error)
+      } finally {
+        this.loading = false
       }
+    },
+    onSure () {
+      this.$refs.form.validate(async valid => {
+        if (!valid) return
+        try {
+          await saveWelfare(this.values)
+          this.$message.success('操作成功')
+          this.$refs.dialog.close()
+          this.$emit('refresh')
+        } catch (error) {
+          this.$message.error(error)
+        }
+      })
     }
   }
 }