salarySolutionRulesEdit.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <m-card shadow="never">
  3. <div>
  4. <div class="d-flex mb-3">
  5. <div class="boxLabel">参数配置</div>
  6. <div class="boxContent">
  7. <m-table
  8. ref="tableRefs"
  9. shadow="naver"
  10. clearHeader
  11. :items="items"
  12. row-key="index"
  13. :headers="[
  14. { type: 'expand', prop: 'expandProp' },
  15. { label: '参数', prop: 'name' },
  16. { label: '参数类型', prop: 'valueCategory' },
  17. { label: '操作', prop: 'actions' }
  18. ]"
  19. @expand-change="onExpandChange"
  20. >
  21. <template #expandProp="{ row, $index }">
  22. <SalarySolutionRulesEditParam :ref="`salarySolutionRulesEditParamRefs${$index}`" @assign="onAssign(row, $event)"></SalarySolutionRulesEditParam>
  23. </template>
  24. <div class="text-center mt-3">
  25. <m-button icon="el-icon-plus" type="orange" size="small" @click="onAdd">添加参数</m-button>
  26. </div>
  27. <template #valueCategory="{ row }">
  28. {{ DICT_CATEGORY.find(item => item.value === row.valueCategory)?.label }}
  29. </template>
  30. <template #actions="scope">
  31. <m-button size="small" text type="danger" @click="onDelete(scope)">移除</m-button>
  32. </template>
  33. </m-table>
  34. </div>
  35. </div>
  36. <div class="d-flex">
  37. <div class="boxLabel">计算公式</div>
  38. <div class="boxContent">
  39. <m-card shadow="never">
  40. <Toolbar
  41. style="border-bottom: 1px solid #eee"
  42. :editor="editor"
  43. :defaultConfig="toolbarConfig"
  44. :mode="mode"
  45. />
  46. <Editor
  47. style="height: 250px; overflow-y: hidden;"
  48. v-model="formulaData"
  49. :defaultConfig="editorConfig"
  50. :mode="mode"
  51. @onCreated="onCreated"
  52. />
  53. </m-card>
  54. </div>
  55. </div>
  56. </div>
  57. </m-card>
  58. </template>
  59. <script>
  60. import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
  61. import '@wangeditor/editor/dist/css/style.css'
  62. import SalarySolutionRulesEditParam from './salarySolutionRulesEditParam.vue'
  63. import {
  64. DICT_CATEGORY
  65. } from '../salary/solution/utils/Dict'
  66. export default {
  67. name: 'salarySolutionRulesRulesEdit',
  68. components: { Editor, Toolbar, SalarySolutionRulesEditParam },
  69. props: {
  70. item: {
  71. type: Object,
  72. default: () => ({})
  73. }
  74. },
  75. data () {
  76. return {
  77. DICT_CATEGORY,
  78. editor: null,
  79. formulaData: '',
  80. toolbarConfig: {
  81. toolbarKeys: [
  82. 'headerSelect',
  83. // 分割线
  84. '|',
  85. 'bold',
  86. 'italic'
  87. ]
  88. },
  89. editorConfig: { placeholder: '请输入内容...' },
  90. mode: 'default', // or 'simple'
  91. items: []
  92. }
  93. },
  94. beforeDestroy () {
  95. const editor = this.editor
  96. if (editor == null) return
  97. editor.destroy() // 组件销毁时,及时销毁编辑器
  98. },
  99. methods: {
  100. onAssign (row, obj) {
  101. Object.assign(row, obj)
  102. },
  103. onCreated (editor) {
  104. this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
  105. },
  106. onAdd () {
  107. const item = {
  108. index: this.items.length,
  109. name: null,
  110. valueCategory: 0
  111. }
  112. this.items.push(item)
  113. const ref = this.$refs.tableRefs.getRefs()
  114. ref.toggleRowExpansion(item)
  115. },
  116. onDelete (scope) {
  117. this.$confirm('确定要移除改组参数吗?', '提示').then(e => {
  118. this.items.splice(scope.$index, 1)
  119. }).catch(_ => {})
  120. },
  121. valid () {
  122. return new Promise((resolve, reject) => {
  123. const check = this.items.every(e => {
  124. if (!this.$refs[`salarySolutionRulesEditParamRefs${e.index}`]) {
  125. return true
  126. }
  127. return this.$refs[`salarySolutionRulesEditParamRefs${e.index}`].valid()
  128. })
  129. if (!check) {
  130. reject(this.item)
  131. } else {
  132. resolve(this.getValue())
  133. }
  134. })
  135. },
  136. onExpandChange (row, expandedRows) {
  137. const open = expandedRows.find(e => e.index === row.index)
  138. if (!open) {
  139. return
  140. }
  141. this.$nextTick(() => {
  142. this.$refs[`salarySolutionRulesEditParamRefs${row.index}`].setValue(row)
  143. })
  144. },
  145. setValue (data) {
  146. this.items = data.calculateConfigurations.map((e, index) => {
  147. return {
  148. index,
  149. ...e
  150. }
  151. })
  152. this.$nextTick(() => {
  153. this.formulaData = data.calculateFormulas.length ? data.calculateFormulas[0].content : ''
  154. })
  155. },
  156. getValue () {
  157. const calculateConfigurations = this.items.map(e => {
  158. if (!this.$refs[`salarySolutionRulesEditParamRefs${e.index}`]) {
  159. const { index, ...obj } = e
  160. return obj
  161. }
  162. return this.$refs[`salarySolutionRulesEditParamRefs${e.index}`].getValue()
  163. })
  164. return {
  165. category: this.item.title,
  166. calculateConfigurations,
  167. calculateFormulas: [
  168. {
  169. category: this.item.title,
  170. content: this.formulaData
  171. }
  172. ]
  173. }
  174. }
  175. }
  176. }
  177. </script>
  178. <style lang="scss" scoped>
  179. ::v-deep .el-tree-node__content {
  180. height: 40px;
  181. }
  182. .boxLabel {
  183. width: 80px;
  184. text-align: right;
  185. padding-right: 20px;
  186. box-sizing: border-box;
  187. }
  188. .boxContent {
  189. flex: 1;
  190. }
  191. </style>