salarySolutionEdit.vue 5.4 KB

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