salarySolutionRules.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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>
  37. </m-dialog>
  38. </template>
  39. <script>
  40. import SalarySolutionRulesEdit from './salarySolutionRulesEdit.vue'
  41. import {
  42. saveSolution,
  43. getSolutionDetails
  44. } from '@/api/salary'
  45. export default {
  46. name: 'salarySolutionRules',
  47. components: {
  48. SalarySolutionRulesEdit
  49. },
  50. inject: ['env'],
  51. data () {
  52. return {
  53. editableTabsValue: '1',
  54. editableTabs: [],
  55. ids: 1,
  56. itemData: {},
  57. loading: false
  58. }
  59. },
  60. methods: {
  61. async open (item) {
  62. this.itemData = item
  63. this.$refs.dialog.open()
  64. this.loading = true
  65. this.ids = 1
  66. this.editableTabsValue = '1'
  67. try {
  68. const { data } = await getSolutionDetails({
  69. performanceSolutionId: item.performanceSolutionId
  70. })
  71. if (!data.performanceSolutionDetailRespCategoryVos.length) {
  72. this.editableTabs = [{
  73. title: '类型1',
  74. name: '1'
  75. }]
  76. return
  77. }
  78. this.editableTabs = data.performanceSolutionDetailRespCategoryVos.map((e, index) => {
  79. const key = String(index + 1)
  80. return {
  81. title: e.category,
  82. name: key
  83. }
  84. })
  85. this.ids = this.editableTabs.length
  86. this.$nextTick(() => {
  87. this.$refs.salarySolutionRulesEditRefs.forEach((e, index) => {
  88. e.setValue(data.performanceSolutionDetailRespCategoryVos[index])
  89. })
  90. })
  91. } catch (error) {
  92. this.$message.error(error)
  93. } finally {
  94. this.loading = false
  95. }
  96. },
  97. onTabsEdit (targetName, action) {
  98. if (action === 'add') {
  99. this.ids++
  100. this.editableTabs.push(
  101. { title: '类型' + this.ids, name: String(this.ids) }
  102. )
  103. }
  104. if (action === 'remove') {
  105. if (this.editableTabs.length === 1) {
  106. this.$message.error('至少保留一个分类')
  107. return
  108. }
  109. const index = this.editableTabs.findIndex(tab => tab.name === targetName)
  110. this.editableTabs.splice(index, 1)
  111. if (index === 0) {
  112. this.editableTabsValue = this.editableTabs[0].name
  113. return
  114. }
  115. if (targetName === this.editableTabsValue) {
  116. this.editableTabsValue = this.editableTabs[index - 1].name
  117. }
  118. }
  119. },
  120. async onSure () {
  121. // 验证
  122. Promise.all(this.$refs.salarySolutionRulesEditRefs.map(e => e.valid())).then(async data => {
  123. try {
  124. await saveSolution({
  125. entity: {
  126. performanceSolutionId: this.itemData.performanceSolutionId,
  127. env: this.env
  128. },
  129. performanceSolutionDetailRespCategoryVos: data
  130. })
  131. this.$refs.dialog.close()
  132. this.$emit('refresh')
  133. this.$message.success('保存成功')
  134. } catch (error) {
  135. this.$message.error(error)
  136. }
  137. }).catch(error => {
  138. console.log(error)
  139. this.editableTabsValue = error.name
  140. this.$message.error('请填充完整')
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. </style>