surveyForm.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div class="app-container">
  3. </div>
  4. </template>
  5. <script>
  6. import Parser from '@/components/parser/Parser'
  7. import {definitionStart, flowXmlAndNode} from "@/api/flowable/definition";
  8. import flow from '../../flowable/task/myProcess/send/flow'
  9. import {flowFormData} from "@/api/flowable/process";
  10. import {getNextFlowNodeByStart} from "@/api/flowable/todo";
  11. import FlowUser from '@/components/flow/User'
  12. import FlowRole from '@/components/flow/Role'
  13. export default {
  14. name: "investPoolSurveyForm",
  15. components: {
  16. Parser,
  17. flow,
  18. FlowUser,
  19. FlowRole,
  20. },
  21. props: {},
  22. data() {
  23. return {
  24. // 模型xml数据
  25. flowData: {},
  26. activeName: '1', // 切换tab标签
  27. defaultProps: {
  28. children: "children",
  29. label: "label"
  30. },
  31. // 查询参数
  32. queryParams: {
  33. deptId: undefined
  34. },
  35. // 遮罩层
  36. loading: true,
  37. deployId: "", // 流程定义编号
  38. procDefId: "", // 流程实例编号
  39. formConf: {}, // 默认表单数据
  40. variables: [], // 流程变量数据
  41. taskTitle: null,
  42. taskOpen: false,
  43. checkSendUser: false, // 是否展示人员选择模块
  44. checkSendRole: false,// 是否展示角色选择模块
  45. checkType: '', // 选择类型
  46. checkValues: null, // 选中任务接收人员数据
  47. formData: {}, // 填写的表单数据,
  48. multiInstanceVars: '' // 会签节点
  49. };
  50. },
  51. created() {
  52. this.deployId = this.$route.query && this.$route.query.deployId;
  53. // 初始化表单
  54. this.procDefId = this.$route.query && this.$route.query.procDefId;
  55. // this.getNextFlowNodeByStart(this.deployId);
  56. this.getFlowFormData(this.deployId);
  57. },
  58. methods: {
  59. handleClick(tab, event) {
  60. if (tab.name === '2'){
  61. flowXmlAndNode({deployId:this.deployId}).then(res => {
  62. this.flowData = res.data;
  63. })
  64. }
  65. },
  66. /** 流程表单数据 */
  67. getFlowFormData(deployId) {
  68. const that = this
  69. const params = {deployId: deployId}
  70. flowFormData(params).then(res => {
  71. // 流程过程中不存在初始化表单 直接读取的流程变量中存储的表单值
  72. that.formConf = res.data;
  73. }).catch(res => {
  74. this.goBack();
  75. })
  76. },
  77. /** 返回页面 */
  78. goBack() {
  79. // 关闭当前标签页并返回上个页面
  80. const obj = { path: "/task/process", query: { t: Date.now()} };
  81. this.$tab.closeOpenPage(obj);
  82. },
  83. /** 接收子组件传的值 */
  84. getData(data) {
  85. if (data) {
  86. const variables = [];
  87. data.fields.forEach(item => {
  88. let variableData = {};
  89. variableData.label = item.__config__.label
  90. // 表单值为多个选项时
  91. if (item.__config__.defaultValue instanceof Array) {
  92. const array = [];
  93. item.__config__.defaultValue.forEach(val => {
  94. array.push(val)
  95. })
  96. variableData.val = array;
  97. } else {
  98. variableData.val = item.__config__.defaultValue
  99. }
  100. variables.push(variableData)
  101. })
  102. this.variables = variables;
  103. }
  104. },
  105. /** 申请流程表单数据提交 */
  106. submitForm(formData) {
  107. // 根据当前任务或者流程设计配置的下一步节点 todo 暂时未涉及到考虑网关、表达式和多节点情况
  108. getNextFlowNodeByStart({deploymentId: this.deployId,variables:formData.valData}).then(res => {
  109. const data = res.data;
  110. if (data) {
  111. this.formData = formData;
  112. if (data.dataType === 'dynamic') {
  113. if (data.type === 'assignee') { // 指定人员
  114. this.checkSendUser = true;
  115. this.checkType = "single";
  116. } else if (data.type === 'candidateUsers') { // 候选人员(多个)
  117. this.checkSendUser = true;
  118. this.checkType = "multiple";
  119. } else if (data.type === 'candidateGroups') { // 指定组(所属角色接收任务)
  120. this.checkSendRole = true;
  121. } else { // 会签
  122. // 流程设计指定的 elementVariable 作为会签人员列表
  123. this.multiInstanceVars = data.vars;
  124. this.checkSendUser = true;
  125. this.checkType = "multiple";
  126. }
  127. this.taskOpen = true;
  128. this.taskTitle = "选择任务接收";
  129. } else {
  130. const variables = this.formData.valData;
  131. const formData = this.formData.formData;
  132. formData.disabled = true;
  133. formData.formBtns = false;
  134. if (this.procDefId) {
  135. variables.variables = formData;
  136. // 启动流程并将表单数据加入流程变量
  137. definitionStart(this.procDefId, JSON.stringify(variables)).then(res => {
  138. this.$modal.msgSuccess(res.msg);
  139. this.goBack();
  140. })
  141. }
  142. }
  143. }
  144. })
  145. },
  146. /** 提交流程 */
  147. submitTask() {
  148. if (!this.checkValues && this.checkSendUser){
  149. this.$modal.msgError("请选择任务接收!");
  150. return;
  151. }
  152. if (!this.checkValues && this.checkSendRole){
  153. this.$modal.msgError("请选择流程接收角色组!");
  154. return;
  155. }
  156. if (this.formData) {
  157. const variables = this.formData.valData;
  158. const formData = this.formData.formData;
  159. // 表单是否禁用
  160. formData.disabled = true;
  161. // 是否显示按钮
  162. formData.formBtns = false;
  163. variables.variables = formData;
  164. if (this.multiInstanceVars) {
  165. this.$set(variables, this.multiInstanceVars, this.checkValues);
  166. } else {
  167. this.$set(variables, "approval", this.checkValues);
  168. }
  169. console.log(variables,"流程发起提交表单数据")
  170. // 启动流程并将表单数据加入流程变量
  171. definitionStart(this.procDefId, JSON.stringify(variables)).then(res => {
  172. this.$modal.msgSuccess(res.msg);
  173. this.goBack();
  174. })
  175. }
  176. },
  177. /** 根据当前任务获取流程设计配置的下一步节点 */
  178. getNextFlowNodeByStart(deploymentId,variables) {
  179. // 根据当前任务或者流程设计配置的下一步节点 todo 暂时未涉及到考虑网关、表达式和多节点情况
  180. getNextFlowNodeByStart({deploymentId: deploymentId,variables:variables}).then(res => {
  181. const data = res.data;
  182. if (data) {
  183. if (data.type === 'assignee') { // 指定人员
  184. this.checkSendUser = true;
  185. this.checkType = "single";
  186. } else if (data.type === 'candidateUsers') { // 候选人员(多个)
  187. this.checkSendUser = true;
  188. this.checkType = "multiple";
  189. } else if (data.type === 'candidateGroups') { // 指定组(所属角色接收任务)
  190. this.checkSendRole = true;
  191. } else if (data.type === 'multiInstance') { // 会签?
  192. // 流程设计指定的 elementVariable 作为会签人员列表
  193. this.multiInstanceVars = data.vars;
  194. this.checkSendUser = true;
  195. this.checkType = "multiple";
  196. }
  197. }
  198. })
  199. },
  200. // 用户信息选中数据
  201. handleUserSelect(selection) {
  202. if (selection) {
  203. if (selection instanceof Array) {
  204. const selectVal = selection.map(item => item.userId);
  205. if (this.multiInstanceVars) {
  206. this.checkValues = selectVal;
  207. } else {
  208. this.checkValues = selectVal.join(',');
  209. }
  210. } else {
  211. this.checkValues = selection.userId;
  212. }
  213. }
  214. },
  215. // 角色信息选中数据
  216. handleRoleSelect(selection) {
  217. if (selection) {
  218. if (selection instanceof Array) {
  219. const selectVal = selection.map(item => item.roleId);
  220. this.checkValues = selectVal.join(',')
  221. } else {
  222. this.checkValues = selection;
  223. }
  224. }
  225. },
  226. }
  227. };
  228. </script>
  229. <style lang="scss" scoped>
  230. .test-form {
  231. margin: 15px auto;
  232. width: 800px;
  233. padding: 15px;
  234. }
  235. .clearfix:before,
  236. .clearfix:after {
  237. display: table;
  238. content: "";
  239. }
  240. .clearfix:after {
  241. clear: both
  242. }
  243. .box-card {
  244. width: 100%;
  245. margin-bottom: 20px;
  246. }
  247. .el-tag + .el-tag {
  248. margin-left: 10px;
  249. }
  250. .my-label {
  251. background: #E1F3D8;
  252. }
  253. </style>