create.vue 23 KB

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