salarySolutionEdit.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <m-dialog ref="dialog" :title="itemData.entity ? '编辑' : '新增'" @sure="onSure">
  3. <m-form ref="form" v-model="formQuery" :items="items" v-loading="loading"></m-form>
  4. </m-dialog>
  5. </template>
  6. <script>
  7. import {
  8. saveSolution,
  9. getSolutionDetails
  10. } from '@/api/salary'
  11. import {
  12. getPostNameByOrganizationNo
  13. // getOrganizationAtlasPostName
  14. } from '@/api/system'
  15. import { mapGetters } from 'vuex'
  16. export default {
  17. name: 'salary-solution-edit',
  18. data () {
  19. return {
  20. loading: false,
  21. formQuery: {
  22. title: null,
  23. tag: null,
  24. organizationNo: null,
  25. postNames: [],
  26. rewriteType: 0
  27. },
  28. postNamesItems: [],
  29. itemData: {}
  30. }
  31. },
  32. computed: {
  33. ...mapGetters(['organizationTree']),
  34. items () {
  35. return [
  36. {
  37. label: '方案名称',
  38. prop: 'title',
  39. type: 'input',
  40. rules: [
  41. { required: true, message: '请输入方案名称', trigger: 'blur' }
  42. ],
  43. options: {
  44. placeholder: '请输入方案名称'
  45. }
  46. },
  47. {
  48. label: '方案描述',
  49. prop: 'tag',
  50. type: 'input',
  51. options: {
  52. placeholder: '请输入方案描述'
  53. }
  54. },
  55. {
  56. label: '绩效机构',
  57. prop: 'organizationNo',
  58. type: 'cascader',
  59. options: {
  60. clearable: true,
  61. placeholder: '请选择机构',
  62. options: this.organizationTree,
  63. showAllLevels: false,
  64. props: {
  65. emitPath: false,
  66. checkStrictly: true,
  67. value: 'organizationNo',
  68. label: 'organizationName',
  69. children: 'child'
  70. }
  71. },
  72. handles: {
  73. change: this.onchange
  74. },
  75. rules: [
  76. { required: true, message: '请选择绩效机构', trigger: 'change' }
  77. ]
  78. },
  79. {
  80. label: '绩效职务',
  81. prop: 'postNames',
  82. type: 'select',
  83. options: {
  84. placeholder: '请选择绩效职务',
  85. collapseTags: true,
  86. multiple: true,
  87. items: this.postNamesItems
  88. },
  89. rules: [
  90. { required: true, message: '请选择绩效职务', trigger: 'change' }
  91. ]
  92. },
  93. {
  94. label: '下级自定义',
  95. prop: 'rewriteType',
  96. type: 'radioGroup',
  97. options: {
  98. items: [
  99. {
  100. text: '允许',
  101. label: 0
  102. },
  103. {
  104. text: '不允许',
  105. label: 1
  106. }
  107. ]
  108. },
  109. rules: [
  110. { required: true, message: '请选择下级自定义', trigger: 'change' }
  111. ]
  112. }
  113. ]
  114. }
  115. },
  116. methods: {
  117. async open (item) {
  118. this.$refs.dialog.open()
  119. this.formQuery.title = item?.title ?? null
  120. this.formQuery.tag = item?.tag ?? null
  121. this.formQuery.organizationNo = item?.organizationNo ?? null
  122. this.formQuery.postNames = item?.postNames ?? []
  123. this.itemData = {}
  124. this.$nextTick(() => {
  125. this.$refs.form.clearValidate()
  126. })
  127. if (!item) {
  128. return
  129. }
  130. this.loading = true
  131. try {
  132. const { data } = await getSolutionDetails({
  133. performanceSolutionId: item.performanceSolutionId
  134. })
  135. this.itemData = data
  136. } catch (error) {
  137. this.$message.error(error)
  138. } finally {
  139. this.loading = false
  140. }
  141. },
  142. async onchange (organizationNo) {
  143. this.formQuery.postNames = []
  144. if (!organizationNo) {
  145. return
  146. }
  147. try {
  148. const { data } = await getPostNameByOrganizationNo({
  149. organizationNo
  150. })
  151. this.postNamesItems = (data && data.map(e => {
  152. return {
  153. label: e,
  154. value: e
  155. }
  156. })) || []
  157. } catch (error) {
  158. this.$message.error(error)
  159. }
  160. },
  161. onSure () {
  162. this.$refs.form.validate(async valid => {
  163. if (valid) {
  164. const query = {
  165. entity: {
  166. performanceSolutionId: this.itemData.entity?.performanceSolutionId,
  167. ...this.formQuery
  168. },
  169. calculateConfigurations: this.itemData.calculateConfigurations ?? []
  170. }
  171. try {
  172. await saveSolution(query)
  173. this.$refs.dialog.close()
  174. this.$emit('refresh')
  175. this.$message.success('保存成功')
  176. } catch (error) {
  177. this.$message.error(error)
  178. }
  179. }
  180. })
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. </style>