workflowApproved.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <m-dialog title="审批配置" ref="dialog" @sure="onSure">
  3. <el-form ref="form" inline :model="formValues" label-width="70px" >
  4. <el-form-item label="工作流">
  5. <el-tag>{{ item.workFlowTmplate?.name }}</el-tag>
  6. </el-form-item>
  7. <el-form-item label="工作流">
  8. <m-card shadow="never">
  9. <m-card
  10. v-for="(item, index) in formValues.items"
  11. :key="item.key"
  12. class="mb-5 cardBox"
  13. >
  14. <el-form-item label="处理对象" :prop="`items.${index}.handleType`">
  15. <el-select v-model="item.handleType" placeholder="请选择处理对象" @change="onChange(item)">
  16. <el-option label="指定人" value="0"></el-option>
  17. <el-option label="指定部室岗位" value="1"></el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item label="处理方" :prop="`items.${index}.handleValue`" :rules="{ required: true, message: '请选择处理方', trigger: 'change' }">
  21. <el-cascader
  22. v-model="item.handleValue"
  23. :ref="`cascader_${index}`"
  24. placeholder="请选择处理方"
  25. :show-all-levels="false"
  26. :options="options[item.handleType]"
  27. :props="{
  28. emitPath: false,
  29. value: 'id',
  30. label: 'title',
  31. children: 'child'
  32. }"
  33. @change="onChangeCascader(item, `cascader_${index}`)"
  34. ></el-cascader>
  35. </el-form-item>
  36. <div class="button-group">
  37. <m-button :disabled="index === 0" icon="el-icon-top" circle size="mini" @click="onUp(index)"></m-button>
  38. <m-button :disabled="index === formValues.items.length - 1" icon="el-icon-bottom" circle size="mini" @click="onDown(index)"></m-button>
  39. <m-button type="danger" icon="el-icon-delete" circle size="mini" @click="onDelete(index)"></m-button>
  40. </div>
  41. </m-card>
  42. <div class="text-center">
  43. <el-button type="orange" @click="onAdd" icon="el-icon-plus">新增一条记录</el-button>
  44. </div>
  45. </m-card>
  46. </el-form-item>
  47. </el-form>
  48. </m-dialog>
  49. </template>
  50. <script>
  51. import {
  52. saveWorkflow
  53. } from '@/api/workflow'
  54. import {
  55. getOrganizationAtlasAll
  56. } from '@/api/system'
  57. import { mapGetters } from 'vuex'
  58. import { cloneDeep } from 'lodash'
  59. export default {
  60. name: 'workflowApproved',
  61. data () {
  62. return {
  63. key: 0,
  64. formValues: {
  65. items: [
  66. {
  67. key: 0,
  68. handleType: '0',
  69. handleValue: null,
  70. handleValueData: {}
  71. }
  72. ]
  73. },
  74. item: {},
  75. options: []
  76. }
  77. },
  78. computed: {
  79. ...mapGetters(['organizationTree']),
  80. personOrganizationTree () {
  81. return cloneDeep(this.organizationTree)
  82. },
  83. postOrganizationTree () {
  84. return cloneDeep(this.organizationTree)
  85. }
  86. },
  87. methods: {
  88. async open (item) {
  89. this.item = item
  90. this.$refs.dialog.open()
  91. this.loading = true
  92. if (item.workFlowTmplateItems.length > 0) {
  93. this.formValues.items = item.workFlowTmplateItems.map((e, index) => {
  94. return {
  95. handleType: e.handleType,
  96. handleValue: e.handleType === '0' ? e.handleValue.userId : e.handleValue.postName,
  97. handleValueData: e.handleValue, // 回显
  98. key: index
  99. }
  100. })
  101. }
  102. this.key = item.workFlowTmplateItems.length + 1
  103. try {
  104. const { data: person } = await getOrganizationAtlasAll({ type: 0 })
  105. this.options.push(person)
  106. const { data: post } = await getOrganizationAtlasAll({ type: 1 })
  107. this.options.push(post)
  108. } catch (error) {
  109. this.$message.error(error)
  110. } finally {
  111. this.loading = false
  112. }
  113. },
  114. onAdd () {
  115. this.key++
  116. this.formValues.items.push({
  117. key: this.key,
  118. handleType: '0',
  119. handleValue: null,
  120. handleValueData: {}
  121. })
  122. },
  123. // 向上移动一位
  124. onUp (index) {
  125. if (index === 0) return
  126. const temp = this.formValues.items[index]
  127. this.formValues.items.splice(index, 1)
  128. this.formValues.items.splice(index - 1, 0, temp)
  129. },
  130. // 向下移动一位
  131. onDown (index) {
  132. if (index === this.formValues.items.length - 1) return
  133. const temp = this.formValues.items[index]
  134. this.formValues.items.splice(index, 1)
  135. this.formValues.items.splice(index + 1, 0, temp)
  136. },
  137. // 删除
  138. onDelete (index) {
  139. this.formValues.items.splice(index, 1)
  140. },
  141. // 情况选项
  142. onChange (item) {
  143. item.handleValue = null
  144. },
  145. // 提交参数格式化
  146. onChangeCascader (item, ref) {
  147. if (item.handleType === '0') {
  148. item.handleValueData = {
  149. userId: item.handleValue
  150. }
  151. return
  152. }
  153. const node = this.$refs[ref][0].getCheckedNodes()[0]
  154. item.handleValueData = {
  155. organizationNo: node.parent.value,
  156. postName: node.value
  157. }
  158. },
  159. onSure () {
  160. this.$refs.form.validate(async valid => {
  161. if (!valid) return
  162. try {
  163. await saveWorkflow({
  164. workFlowTmplateItems: this.formValues.items.map((e, index) => {
  165. return {
  166. handleType: e.handleType,
  167. handleValue: e.handleValueData,
  168. sort: index
  169. }
  170. }),
  171. workFlowTmplate: {
  172. workFlowTmplateId: this.item.workFlowTmplate.workFlowTmplateId
  173. }
  174. })
  175. this.$message.success('保存成功')
  176. this.$refs.dialog.close()
  177. } catch (error) {
  178. this.$message.error(error)
  179. }
  180. })
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .cardBox {
  187. position: relative;
  188. overflow: visible;
  189. .button-group {
  190. position: absolute;
  191. right: 10px;
  192. top: -20px;
  193. }
  194. }
  195. </style>