index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div>
  3. <m-search class="mb-3" :items="searchItems" v-model="searchValues" @search="onSearch">
  4. <template #button>
  5. <m-button type="primary" icon="el-icon-plus" plain @click="onAdd">新增</m-button>
  6. </template>
  7. </m-search>
  8. <m-table
  9. v-loading="loading"
  10. row-key="calculateConfigurationId"
  11. :items="items"
  12. :headers="headers"
  13. :page-size="pageInfo.size"
  14. :page-current="pageInfo.current"
  15. :total="total"
  16. @page-change="onPageChange"
  17. >
  18. <template #actions="{ row }">
  19. <m-button text type="primary" @click="onEdit(row)" size="small">编辑</m-button>
  20. <m-button text type="danger" @click="onDelete(row)" size="small">删除</m-button>
  21. </template>
  22. </m-table>
  23. <config-edit ref="editRefs" @refresh="onInit"></config-edit>
  24. </div>
  25. </template>
  26. <script>
  27. import ConfigEdit from './configEdit'
  28. import {
  29. getConfigPage,
  30. getConfigCateGories,
  31. deleteConfig,
  32. getConfig
  33. } from '@/api/salary'
  34. export default {
  35. name: 'salary-config',
  36. components: { ConfigEdit },
  37. data () {
  38. return {
  39. searchItems: [
  40. { label: '关键词', prop: 'keyword', type: 'input', option: { placeholder: '请输入关键词' } },
  41. {
  42. label: '分类',
  43. prop: 'category',
  44. type: 'autocomplete',
  45. option: {
  46. clearable: true,
  47. placeholder: '请输入分类',
  48. fetchSuggestions: this.fetchSuggestions
  49. }
  50. }
  51. ],
  52. searchValues: {},
  53. headers: [
  54. { label: '配置名称', prop: 'name' },
  55. { label: '数值', prop: 'value' },
  56. { label: '分类', prop: 'category' },
  57. { label: '描述', prop: 'tag' },
  58. { label: '创建时间', prop: 'createDate' },
  59. { label: '操作', prop: 'actions' }
  60. ],
  61. items: [],
  62. loading: false,
  63. pageInfo: {
  64. size: 10,
  65. current: 1
  66. },
  67. total: 0
  68. }
  69. },
  70. mounted () {
  71. this.$emit('mounted')
  72. },
  73. methods: {
  74. async onInit () {
  75. this.loading = true
  76. try {
  77. const { data } = await getConfigPage({
  78. ...this.searchValues,
  79. ...this.pageInfo,
  80. history: 0
  81. })
  82. this.items = data.records
  83. this.total = data.total
  84. } catch (error) {
  85. this.$message.error(error)
  86. } finally {
  87. this.loading = false
  88. }
  89. },
  90. async fetchSuggestions (category, cb) {
  91. try {
  92. const { data } = await getConfigCateGories({ category })
  93. cb(data.map(e => {
  94. return {
  95. value: e
  96. }
  97. }))
  98. } catch (error) {
  99. this.$message.error(error)
  100. }
  101. },
  102. onSearch () {
  103. this.pageInfo.current = 1
  104. this.onInit()
  105. },
  106. onAdd () {
  107. this.$refs.editRefs.open()
  108. },
  109. async onEdit (item) {
  110. try {
  111. const { data } = await getConfig(item.calculateConfigurationId)
  112. this.$refs.editRefs.open(data)
  113. } catch (error) {
  114. this.$message.error(error)
  115. }
  116. },
  117. onDelete (item) {
  118. this.$confirm('确定删除该配置吗?', '提示', {
  119. confirmButtonText: '确定',
  120. cancelButtonText: '取消',
  121. type: 'warning'
  122. }).then(async () => {
  123. try {
  124. await deleteConfig(item.calculateConfigurationId)
  125. this.$message.success('删除成功')
  126. this.onInit()
  127. } catch (error) {
  128. this.$message.error(error)
  129. }
  130. }).catch(() => {})
  131. },
  132. onPageChange (index) {
  133. this.pageInfo.current = index
  134. this.onInit()
  135. },
  136. onHistory (row) {
  137. this.$refs.configHistoryRefs.open(row)
  138. }
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. </style>