welfareList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div>
  3. <m-search :items="searchItems" v-model="searchValues" @search="onSearch" class="mb-3">
  4. <template #button>
  5. <m-button type="primary" icon="el-icon-plus" @click="onAdd">新增</m-button>
  6. </template>
  7. </m-search>
  8. <m-table
  9. :items="items"
  10. :headers="headers"
  11. :loading="loading"
  12. :total="total"
  13. :page-size="pageInfo.size"
  14. :page-current="pageInfo.current"
  15. @page-change="onPageChange"
  16. >
  17. <template #actions="{ row }">
  18. <m-button text type="primary" size="small" @click="onEdit(row)">编辑</m-button>
  19. <m-button text type="danger" size="small" @click="onDelete(row)">删除</m-button>
  20. </template>
  21. </m-table>
  22. <welfareListEdit ref="welfareListEditRefs" :title="title"></welfareListEdit>
  23. </div>
  24. </template>
  25. <script>
  26. import {
  27. getWelfarePage,
  28. getWelfareDetail,
  29. getWelfareCategoryPage,
  30. deleteWelfare
  31. } from '@/api/salary'
  32. import welfareListEdit from './welfareListEdit.vue'
  33. export default {
  34. name: 'welfare-list',
  35. components: {
  36. welfareListEdit
  37. },
  38. data () {
  39. return {
  40. title: '',
  41. subsidyPersonnelCategoryIdItems: [],
  42. searchValues: {},
  43. headers: [
  44. {
  45. label: '福利名称',
  46. prop: 'name'
  47. },
  48. {
  49. label: '福利类别',
  50. prop: 'subsidyPersonnelCategoryId'
  51. },
  52. {
  53. label: '金额(元 / 月)',
  54. prop: 'subsidySalary'
  55. },
  56. {
  57. label: '描述',
  58. prop: 'subsidyTag'
  59. },
  60. {
  61. label: '操作',
  62. prop: 'actions'
  63. }
  64. ],
  65. items: [],
  66. loading: false,
  67. total: 0,
  68. pageInfo: {
  69. current: 1,
  70. size: 10
  71. },
  72. orders: [],
  73. loadingSelect: false
  74. }
  75. },
  76. computed: {
  77. searchItems () {
  78. return [
  79. {
  80. label: '福利名称',
  81. prop: 'subsidyName',
  82. type: 'input',
  83. option: {
  84. placeholder: '请输入补助名称'
  85. }
  86. },
  87. {
  88. label: '福利类别',
  89. prop: 'subsidyPersonnelCategoryId',
  90. type: 'select',
  91. option: {
  92. placeholder: '请输入补助分类',
  93. filterable: true,
  94. remote: true,
  95. remoteMethod: this.remoteMethod,
  96. defaultFirstOption: true,
  97. loading: this.loadingSelect,
  98. items: this.subsidyPersonnelCategoryIdItems
  99. }
  100. }
  101. ]
  102. }
  103. },
  104. created () {
  105. this.init()
  106. },
  107. methods: {
  108. async init () {
  109. this.loading = true
  110. try {
  111. const { data } = await getWelfarePage({
  112. entity: this.searchValues,
  113. page: {
  114. ...this.pageInfo,
  115. orders: this.orders
  116. }
  117. })
  118. this.items = data.records
  119. this.total = data.total
  120. } catch (error) {
  121. this.$message.error(error)
  122. } finally {
  123. this.loading = false
  124. }
  125. },
  126. onSearch () {
  127. this.pageInfo.current = 1
  128. this.init()
  129. },
  130. onPageChange (page) {
  131. this.pageInfo.current = page
  132. this.init()
  133. },
  134. async remoteMethod (str) {
  135. try {
  136. this.loadingSelect = true
  137. const { data } = await getWelfareCategoryPage({
  138. page: {
  139. current: 1,
  140. size: 10
  141. },
  142. entity: {
  143. title: str || null
  144. }
  145. })
  146. this.subsidyPersonnelCategoryIdItems = data.records
  147. } catch (error) {
  148. this.subsidyPersonnelCategoryIdItems = []
  149. this.$message.error(error)
  150. } finally {
  151. this.loadingSelect = false
  152. }
  153. },
  154. onAdd () {
  155. this.title = '新增福利'
  156. this.$refs.welfareListEditRefs.open({
  157. subsidyPersonnelCategoryId: null,
  158. subsidySalary: null,
  159. subsidyTag: null,
  160. subsidyCheck: 0,
  161. subsidyName: null
  162. })
  163. },
  164. async onEdit (item) {
  165. this.title = '编辑福利'
  166. try {
  167. const { data } = await getWelfareDetail({ id: item.subsidyCategoryId })
  168. this.$refs.welfareListEditRefs.open({
  169. subsidyCategoryId: data.subsidyCategoryId,
  170. subsidyPersonnelCategoryId: data.subsidyPersonnelCategoryId,
  171. subsidySalary: data.subsidySalary,
  172. subsidyTag: data.subsidyTag,
  173. subsidyCheck: data.subsidyCheck,
  174. subsidyName: data.subsidyName
  175. })
  176. } catch (error) {
  177. this.$message.error(error)
  178. }
  179. },
  180. onDelete (item) {
  181. this.$confirm('确定删除?', '提示', {
  182. confirmButtonText: '确定',
  183. cancelButtonText: '取消',
  184. type: 'warning'
  185. }).then(async () => {
  186. try {
  187. await deleteWelfare({ id: item.subsidyCategoryId })
  188. this.$message.success('删除成功')
  189. this.init()
  190. } catch (error) {
  191. this.$message.error(error)
  192. }
  193. })
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="scss" scoped>
  199. </style>