create.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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 {
  239. filterOrganId = [
  240. // 1, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
  241. // 22, 23, 25, 26, 27, 28, 34, 37, 40, 71, 72, 123, 124, 125, 128, 134
  242. 148, 147, 127, 151, 36, 149, 152, 16, 1, 40, 15, 23, 28, 17, 6, 8, 13, 134, 139, 153, 154, 123
  243. ];
  244. }
  245. let tempOrgan = [];
  246. // 过滤不会显示的分部
  247. result.forEach((item) => {
  248. if (filterOrganId.includes(item.id)) {
  249. tempOrgan.push(item);
  250. }
  251. });
  252. this.organList = tempOrgan;
  253. }
  254. });
  255. },
  256. async getProcessNodeList() {
  257. const processId = this.$route.query.processId;
  258. if (!processId) {
  259. return;
  260. }
  261. await processStructure({
  262. processId: this.$route.query.processId,
  263. userId: this.userId,
  264. }).then((response) => {
  265. let tempData = response.data.tpls;
  266. // 获取对应模板中,下拉框的key, value
  267. let selectList = this.getSelectValueObject(tempData);
  268. // 获取对应模板中,需要隐藏的字段
  269. let hiddenFormList = this.getSelectValueObject(
  270. tempData,
  271. "hiddenForm",
  272. selectList
  273. );
  274. console.log(hiddenFormList, "hiddenFormList", tempData);
  275. // 获取对应缓存
  276. const responseData = response.data;
  277. console.log(responseData, "responseData");
  278. // let formCatchData = ''
  279. for (let i in responseData.tpls) {
  280. const findItem = this.cacheFormData.find(
  281. (item) => item.tplId == responseData.tpls[i].id
  282. );
  283. console.log(findItem, "findItem");
  284. if (findItem) {
  285. // formCatchData = JSON.parse(
  286. // JSON.stringify(findItem.formData)
  287. // );
  288. responseData.tpls[i].form_data = JSON.parse(
  289. JSON.stringify(findItem.formData)
  290. );
  291. } else {
  292. // formCatchData = '';
  293. responseData.tpls[i].form_data = "";
  294. }
  295. }
  296. // 获取需要显示的表单
  297. // let getShowForm = [] // 显示表单显示
  298. // tempData.forEach((temp, index) => {
  299. // let tempList = temp.form_structure.list || [];
  300. // tempList.forEach((item) => {
  301. // const currentItem = formCatchData ? formCatchData[item.model] : ''
  302. // if (item.type == 'select' && currentItem && item.options.relationStatus) {
  303. // const selectChioce = item.options.options ? item.options.options.find(v => v.value == currentItem) : ''
  304. // // 判断是否有多个select
  305. // getShowForm.push(selectChioce ? selectChioce.relationOptions : [])
  306. // }
  307. // })
  308. // })
  309. tempData.forEach((temp, index) => {
  310. let tempList = temp.form_structure.list || [];
  311. tempList.forEach((item) => {
  312. // 设置默认显示和隐藏的表单
  313. if (hiddenFormList[index].length > 0) {
  314. if (item.type != "text" && !item.options.relationStatus) {
  315. item.hidden = true;
  316. } else {
  317. item.hidden = false;
  318. }
  319. // item.hidden = false
  320. if (hiddenFormList[index].includes(item.model)) {
  321. item.hidden = false;
  322. }
  323. } else {
  324. item.hidden = false;
  325. }
  326. // 子表单
  327. if (item.type == "subform") {
  328. let childList = item.columns || [];
  329. let subFormStatus = true;
  330. childList.forEach((child) => {
  331. let childList = child.list || [];
  332. childList.forEach((c) => {
  333. if (hiddenFormList[index].length > 0) {
  334. if (c.type != "text" && !c.options.relationStatus) {
  335. c.hidden = true;
  336. } else {
  337. c.hidden = false;
  338. subFormStatus = false;
  339. }
  340. if (hiddenFormList[index].includes(c.model)) {
  341. c.hidden = false;
  342. subFormStatus = false;
  343. }
  344. } else {
  345. c.hidden = false;
  346. subFormStatus = false;
  347. }
  348. });
  349. });
  350. item.hidden = subFormStatus;
  351. }
  352. // if (getShowForm && getShowForm.length > 0) {
  353. // const findIndex = getShowForm.findIndex(v => v == item.model)
  354. // console.log(findIndex, 'findIndex')
  355. // if (findIndex >= 0) {
  356. // item.hidden = false
  357. // }
  358. // }
  359. });
  360. });
  361. this.processStructureValue = response.data;
  362. this.currentNode = this.processStructureValue.nodes[0];
  363. this.deptList = response.data.depts || [];
  364. const defaultDept = response.data.deptId;
  365. this.socialId = defaultDept;
  366. if (this.cacheFormData.length > 0) {
  367. const tempSearch = this.cacheFormData[0];
  368. this.ruleForm.deptId = tempSearch.deptId
  369. ? Number(tempSearch.deptId)
  370. : null;
  371. this.ruleForm.priority = tempSearch.priority;
  372. } else {
  373. this.deptList.forEach((item, index) => {
  374. if (defaultDept) {
  375. if (item.deptId == defaultDept) {
  376. this.deptName = item.deptName;
  377. this.ruleForm.deptId = item.deptId;
  378. }
  379. } else {
  380. if (index == 0) {
  381. this.deptName = item.deptName;
  382. this.ruleForm.deptId = item.deptId;
  383. }
  384. }
  385. item.text = item.deptName;
  386. });
  387. }
  388. // 按钮设置
  389. const psv = response.data.edges || [];
  390. const btn_group = [];
  391. psv.forEach((item) => {
  392. if (item.source === this.currentNode.id && item.flowProperties == 1) {
  393. if (item.flowProperties == 1) {
  394. item.className = "primary";
  395. } else if (item.flowProperties == 0) {
  396. item.className = "danger";
  397. } else if (item.flowProperties == 2) {
  398. item.className = "primary";
  399. }
  400. btn_group.push(item);
  401. } else {
  402. item.className = "primary";
  403. }
  404. });
  405. this.btn_group = btn_group;
  406. if (!this.socialId && this.deptList.length <= 0) {
  407. this.$alert("您当前暂未设置所属部门,请联系管理员", "提示", {
  408. confirmButtonText: "确定",
  409. callback: (action) => {},
  410. });
  411. }
  412. });
  413. },
  414. // // 添加关联表单方法
  415. // relationFormChange(value) {
  416. // // false 为显示,true 为隐藏
  417. // let temp = value || [];
  418. // let tempData = JSON.parse(JSON.stringify(this.templateData));
  419. // tempData.forEach((item) => {
  420. // if (this.formStatus) {
  421. // // 判断表单是否在关联列表里,如果在则隐藏
  422. // if (this.formRelationList.includes(item.model)) {
  423. // item.hidden = true;
  424. // this.fileCheckList[item.model] =
  425. // item.type == "subform" ? true : false;
  426. // }
  427. // // 判断是否是文本类型,一直默认显示
  428. // if (item.type == "text") {
  429. // item.hidden = false;
  430. // }
  431. // } else {
  432. // item.hidden = false;
  433. // }
  434. // });
  435. // this.templateData = tempData;
  436. // this.$forceUpdate();
  437. // },
  438. getSelectValueObject(tpls, type = "value", tplValues = []) {
  439. const tempData = tpls || [];
  440. let selectList = [];
  441. tempData.forEach((temp, index) => {
  442. let tempList = temp.form_structure.list || [];
  443. let tempSelectList = tplValues[index] || [];
  444. let listArray = [];
  445. tempList.forEach((list) => {
  446. if (list.type == "select") {
  447. if (type == "value") {
  448. const result = this.getFormDataDetail(temp.form_data, list.model);
  449. if (result.status) {
  450. listArray.push(result);
  451. }
  452. } else {
  453. let selectOptions = [];
  454. let selectValue = [];
  455. tempSelectList.forEach((tsl) => {
  456. if (tsl.model == list.model) {
  457. selectOptions = list.options.options || [];
  458. selectValue = tsl.value || [];
  459. }
  460. });
  461. selectOptions.forEach((so) => {
  462. if (selectValue.includes(so.value)) {
  463. let tempRo = so.relationOptions || [];
  464. listArray.push(...tempRo);
  465. }
  466. });
  467. }
  468. }
  469. if (list.type == "subform") {
  470. let childList = list.columns || [];
  471. childList.forEach((child) => {
  472. let childList = child.list || [];
  473. childList.forEach((c) => {
  474. if (c.type == "select") {
  475. if (type == "value") {
  476. const originObj = JSON.parse(JSON.stringify(c));
  477. const result = this.getFormDataDetail(
  478. temp.form_data,
  479. originObj.model
  480. );
  481. if (result.status) {
  482. listArray.push(result);
  483. }
  484. } else {
  485. let selectOptions = [];
  486. let selectValue = [];
  487. tempSelectList.forEach((tsl) => {
  488. if (tsl.model == c.model) {
  489. selectOptions = c.options.options || [];
  490. selectValue = tsl.value || [];
  491. }
  492. });
  493. selectOptions.forEach((so) => {
  494. if (selectValue.includes(so.value)) {
  495. let tempRo = so.relationOptions || [];
  496. listArray.push(...tempRo);
  497. }
  498. });
  499. }
  500. }
  501. });
  502. });
  503. }
  504. });
  505. selectList.push(listArray);
  506. });
  507. return selectList;
  508. },
  509. // 获取对应元素的值
  510. getFormDataDetail(formData, model) {
  511. let modelStatus = {
  512. status: false,
  513. value: null,
  514. };
  515. for (let data in formData) {
  516. if (typeof formData[data] == "object") {
  517. // 没有子表单里面有子表单
  518. for (let child in formData[data]) {
  519. if (child == model) {
  520. modelStatus = {
  521. status: true,
  522. model: child,
  523. value: formData[data][child]
  524. ? formData[data][child].split(",")
  525. : [],
  526. };
  527. }
  528. }
  529. } else {
  530. if (data == model) {
  531. modelStatus = {
  532. status: true,
  533. model: data,
  534. value: formData[data] ? formData[data].split(",") : [],
  535. };
  536. }
  537. }
  538. }
  539. return modelStatus;
  540. },
  541. submitAction(target) {
  542. console.log(this.ruleForm, "ruleForm");
  543. this.$refs["ruleForm"].validate((valid) => {
  544. if (valid) {
  545. this.submitDisabled = true;
  546. var stateMap = {};
  547. this.ruleForm.process = parseInt(this.$route.query.processId);
  548. this.ruleForm.classify = this.processStructureValue.process.classify;
  549. stateMap["id"] = target;
  550. this.ruleForm.source_state =
  551. this.processStructureValue.nodes[this.active].label;
  552. for (var v of this.processStructureValue.nodes) {
  553. if (v.id === target) {
  554. if (v.assignType !== undefined) {
  555. stateMap["process_method"] = v.assignType;
  556. }
  557. if (v.assignValue !== undefined) {
  558. stateMap["processor"] = Array.from(new Set(v.assignValue));
  559. }
  560. stateMap["label"] = v.label;
  561. break;
  562. }
  563. }
  564. this.ruleForm.state = [stateMap];
  565. this.ruleForm.tpls = {
  566. form_structure: [],
  567. form_data: [],
  568. };
  569. // 绑定流程任务
  570. this.ruleForm.tasks =
  571. this.processStructureValue.process.task === undefined
  572. ? []
  573. : this.processStructureValue.process.task;
  574. // 追加节点任务
  575. if (
  576. this.processStructureValue.nodes[this.active].task !== undefined &&
  577. this.processStructureValue.nodes[this.active].task.length > 0
  578. ) {
  579. for (var task of this.processStructureValue.nodes[this.active]
  580. .task) {
  581. if (this.ruleForm.tasks.indexOf(task) === -1) {
  582. this.ruleForm.tasks.push(task);
  583. }
  584. }
  585. }
  586. let promiseList = [];
  587. for (var tpl of this.processStructureValue.tpls) {
  588. tpl.form_structure.id = tpl.id;
  589. this.ruleForm.tpls.form_structure.push(tpl.form_structure);
  590. promiseList.push(this.$refs["generateForm-" + tpl.id][0].getData());
  591. }
  592. Promise.all(promiseList)
  593. .then(async (values) => {
  594. this.ruleForm.source =
  595. this.processStructureValue.nodes[this.active].id;
  596. this.ruleForm.tpls.form_data = values;
  597. const formData = values[0];
  598. const tplInfo = this.processStructureValue.tpls[0]; // 默认只用第一个模板
  599. // 校验数据
  600. const res = await checkCourseReturnFee({
  601. tplInfoId: tplInfo.id,
  602. formData,
  603. });
  604. if (res.code == 200) {
  605. await createWorkOrder(this.ruleForm)
  606. .then((response) => {
  607. if (response.code === 200) {
  608. this.$message.success("工单申请成功");
  609. this.documentState = 1;
  610. // 删除已经有数据
  611. this.searchs.removeByKey();
  612. setTimeout(() => {
  613. this.$router.push({ path: "/process/my-create" });
  614. }, 50);
  615. }
  616. })
  617. .catch(() => {
  618. this.submitDisabled = false;
  619. });
  620. } else {
  621. this.$message.error(res.message);
  622. return;
  623. }
  624. })
  625. .catch(() => {
  626. this.submitDisabled = false;
  627. });
  628. }
  629. });
  630. },
  631. },
  632. beforeRouteLeave(to, from, next) {
  633. // 从 bar 里面赋值的
  634. const create_ticket_status = sessionStorage.getItem("create_ticket_status");
  635. if (this.documentState == 0 && !create_ticket_status) {
  636. setTimeout(() => {
  637. // 做是否离开判断?
  638. // 还是做是否保存判断?
  639. sessionStorage.removeItem("createReopenReopen");
  640. this.$confirm("您的申请尚未提交,是否确认返回?", "提示", {
  641. confirmButtonText: "确认",
  642. cancelButtonText: "取消",
  643. type: "warning",
  644. })
  645. .then(() => {
  646. this.onGetFormData();
  647. next();
  648. })
  649. .catch(() => {
  650. next(false);
  651. });
  652. }, 200);
  653. } else {
  654. if (create_ticket_status) {
  655. this.onGetFormData();
  656. sessionStorage.removeItem("create_ticket_status");
  657. sessionStorage.removeItem("createReopenReopen");
  658. }
  659. next();
  660. }
  661. },
  662. };
  663. </script>