workflowApproved.vue 6.3 KB

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