salarySolutionEdit.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. filterable: true,
  61. clearable: true,
  62. placeholder: '请选择机构',
  63. options: this.organizationTree,
  64. showAllLevels: false,
  65. props: {
  66. emitPath: false,
  67. checkStrictly: true,
  68. value: 'organizationNo',
  69. label: 'organizationName',
  70. children: 'child'
  71. }
  72. },
  73. handles: {
  74. change: this.onchange
  75. },
  76. rules: [
  77. { required: true, message: '请选择绩效机构', trigger: 'change' }
  78. ]
  79. },
  80. {
  81. label: '绩效职务',
  82. prop: 'postNames',
  83. type: 'select',
  84. options: {
  85. placeholder: '请选择绩效职务',
  86. filterable: true,
  87. collapseTags: true,
  88. multiple: true,
  89. items: this.postNamesItems
  90. },
  91. rules: [
  92. { required: true, message: '请选择绩效职务', trigger: 'change' }
  93. ]
  94. }
  95. ]
  96. }
  97. },
  98. methods: {
  99. async open (item) {
  100. this.$refs.dialog.open()
  101. this.formQuery.title = item?.title ?? null
  102. this.formQuery.tag = item?.tag ?? null
  103. this.formQuery.organizationNo = item?.organizationNo ?? null
  104. this.formQuery.postNames = []
  105. this.itemData = {}
  106. this.$nextTick(() => {
  107. this.$refs.form.clearValidate()
  108. })
  109. if (!item) {
  110. return
  111. }
  112. this.loading = true
  113. try {
  114. const { data } = await getSolutionDetails({
  115. performanceSolutionId: item.performanceSolutionId
  116. })
  117. this.itemData = data
  118. this.onchange(this.formQuery.organizationNo)
  119. this.formQuery.postNames = item.postNames
  120. } catch (error) {
  121. this.$message.error(error)
  122. } finally {
  123. this.loading = false
  124. }
  125. },
  126. async onchange (organizationNo) {
  127. this.formQuery.postNames = []
  128. if (!organizationNo) {
  129. return
  130. }
  131. try {
  132. const { data } = await getPostNameByOrganizationNo({
  133. organizationNo
  134. })
  135. this.postNamesItems = (data && data.map(e => {
  136. return {
  137. label: e,
  138. value: e
  139. }
  140. })) || []
  141. } catch (error) {
  142. this.$message.error(error)
  143. }
  144. },
  145. onSure () {
  146. this.$refs.form.validate(async valid => {
  147. if (valid) {
  148. const query = {
  149. entity: {
  150. performanceSolutionId: this.itemData.entity?.performanceSolutionId,
  151. ...this.formQuery
  152. },
  153. performanceSolutionDetailRespCategoryVos: this.itemData.performanceSolutionDetailRespCategoryVos
  154. }
  155. try {
  156. await saveSolution(query)
  157. this.$refs.dialog.close()
  158. this.$emit('refresh')
  159. this.$message.success('保存成功')
  160. } catch (error) {
  161. this.$message.error(error)
  162. }
  163. }
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. </style>