salarySolutionRules.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <m-dialog ref="dialog" title="规则配置" width="1000px" @sure="onSure">
  3. <el-form v-loading="loading" label-width="100px">
  4. <el-form-item label="名称">
  5. <el-tag color="primary">{{ itemData.title }}</el-tag>
  6. </el-form-item>
  7. <el-form-item label="类型">
  8. <template v-slot:default>
  9. <el-tabs type="card" addable v-model="editableTabsValue" @edit="onTabsEdit">
  10. <el-tab-pane
  11. v-for="tab in editableTabs"
  12. :key="tab.name"
  13. :name="tab.name"
  14. :closable="editableTabs.length > 1"
  15. >
  16. <template v-slot:label>
  17. {{ tab.title }}
  18. <el-popover
  19. placement="top-start"
  20. width="200"
  21. trigger="click"
  22. >
  23. <el-input v-model="tab.title" size="small"></el-input>
  24. <span class="ml-3" slot="reference" @click.stop="">
  25. <i class="el-icon-edit"></i>
  26. </span>
  27. </el-popover>
  28. </template>
  29. <template v-slot:default>
  30. <SalarySolutionRulesEdit :item="tab" ref="salarySolutionRulesEditRefs"></SalarySolutionRulesEdit>
  31. </template>
  32. </el-tab-pane>
  33. </el-tabs>
  34. </template>
  35. </el-form-item>
  36. <el-form-item label="提交说明">
  37. <el-input v-model="versionTag" placeholder="请输入本次修改的记录描述"></el-input>
  38. </el-form-item>
  39. </el-form>
  40. </m-dialog>
  41. </template>
  42. <script>
  43. import SalarySolutionRulesEdit from './salarySolutionRulesEdit.vue'
  44. import {
  45. saveSolution,
  46. getSolutionDetails
  47. } from '@/api/salary'
  48. export default {
  49. name: 'salarySolutionRules',
  50. components: {
  51. SalarySolutionRulesEdit
  52. },
  53. inject: ['env'],
  54. data () {
  55. return {
  56. versionTag: null,
  57. editableTabsValue: '1',
  58. editableTabs: [],
  59. ids: 1,
  60. itemData: {},
  61. loading: false
  62. }
  63. },
  64. methods: {
  65. async open (item) {
  66. this.itemData = item
  67. this.versionTag = null
  68. this.$refs.dialog.open()
  69. this.loading = true
  70. this.ids = 1
  71. this.editableTabsValue = '1'
  72. try {
  73. const { data } = await getSolutionDetails({
  74. performanceSolutionId: item.performanceSolutionId
  75. })
  76. if (!data.performanceSolutionDetailRespCategoryVos.length) {
  77. this.editableTabs = [{
  78. title: '类型1',
  79. name: '1'
  80. }]
  81. return
  82. }
  83. this.editableTabs = data.performanceSolutionDetailRespCategoryVos.map((e, index) => {
  84. const key = String(index + 1)
  85. return {
  86. title: e.category,
  87. name: key
  88. }
  89. })
  90. this.ids = this.editableTabs.length
  91. this.$nextTick(() => {
  92. this.$refs.salarySolutionRulesEditRefs.forEach((e, index) => {
  93. e.setValue(data.performanceSolutionDetailRespCategoryVos[index])
  94. })
  95. })
  96. } catch (error) {
  97. this.$message.error(error)
  98. } finally {
  99. this.loading = false
  100. }
  101. },
  102. onTabsEdit (targetName, action) {
  103. if (action === 'add') {
  104. this.ids++
  105. this.editableTabs.push(
  106. { title: '类型' + this.ids, name: String(this.ids) }
  107. )
  108. }
  109. if (action === 'remove') {
  110. if (this.editableTabs.length === 1) {
  111. this.$message.error('至少保留一个分类')
  112. return
  113. }
  114. const index = this.editableTabs.findIndex(tab => tab.name === targetName)
  115. this.editableTabs.splice(index, 1)
  116. if (index === 0) {
  117. this.editableTabsValue = this.editableTabs[0].name
  118. return
  119. }
  120. if (targetName === this.editableTabsValue) {
  121. this.editableTabsValue = this.editableTabs[index - 1].name
  122. }
  123. }
  124. },
  125. async onSure () {
  126. // 验证
  127. Promise.all(this.$refs.salarySolutionRulesEditRefs.map(e => e.valid())).then(async data => {
  128. if (!this.versionTag) {
  129. this.$message.error('请填写提交说明')
  130. return
  131. }
  132. try {
  133. await saveSolution({
  134. entity: {
  135. performanceSolutionId: this.itemData.performanceSolutionId,
  136. env: this.env,
  137. versionTag: this.versionTag,
  138. versionType: 0 // 规则变更
  139. },
  140. performanceSolutionDetailRespCategoryVos: data
  141. })
  142. this.$refs.dialog.close()
  143. this.$emit('refresh')
  144. this.$message.success('保存成功')
  145. } catch (error) {
  146. this.$message.error(error)
  147. }
  148. }).catch(error => {
  149. this.editableTabsValue = error.name
  150. this.$message.error('请填充完整')
  151. })
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. </style>