salarySolutionRulesEdit.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <!-- <m-card shadow="never"> -->
  3. <div>
  4. <el-form-item label="参数配置">
  5. <m-card shadow="never">
  6. <el-row>
  7. <el-col :span="8">参数名称</el-col>
  8. <el-col :span="4" class="text-center">初始值</el-col>
  9. <el-col :span="5" class="text-center">最小值 (是否启用)</el-col>
  10. <el-col :span="5" class="text-center">最大值 (是否启用)</el-col>
  11. <el-col :span="2">操作</el-col>
  12. </el-row>
  13. <el-row
  14. v-for="(row, index) in items"
  15. :key="row.key"
  16. >
  17. <el-col :span="8">
  18. <el-input v-model="row.name" placeholder="请输入参数名称" size="small"></el-input>
  19. </el-col>
  20. <el-col :span="4" class="text-center">
  21. <el-input-number v-model="row.value" placeholder="初始值" size="small"></el-input-number>
  22. </el-col>
  23. <el-col :span="5" class="text-center">
  24. <el-input-number :disabled="!row.miniValueActive" v-model="row.miniValue" placeholder="最小值" size="small"></el-input-number>
  25. <el-switch active-color="#13ce66" class="ml-3" v-model="row.miniValueActive"></el-switch>
  26. </el-col>
  27. <el-col :span="5" class="text-center">
  28. <el-input-number :disabled="!row.maxValueActive" v-model="row.maxValue" placeholder="最大值" size="small"></el-input-number>
  29. <el-switch active-color="#13ce66" class="ml-3" v-model="row.maxValueActive"></el-switch>
  30. </el-col>
  31. <el-col :span="2">
  32. <m-button :disabled="items.length === 1" size="small" type="danger" @click="onDelete(index)">移除</m-button>
  33. </el-col>
  34. </el-row>
  35. <div class="text-center mt-3">
  36. <m-button type="orange" size="small" @click="onAdd">添加一个参数</m-button>
  37. </div>
  38. </m-card>
  39. </el-form-item>
  40. <!-- <div class="d-flex mb-3">
  41. <div class="boxLabel">参数配置</div>
  42. <div class="boxContent">
  43. <m-table
  44. ref="tableRefs"
  45. shadow="naver"
  46. clearHeader
  47. :items="items"
  48. row-key="index"
  49. :headers="[
  50. { type: 'expand', prop: 'expandProp' },
  51. { label: '参数', prop: 'name' },
  52. { label: '参数类型', prop: 'valueCategory' },
  53. { label: '操作', prop: 'actions' }
  54. ]"
  55. >
  56. <template #expandProp="{ $index }">
  57. <SalarySolutionRulesEditParam :ref="`salarySolutionRulesEditParamRefs${$index}`" v-model="items[$index]"></SalarySolutionRulesEditParam>
  58. </template>
  59. <div class="text-center mt-3">
  60. <m-button icon="el-icon-plus" type="orange" size="small" @click="onAdd">添加参数</m-button>
  61. </div>
  62. <template #valueCategory="{ row }">
  63. {{ DICT_CATEGORY.find(item => item.value === row.valueCategory)?.label }}
  64. </template>
  65. <template #actions="scope">
  66. <m-button size="small" text type="danger" @click="onDelete(scope)">移除</m-button>
  67. </template>
  68. </m-table>
  69. </div>
  70. </div>
  71. <div class="d-flex">
  72. <div class="boxLabel">计算公式</div>
  73. <div class="boxContent">
  74. <m-card shadow="never">
  75. <Toolbar
  76. style="border-bottom: 1px solid #eee"
  77. :editor="editor"
  78. :defaultConfig="toolbarConfig"
  79. :mode="mode"
  80. />
  81. <Editor
  82. style="height: 250px; overflow-y: hidden;"
  83. v-model="formulaData"
  84. :defaultConfig="editorConfig"
  85. :mode="mode"
  86. @onCreated="onCreated"
  87. />
  88. </m-card>
  89. </div>
  90. </div> -->
  91. <el-form-item label="计算公式">
  92. <m-card shadow="never">
  93. <Toolbar
  94. style="border-bottom: 1px solid #eee"
  95. :editor="editor"
  96. :defaultConfig="toolbarConfig"
  97. :mode="mode"
  98. />
  99. <Editor
  100. style="height: 250px; overflow-y: hidden;"
  101. v-model="formulaData"
  102. :defaultConfig="editorConfig"
  103. :mode="mode"
  104. @onCreated="onCreated"
  105. />
  106. </m-card>
  107. </el-form-item>
  108. </div>
  109. <!-- </m-card> -->
  110. </template>
  111. <script>
  112. import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
  113. import '@wangeditor/editor/dist/css/style.css'
  114. // import {
  115. // DICT_CATEGORY
  116. // } from '../utils/Dict'
  117. export default {
  118. name: 'salarySolutionRulesRulesEdit',
  119. components: { Editor, Toolbar },
  120. // props: {
  121. // item: {
  122. // type: Object,
  123. // default: () => ({})
  124. // }
  125. // },
  126. data () {
  127. return {
  128. // DICT_CATEGORY,
  129. editor: null,
  130. formulaData: '',
  131. toolbarConfig: {
  132. toolbarKeys: [
  133. 'headerSelect',
  134. // 分割线
  135. '|',
  136. 'bold',
  137. 'italic'
  138. ]
  139. },
  140. editorConfig: { placeholder: '请输入内容...' },
  141. mode: 'default', // or 'simple'
  142. id: 0,
  143. items: [
  144. {
  145. key: 0,
  146. miniValue: 0,
  147. miniValueActive: true,
  148. maxValue: 1,
  149. maxValueActive: true,
  150. name: null,
  151. value: 0,
  152. valueCategory: 0
  153. }
  154. ]
  155. }
  156. },
  157. beforeDestroy () {
  158. const editor = this.editor
  159. if (editor == null) return
  160. editor.destroy() // 组件销毁时,及时销毁编辑器
  161. },
  162. methods: {
  163. onCreated (editor) {
  164. this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
  165. },
  166. onAdd () {
  167. // const item = {
  168. // index: this.items.length,
  169. // name: null,
  170. // valueCategory: 0
  171. // }
  172. this.items.push({
  173. key: this.id++,
  174. miniValue: 0,
  175. miniValueActive: true,
  176. maxValue: 1,
  177. maxValueActive: true,
  178. name: null,
  179. value: 0,
  180. valueCategory: 0
  181. })
  182. // const ref = this.$refs.tableRefs.getRefs()
  183. // ref.toggleRowExpansion(item)
  184. },
  185. onDelete (index) {
  186. this.items.splice(index, 1)
  187. // this.$confirm('确定要移除改组参数吗?', '提示').then(e => {
  188. // this.items.splice(scope.$index, 1)
  189. // }).catch(_ => {})
  190. },
  191. valid () {
  192. return new Promise((resolve, reject) => {
  193. const check = this.items.every(e => {
  194. return e.name && e.value !== null && (!e.miniValueActive || e.miniValue !== null) && (!e.maxValueActive || e.maxValue !== null)
  195. })
  196. if (!check) {
  197. reject(check)
  198. } else {
  199. resolve(this.getValue())
  200. }
  201. })
  202. },
  203. setValue (data) {
  204. this.id = 0
  205. this.formulaData = data.calculateFormulas.length ? data.calculateFormulas[0].content : ''
  206. if (!data.calculateConfigurations.length) {
  207. this.items = [
  208. {
  209. key: 0,
  210. miniValue: 0,
  211. miniValueActive: true,
  212. maxValue: 1,
  213. maxValueActive: true,
  214. name: null,
  215. value: 0,
  216. valueCategory: 0
  217. }
  218. ]
  219. return
  220. }
  221. this.items = data.calculateConfigurations.map(e => {
  222. return {
  223. key: this.id++,
  224. maxValueActive: e.maxValue !== null,
  225. miniValueActive: e.miniValue !== null,
  226. ...e
  227. }
  228. })
  229. },
  230. getValue () {
  231. const calculateConfigurations = this.items.map(e => {
  232. const {
  233. name,
  234. valueCategory,
  235. miniValue,
  236. miniValueActive,
  237. maxValue,
  238. maxValueActive,
  239. value
  240. } = e
  241. // if (valueCategory === 0) {
  242. return {
  243. name,
  244. valueCategory,
  245. miniValue: miniValueActive ? miniValue : null,
  246. maxValue: maxValueActive ? maxValue : null,
  247. value: value.toString()
  248. }
  249. // }
  250. // const _value = JSON.stringify(value.map(_e => {
  251. // return {
  252. // name: _e.name,
  253. // value: _e.value
  254. // }
  255. // }))
  256. // if (valueCategory === 1) {
  257. // return {
  258. // name,
  259. // valueCategory,
  260. // value: _value
  261. // }
  262. // }
  263. // return {
  264. // name,
  265. // valueCategory,
  266. // miniValue: miniValue ?? null,
  267. // maxValue: maxValue ?? null,
  268. // value: _value
  269. // }
  270. })
  271. return {
  272. category: '类型',
  273. calculateConfigurations,
  274. calculateFormulas: [
  275. {
  276. category: '类型',
  277. content: this.formulaData
  278. }
  279. ]
  280. }
  281. }
  282. }
  283. }
  284. </script>
  285. <style lang="scss" scoped>
  286. ::v-deep .el-tree-node__content {
  287. height: 40px;
  288. }
  289. .boxLabel {
  290. width: 80px;
  291. text-align: right;
  292. padding-right: 20px;
  293. box-sizing: border-box;
  294. }
  295. .boxContent {
  296. flex: 1;
  297. }
  298. </style>