create.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <template>
  2. <div class="app-container">
  3. <el-card class="box-card">
  4. <div slot="header" class="clearfix">
  5. <span>公共信息</span>
  6. </div>
  7. <div class="text item">
  8. <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="150px">
  9. <el-form-item label="优先级:" prop="priority" style="margin-bottom: 0">
  10. <el-radio-group v-model="ruleForm.priority" size="small">
  11. <el-radio :label="1">一般</el-radio>
  12. <el-radio :label="2">紧急</el-radio>
  13. <el-radio :label="3">非常紧急</el-radio>
  14. </el-radio-group>
  15. </el-form-item>
  16. <el-form-item label="申请部门:" prop="deptId" style="margin-bottom: 0">
  17. <el-select v-model="ruleForm.deptId" size="small" clearable>
  18. <el-option v-for="(item, index) in deptList" :label="item.deptName" :value="item.deptId"
  19. :key="index"></el-option>
  20. </el-select>
  21. <span v-if="!socialId && currentNode.id">(未设置社保部门)</span>
  22. <span v-if="ruleForm.deptId && socialId != ruleForm.deptId">(该部门非社保部门)</span>
  23. </el-form-item>
  24. </el-form>
  25. </div>
  26. </el-card>
  27. <el-card class="box-card" style="margin-top: 10px">
  28. <div slot="header" class="clearfix">
  29. <span>表单信息</span>
  30. </div>
  31. <div class="text item">
  32. <template v-for="(tplItem, tplIndex) in processStructureValue.tpls">
  33. <fm-generate-form v-show="currentNode.hideTpls === undefined ||
  34. currentNode.hideTpls === null ||
  35. currentNode.hideTpls.indexOf(tplItem.id) === -1
  36. " :key="tplIndex" :ref="'generateForm-' + tplItem.id" :preview="currentNode.hideTpls === undefined ||
  37. currentNode.hideTpls === null ||
  38. currentNode.hideTpls.indexOf(tplItem.id) === -1
  39. ? false
  40. : true
  41. " :remote="remoteFunc" :data="tplItem.form_structure" :value="tplItem.form_data" :disabled="currentNode.readonlyTpls === undefined ||
  42. currentNode.readonlyTpls === null ||
  43. currentNode.readonlyTpls.indexOf(tplItem.id) === -1
  44. ? null
  45. : true
  46. " :organ-list="organList" />
  47. </template>
  48. </div>
  49. <hr style="background-color: #d9d9d9; border: 0; height: 1px" />
  50. <div class="text item" style="text-align: center; margin-top: 18px">
  51. <el-button v-for="(item, index) in btn_group" :key="index" :type="item.className" :disabled="submitDisabled"
  52. @click="submitAction(item.target)">提交</el-button>
  53. <!-- <el-button type="default" @click="onGetFormData"> 获取数据 </el-button> -->
  54. </div>
  55. </el-card>
  56. </div>
  57. </template>
  58. <script>
  59. import Vue from "vue";
  60. import { GenerateForm } from "@/components/VueFormMaking";
  61. import "form-making/dist/FormMaking.css";
  62. Vue.component(GenerateForm.name, GenerateForm);
  63. import { Searchs } from "./save-data";
  64. import {
  65. processStructure,
  66. createWorkOrder,
  67. checkCourseReturnFee,
  68. queryAllToOrgan,
  69. queryTeacherOrgan,
  70. queryUserInfo,
  71. } from "@/api/process/work-order";
  72. import { listUser } from "@/api/system/sysuser";
  73. export default {
  74. name: "Create",
  75. data() {
  76. return {
  77. submitDisabled: false,
  78. active: 0,
  79. currentNode: {},
  80. organList: [],
  81. processStructureValue: {},
  82. socialId: null, // 是否是社保分部
  83. userId: null,
  84. tenantId: 1,
  85. userType: "SYSTEM",
  86. cacheFormData: [],
  87. ruleForm: {
  88. priority: 1,
  89. deptId: null, // 社保部分
  90. process: "",
  91. classify: "",
  92. state: [],
  93. source: "",
  94. source_state: "",
  95. process_method: "",
  96. tpls: {
  97. form_structure: [],
  98. form_data: [],
  99. },
  100. tasks: [],
  101. },
  102. rules: {
  103. deptId: [
  104. { required: true, message: "请选择申请部门", trigger: "change" },
  105. ],
  106. priority: [
  107. { required: true, message: "请选择工单优先级", trigger: "blur" },
  108. ],
  109. },
  110. deptList: [], // 分部列表
  111. btn_group: [],
  112. remoteFunc: {
  113. // 获取用户列表
  114. userList(resolve) {
  115. listUser({
  116. pageSize: 999999,
  117. }).then((response) => {
  118. const options = response.data.list;
  119. resolve(options);
  120. });
  121. },
  122. },
  123. documentState: 0, // 草稿状态
  124. searchs: null,
  125. };
  126. },
  127. async mounted() {
  128. const processId = this.$route.query.processId;
  129. this.searchs = new Searchs("process" + processId);
  130. const getSearch = this.searchs.get();
  131. this.cacheFormData = getSearch || [];
  132. console.log(getSearch, 'getSearch')
  133. await this.getUserInfo();
  134. await this.getAllOrgan();
  135. await this.getProcessNodeList();
  136. },
  137. methods: {
  138. onGetFormData() {
  139. var promiseList = [];
  140. for (var tpl of this.processStructureValue.tpls) {
  141. const beforData =
  142. this.$refs["generateForm-" + tpl.id][0].getDataNoValid();
  143. const afterData = {};
  144. // 去除数据为空的对象,其它的保留
  145. for (let i in beforData) {
  146. if (i.indexOf("subform") != -1) {
  147. afterData[i] = [];
  148. for (let j in beforData[i]) {
  149. afterData[i][j] = {};
  150. for (let k in beforData[i][j]) {
  151. if (beforData[i][j][k]) {
  152. afterData[i][j][k] = beforData[i][j][k];
  153. }
  154. }
  155. }
  156. } else {
  157. if (beforData[i]) {
  158. afterData[i] = beforData[i];
  159. }
  160. }
  161. }
  162. // console.log(afterData, "afterData");
  163. promiseList.push({
  164. tplId: tpl.id,
  165. priority: this.ruleForm.priority,
  166. deptId: this.ruleForm.deptId,
  167. formData: afterData,
  168. });
  169. }
  170. this.searchs.update(promiseList, null);
  171. },
  172. async getUserInfo() {
  173. await queryUserInfo().then((res) => {
  174. if (res.code == 200) {
  175. this.userId = res.data.id;
  176. this.tenantId = res.data.tenantId;
  177. this.userType = res.data.userType;
  178. } else {
  179. this.$message.error(res.data);
  180. }
  181. });
  182. },
  183. async getAllOrgan() {
  184. // 获取分部
  185. await queryAllToOrgan({ tenantId: this.tenantId }).then((res) => {
  186. if (res.code == 200) {
  187. const result = res.data;
  188. const processId = this.$route.query.processId;
  189. let filterOrganId = [];
  190. if ([40, 41, 45, 46, 47].includes(processId)) {
  191. filterOrganId = [4];
  192. } else {
  193. filterOrganId = [
  194. 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
  195. 23, 25, 26, 27, 28, 34, 37, 40, 71, 72, 124, 125,
  196. ];
  197. }
  198. let tempOrgan = [];
  199. // 过滤不会显示的分部
  200. result.forEach((item) => {
  201. if (filterOrganId.includes(item.id)) {
  202. tempOrgan.push(item);
  203. }
  204. });
  205. this.organList = tempOrgan;
  206. }
  207. });
  208. },
  209. async getProcessNodeList() {
  210. const processId = this.$route.query.processId;
  211. if (!processId) {
  212. return;
  213. }
  214. await processStructure({
  215. processId: this.$route.query.processId,
  216. userId: this.userId,
  217. }).then((response) => {
  218. let tempData = response.data.tpls;
  219. // 获取对应模板中,下拉框的key, value
  220. let selectList = this.getSelectValueObject(tempData);
  221. // 获取对应模板中,需要隐藏的字段
  222. let hiddenFormList = this.getSelectValueObject(
  223. tempData,
  224. "hiddenForm",
  225. selectList
  226. );
  227. console.log(hiddenFormList, 'hiddenFormList', tempData)
  228. // 获取对应缓存
  229. const responseData = response.data;
  230. // let formCatchData = ''
  231. for (let i in responseData.tpls) {
  232. const findItem = this.cacheFormData.find(
  233. (item) => item.tplId == responseData.tpls[i].id
  234. );
  235. if (findItem) {
  236. // formCatchData = JSON.parse(
  237. // JSON.stringify(findItem.formData)
  238. // );
  239. responseData.tpls[i].form_data = JSON.parse(
  240. JSON.stringify(findItem.formData)
  241. );
  242. } else {
  243. // formCatchData = '';
  244. responseData.tpls[i].form_data = "";
  245. }
  246. }
  247. // 获取需要显示的表单
  248. // let getShowForm = [] // 显示表单显示
  249. // tempData.forEach((temp, index) => {
  250. // let tempList = temp.form_structure.list || [];
  251. // tempList.forEach((item) => {
  252. // const currentItem = formCatchData ? formCatchData[item.model] : ''
  253. // if (item.type == 'select' && currentItem && item.options.relationStatus) {
  254. // const selectChioce = item.options.options ? item.options.options.find(v => v.value == currentItem) : ''
  255. // // 判断是否有多个select
  256. // getShowForm.push(selectChioce ? selectChioce.relationOptions : [])
  257. // }
  258. // })
  259. // })
  260. tempData.forEach((temp, index) => {
  261. let tempList = temp.form_structure.list || [];
  262. tempList.forEach((item) => {
  263. // 设置默认显示和隐藏的表单
  264. if (hiddenFormList[index].length > 0) {
  265. if (item.type != "text" && !item.options.relationStatus) {
  266. item.hidden = true;
  267. } else {
  268. item.hidden = false;
  269. }
  270. // item.hidden = false
  271. if (hiddenFormList[index].includes(item.model)) {
  272. item.hidden = false;
  273. }
  274. } else {
  275. item.hidden = false;
  276. }
  277. // 子表单
  278. if (item.type == "subform") {
  279. let childList = item.columns || [];
  280. let subFormStatus = true;
  281. childList.forEach((child) => {
  282. let childList = child.list || [];
  283. childList.forEach((c) => {
  284. if (hiddenFormList[index].length > 0) {
  285. if (c.type != "text" && !c.options.relationStatus) {
  286. c.hidden = true;
  287. } else {
  288. c.hidden = false;
  289. subFormStatus = false;
  290. }
  291. if (hiddenFormList[index].includes(c.model)) {
  292. c.hidden = false;
  293. subFormStatus = false;
  294. }
  295. } else {
  296. c.hidden = false;
  297. subFormStatus = false;
  298. }
  299. });
  300. });
  301. item.hidden = subFormStatus;
  302. }
  303. // if (getShowForm && getShowForm.length > 0) {
  304. // const findIndex = getShowForm.findIndex(v => v == item.model)
  305. // console.log(findIndex, 'findIndex')
  306. // if (findIndex >= 0) {
  307. // item.hidden = false
  308. // }
  309. // }
  310. });
  311. });
  312. this.processStructureValue = response.data;
  313. this.currentNode = this.processStructureValue.nodes[0];
  314. this.deptList = response.data.depts || [];
  315. const defaultDept = response.data.deptId;
  316. this.socialId = defaultDept;
  317. if (this.cacheFormData.length > 0) {
  318. const tempSearch = this.cacheFormData[0];
  319. this.ruleForm.deptId = tempSearch.deptId
  320. ? Number(tempSearch.deptId)
  321. : null;
  322. this.ruleForm.priority = tempSearch.priority;
  323. } else {
  324. this.deptList.forEach((item, index) => {
  325. if (defaultDept) {
  326. if (item.deptId == defaultDept) {
  327. this.deptName = item.deptName;
  328. this.ruleForm.deptId = item.deptId;
  329. }
  330. } else {
  331. if (index == 0) {
  332. this.deptName = item.deptName;
  333. this.ruleForm.deptId = item.deptId;
  334. }
  335. }
  336. item.text = item.deptName;
  337. });
  338. }
  339. // 按钮设置
  340. const psv = response.data.edges || [];
  341. const btn_group = [];
  342. psv.forEach((item) => {
  343. if (item.source === this.currentNode.id && item.flowProperties == 1) {
  344. if (item.flowProperties == 1) {
  345. item.className = "primary";
  346. } else if (item.flowProperties == 0) {
  347. item.className = "danger";
  348. } else if (item.flowProperties == 2) {
  349. item.className = "primary";
  350. }
  351. btn_group.push(item);
  352. } else {
  353. item.className = "primary";
  354. }
  355. });
  356. this.btn_group = btn_group;
  357. if (!this.socialId && this.deptList.length <= 0) {
  358. this.$alert("您当前暂未设置所属部门,请联系管理员", "提示", {
  359. confirmButtonText: "确定",
  360. callback: (action) => { },
  361. });
  362. }
  363. });
  364. },
  365. // // 添加关联表单方法
  366. // relationFormChange(value) {
  367. // // false 为显示,true 为隐藏
  368. // let temp = value || [];
  369. // let tempData = JSON.parse(JSON.stringify(this.templateData));
  370. // tempData.forEach((item) => {
  371. // if (this.formStatus) {
  372. // // 判断表单是否在关联列表里,如果在则隐藏
  373. // if (this.formRelationList.includes(item.model)) {
  374. // item.hidden = true;
  375. // this.fileCheckList[item.model] =
  376. // item.type == "subform" ? true : false;
  377. // }
  378. // // 判断是否是文本类型,一直默认显示
  379. // if (item.type == "text") {
  380. // item.hidden = false;
  381. // }
  382. // } else {
  383. // item.hidden = false;
  384. // }
  385. // });
  386. // this.templateData = tempData;
  387. // this.$forceUpdate();
  388. // },
  389. getSelectValueObject(tpls, type = "value", tplValues = []) {
  390. const tempData = tpls || [];
  391. let selectList = [];
  392. tempData.forEach((temp, index) => {
  393. let tempList = temp.form_structure.list || [];
  394. let tempSelectList = tplValues[index] || [];
  395. let listArray = [];
  396. tempList.forEach((list) => {
  397. if (list.type == "select") {
  398. if (type == "value") {
  399. const result = this.getFormDataDetail(temp.form_data, list.model);
  400. if (result.status) {
  401. listArray.push(result);
  402. }
  403. } else {
  404. let selectOptions = [];
  405. let selectValue = [];
  406. tempSelectList.forEach((tsl) => {
  407. if (tsl.model == list.model) {
  408. selectOptions = list.options.options || [];
  409. selectValue = tsl.value || [];
  410. }
  411. });
  412. selectOptions.forEach((so) => {
  413. if (selectValue.includes(so.value)) {
  414. let tempRo = so.relationOptions || [];
  415. listArray.push(...tempRo);
  416. }
  417. });
  418. }
  419. }
  420. if (list.type == "subform") {
  421. let childList = list.columns || [];
  422. childList.forEach((child) => {
  423. let childList = child.list || [];
  424. childList.forEach((c) => {
  425. if (c.type == "select") {
  426. if (type == "value") {
  427. const originObj = JSON.parse(JSON.stringify(c));
  428. const result = this.getFormDataDetail(
  429. temp.form_data,
  430. originObj.model
  431. );
  432. if (result.status) {
  433. listArray.push(result);
  434. }
  435. } else {
  436. let selectOptions = [];
  437. let selectValue = [];
  438. tempSelectList.forEach((tsl) => {
  439. if (tsl.model == c.model) {
  440. selectOptions = c.options.options || [];
  441. selectValue = tsl.value || [];
  442. }
  443. });
  444. selectOptions.forEach((so) => {
  445. if (selectValue.includes(so.value)) {
  446. let tempRo = so.relationOptions || [];
  447. listArray.push(...tempRo);
  448. }
  449. });
  450. }
  451. }
  452. });
  453. });
  454. }
  455. });
  456. selectList.push(listArray);
  457. });
  458. return selectList;
  459. },
  460. // 获取对应元素的值
  461. getFormDataDetail(formData, model) {
  462. let modelStatus = {
  463. status: false,
  464. value: null,
  465. };
  466. for (let data in formData) {
  467. if (typeof formData[data] == "object") {
  468. // 没有子表单里面有子表单
  469. for (let child in formData[data]) {
  470. if (child == model) {
  471. modelStatus = {
  472. status: true,
  473. model: child,
  474. value: formData[data][child]
  475. ? formData[data][child].split(",")
  476. : [],
  477. };
  478. }
  479. }
  480. } else {
  481. if (data == model) {
  482. modelStatus = {
  483. status: true,
  484. model: data,
  485. value: formData[data] ? formData[data].split(",") : [],
  486. };
  487. }
  488. }
  489. }
  490. return modelStatus;
  491. },
  492. submitAction(target) {
  493. console.log(this.ruleForm, "ruleForm");
  494. this.$refs["ruleForm"].validate((valid) => {
  495. if (valid) {
  496. this.submitDisabled = true;
  497. var stateMap = {};
  498. this.ruleForm.process = parseInt(this.$route.query.processId);
  499. this.ruleForm.classify = this.processStructureValue.process.classify;
  500. stateMap["id"] = target;
  501. this.ruleForm.source_state =
  502. this.processStructureValue.nodes[this.active].label;
  503. for (var v of this.processStructureValue.nodes) {
  504. if (v.id === target) {
  505. if (v.assignType !== undefined) {
  506. stateMap["process_method"] = v.assignType;
  507. }
  508. if (v.assignValue !== undefined) {
  509. stateMap["processor"] = Array.from(new Set(v.assignValue));
  510. }
  511. stateMap["label"] = v.label;
  512. break;
  513. }
  514. }
  515. this.ruleForm.state = [stateMap];
  516. this.ruleForm.tpls = {
  517. form_structure: [],
  518. form_data: [],
  519. };
  520. // 绑定流程任务
  521. this.ruleForm.tasks =
  522. this.processStructureValue.process.task === undefined
  523. ? []
  524. : this.processStructureValue.process.task;
  525. // 追加节点任务
  526. if (
  527. this.processStructureValue.nodes[this.active].task !== undefined &&
  528. this.processStructureValue.nodes[this.active].task.length > 0
  529. ) {
  530. for (var task of this.processStructureValue.nodes[this.active]
  531. .task) {
  532. if (this.ruleForm.tasks.indexOf(task) === -1) {
  533. this.ruleForm.tasks.push(task);
  534. }
  535. }
  536. }
  537. let promiseList = [];
  538. for (var tpl of this.processStructureValue.tpls) {
  539. tpl.form_structure.id = tpl.id;
  540. this.ruleForm.tpls.form_structure.push(tpl.form_structure);
  541. promiseList.push(this.$refs["generateForm-" + tpl.id][0].getData());
  542. }
  543. Promise.all(promiseList)
  544. .then(async (values) => {
  545. this.ruleForm.source =
  546. this.processStructureValue.nodes[this.active].id;
  547. this.ruleForm.tpls.form_data = values;
  548. const formData = values[0];
  549. const tplInfo = this.processStructureValue.tpls[0]; // 默认只用第一个模板
  550. // 校验数据
  551. const res = await checkCourseReturnFee({
  552. tplInfoId: tplInfo.id,
  553. formData,
  554. });
  555. if (res.code == 200) {
  556. await createWorkOrder(this.ruleForm)
  557. .then((response) => {
  558. if (response.code === 200) {
  559. this.$message.success("工单申请成功");
  560. this.documentState = 1;
  561. // 删除已经有数据
  562. this.searchs.removeByKey();
  563. setTimeout(() => {
  564. this.$router.push({ path: "/process/my-create" });
  565. }, 50);
  566. }
  567. })
  568. .catch(() => {
  569. this.submitDisabled = false;
  570. });
  571. } else {
  572. this.$message.error(res.message);
  573. return;
  574. }
  575. })
  576. .catch(() => {
  577. this.submitDisabled = false;
  578. });
  579. }
  580. });
  581. },
  582. },
  583. beforeRouteLeave(to, from, next) {
  584. // 从 bar 里面赋值的
  585. const create_ticket_status = sessionStorage.getItem("create_ticket_status");
  586. if (this.documentState == 0 && !create_ticket_status) {
  587. setTimeout(() => {
  588. // 做是否离开判断?
  589. // 还是做是否保存判断?
  590. this.$confirm("您的申请尚未提交,是否确认返回?", "提示", {
  591. confirmButtonText: "确认",
  592. cancelButtonText: "取消",
  593. type: "warning",
  594. })
  595. .then(() => {
  596. this.onGetFormData();
  597. next();
  598. })
  599. .catch(() => {
  600. next(false);
  601. });
  602. }, 200);
  603. } else {
  604. if (create_ticket_status) {
  605. this.onGetFormData();
  606. sessionStorage.removeItem("create_ticket_status");
  607. }
  608. next();
  609. }
  610. },
  611. };
  612. </script>