welfareList.vue 5.5 KB

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