create.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. :disabled="
  70. currentNode.readonlyTpls === undefined ||
  71. currentNode.readonlyTpls === null ||
  72. currentNode.readonlyTpls.indexOf(tplItem.id) === -1
  73. ? null
  74. : true
  75. "
  76. :organ-list="organList"
  77. />
  78. </template>
  79. </div>
  80. <hr style="background-color: #d9d9d9; border: 0; height: 1px" />
  81. <div class="text item" style="text-align: center; margin-top: 18px">
  82. <el-button
  83. v-for="(item, index) in btn_group"
  84. :key="index"
  85. :type="item.className"
  86. :disabled="submitDisabled"
  87. @click="submitAction(item.target)"
  88. >提交</el-button
  89. >
  90. </div>
  91. </el-card>
  92. </div>
  93. </template>
  94. <script>
  95. import Vue from "vue";
  96. import { GenerateForm } from "@/components/VueFormMaking";
  97. import "form-making/dist/FormMaking.css";
  98. Vue.component(GenerateForm.name, GenerateForm);
  99. import {
  100. processStructure,
  101. createWorkOrder,
  102. checkCourseReturnFee,
  103. queryAllOrgan,
  104. queryTeacherOrgan,
  105. queryUserInfo,
  106. } from "@/api/process/work-order";
  107. import { listUser } from "@/api/system/sysuser";
  108. export default {
  109. name: "Create",
  110. data() {
  111. return {
  112. submitDisabled: false,
  113. active: 0,
  114. currentNode: {},
  115. organList: [],
  116. processStructureValue: {},
  117. socialId: null, // 是否是社保分部
  118. userId: null,
  119. tenantId: 1,
  120. userType: "SYSTEM",
  121. ruleForm: {
  122. priority: 1,
  123. deptId: null, // 社保部分
  124. process: "",
  125. classify: "",
  126. state: [],
  127. source: "",
  128. source_state: "",
  129. process_method: "",
  130. tpls: {
  131. form_structure: [],
  132. form_data: [],
  133. },
  134. tasks: [],
  135. },
  136. rules: {
  137. deptId: [
  138. { required: true, message: "请选择申请部门", trigger: "change" },
  139. ],
  140. priority: [
  141. { required: true, message: "请选择工单优先级", trigger: "blur" },
  142. ],
  143. },
  144. deptList: [], // 分部列表
  145. btn_group: [],
  146. remoteFunc: {
  147. // 获取用户列表
  148. userList(resolve) {
  149. listUser({
  150. pageSize: 999999,
  151. }).then((response) => {
  152. const options = response.data.list;
  153. resolve(options);
  154. });
  155. },
  156. },
  157. documentState: 0, // 草稿状态
  158. };
  159. },
  160. async mounted() {
  161. await this.getUserInfo();
  162. await this.getAllOrgan();
  163. this.getProcessNodeList();
  164. },
  165. methods: {
  166. async getUserInfo() {
  167. await queryUserInfo().then((res) => {
  168. if (res.code == 200) {
  169. this.userId = res.data.id;
  170. this.tenantId = res.data.tenantId;
  171. this.userType = res.data.userType;
  172. } else {
  173. this.$message.error(res.data);
  174. }
  175. });
  176. },
  177. async getAllOrgan() {
  178. // 获取分部
  179. if (this.userType.indexOf("SYSTEM") != -1) {
  180. await queryAllOrgan({ tenantId: this.tenantId }).then((res) => {
  181. if (res.code == 200) {
  182. const result = res.data;
  183. const filterOrganId = [
  184. 36, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 54, 55, 56,
  185. ];
  186. let tempOrgan = [];
  187. // 过滤不会显示的分部
  188. result.forEach((item) => {
  189. if (!filterOrganId.includes(item.id)) {
  190. tempOrgan.push(item);
  191. }
  192. });
  193. this.organList = tempOrgan;
  194. }
  195. });
  196. } else {
  197. await queryTeacherOrgan({ tenantId: this.tenantId }).then((res) => {
  198. if (res.code == 200) {
  199. const result = res.data;
  200. const filterOrganId = [
  201. 36, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 54, 55, 56,
  202. ];
  203. let tempOrgan = [];
  204. // 过滤不会显示的分部
  205. result.forEach((item) => {
  206. if (!filterOrganId.includes(item.key)) {
  207. tempOrgan.push({
  208. id: item.key,
  209. name: item.value,
  210. });
  211. }
  212. });
  213. this.organList = tempOrgan;
  214. }
  215. });
  216. }
  217. },
  218. getProcessNodeList() {
  219. const processId = this.$route.query.processId;
  220. if (!processId) {
  221. return;
  222. }
  223. processStructure({
  224. processId: this.$route.query.processId,
  225. userId: this.userId,
  226. }).then((response) => {
  227. let tempData = response.data.tpls;
  228. // console.log(response);
  229. // 获取对应模板中,下拉框的key, value
  230. let selectList = this.getSelectValueObject(tempData);
  231. // console.log(selectList);
  232. // 获取对应模板中,需要隐藏的字段
  233. let hiddenFormList = this.getSelectValueObject(
  234. tempData,
  235. "hiddenForm",
  236. selectList
  237. );
  238. tempData.forEach((temp, index) => {
  239. let tempList = temp.form_structure.list || [];
  240. tempList.forEach((item) => {
  241. if (hiddenFormList[index].length > 0) {
  242. if (item.type != "text" && !item.options.relationStatus) {
  243. item.hidden = true;
  244. } else {
  245. item.hidden = false;
  246. }
  247. // item.hidden = false
  248. if (hiddenFormList[index].includes(item.model)) {
  249. item.hidden = false;
  250. }
  251. } else {
  252. item.hidden = false;
  253. }
  254. // 子表单
  255. if (item.type == "subform") {
  256. let childList = item.columns || [];
  257. let subFormStatus = true;
  258. childList.forEach((child) => {
  259. let childList = child.list || [];
  260. childList.forEach((c) => {
  261. if (hiddenFormList[index].length > 0) {
  262. if (c.type != "text" && !c.options.relationStatus) {
  263. c.hidden = true;
  264. } else {
  265. c.hidden = false;
  266. subFormStatus = false;
  267. }
  268. if (hiddenFormList[index].includes(c.model)) {
  269. c.hidden = false;
  270. subFormStatus = false;
  271. }
  272. } else {
  273. c.hidden = false;
  274. subFormStatus = false;
  275. }
  276. });
  277. });
  278. item.hidden = subFormStatus;
  279. }
  280. });
  281. });
  282. this.processStructureValue = response.data;
  283. this.currentNode = this.processStructureValue.nodes[0];
  284. this.deptList = response.data.depts || [];
  285. const defaultDept = response.data.deptId;
  286. this.socialId = defaultDept;
  287. this.deptList.forEach((item, index) => {
  288. if (defaultDept) {
  289. if (item.deptId == defaultDept) {
  290. this.deptName = item.deptName;
  291. this.ruleForm.deptId = item.deptId;
  292. }
  293. } else {
  294. if (index == 0) {
  295. this.deptName = item.deptName;
  296. this.ruleForm.deptId = item.deptId;
  297. }
  298. }
  299. item.text = item.deptName;
  300. });
  301. const psv = response.data.edges || [];
  302. const btn_group = [];
  303. psv.forEach((item) => {
  304. if (item.source === this.currentNode.id && item.flowProperties == 1) {
  305. if (item.flowProperties == 1) {
  306. item.className = "primary";
  307. } else if (item.flowProperties == 0) {
  308. item.className = "danger";
  309. } else if (item.flowProperties == 2) {
  310. item.className = "primary";
  311. }
  312. btn_group.push(item);
  313. } else {
  314. item.className = "primary";
  315. }
  316. });
  317. this.btn_group = btn_group;
  318. if (!this.socialId && this.deptList.length <= 0) {
  319. // this.$dialog.alert({
  320. // message: "您当前暂未设置所属部门,请联系管理员",
  321. // confirmButtonColor: "#01C1B5"
  322. // })
  323. this.$alert("您当前暂未设置所属部门,请联系管理员", "提示", {
  324. confirmButtonText: "确定",
  325. callback: (action) => {},
  326. });
  327. }
  328. });
  329. },
  330. getSelectValueObject(tpls, type = "value", tplValues = []) {
  331. const tempData = tpls || [];
  332. let selectList = [];
  333. tempData.forEach((temp, index) => {
  334. let tempList = temp.form_structure.list || [];
  335. let tempSelectList = tplValues[index] || [];
  336. let listArray = [];
  337. tempList.forEach((list) => {
  338. if (list.type == "select") {
  339. if (type == "value") {
  340. const result = this.getFormDataDetail(temp.form_data, list.model);
  341. if (result.status) {
  342. listArray.push(result);
  343. }
  344. } else {
  345. let selectOptions = [];
  346. let selectValue = [];
  347. tempSelectList.forEach((tsl) => {
  348. if (tsl.model == list.model) {
  349. selectOptions = list.options.options || [];
  350. selectValue = tsl.value || [];
  351. }
  352. });
  353. selectOptions.forEach((so) => {
  354. if (selectValue.includes(so.value)) {
  355. let tempRo = so.relationOptions || [];
  356. listArray.push(...tempRo);
  357. }
  358. });
  359. }
  360. }
  361. if (list.type == "subform") {
  362. let childList = list.columns || [];
  363. childList.forEach((child) => {
  364. let childList = child.list || [];
  365. childList.forEach((c) => {
  366. if (c.type == "select") {
  367. if (type == "value") {
  368. const originObj = JSON.parse(JSON.stringify(c));
  369. const result = this.getFormDataDetail(
  370. temp.form_data,
  371. originObj.model
  372. );
  373. if (result.status) {
  374. listArray.push(result);
  375. }
  376. } else {
  377. let selectOptions = [];
  378. let selectValue = [];
  379. tempSelectList.forEach((tsl) => {
  380. if (tsl.model == c.model) {
  381. selectOptions = c.options.options || [];
  382. selectValue = tsl.value || [];
  383. }
  384. });
  385. selectOptions.forEach((so) => {
  386. if (selectValue.includes(so.value)) {
  387. let tempRo = so.relationOptions || [];
  388. listArray.push(...tempRo);
  389. }
  390. });
  391. }
  392. }
  393. });
  394. });
  395. }
  396. });
  397. selectList.push(listArray);
  398. });
  399. return selectList;
  400. },
  401. // 获取对应元素的值
  402. getFormDataDetail(formData, model) {
  403. let modelStatus = {
  404. status: false,
  405. value: null,
  406. };
  407. for (let data in formData) {
  408. if (typeof formData[data] == "object") {
  409. // 没有子表单里面有子表单
  410. for (let child in formData[data]) {
  411. if (child == model) {
  412. modelStatus = {
  413. status: true,
  414. model: child,
  415. value: formData[data][child]
  416. ? formData[data][child].split(",")
  417. : [],
  418. };
  419. }
  420. }
  421. } else {
  422. if (data == model) {
  423. modelStatus = {
  424. status: true,
  425. model: data,
  426. value: formData[data] ? formData[data].split(",") : [],
  427. };
  428. }
  429. }
  430. }
  431. return modelStatus;
  432. },
  433. submitAction(target) {
  434. this.$refs["ruleForm"].validate((valid) => {
  435. if (valid) {
  436. this.submitDisabled = true;
  437. var stateMap = {};
  438. this.ruleForm.process = parseInt(this.$route.query.processId);
  439. this.ruleForm.classify = this.processStructureValue.process.classify;
  440. stateMap["id"] = target;
  441. this.ruleForm.source_state =
  442. this.processStructureValue.nodes[this.active].label;
  443. for (var v of this.processStructureValue.nodes) {
  444. if (v.id === target) {
  445. if (v.assignType !== undefined) {
  446. stateMap["process_method"] = v.assignType;
  447. }
  448. if (v.assignValue !== undefined) {
  449. stateMap["processor"] = Array.from(new Set(v.assignValue));
  450. }
  451. stateMap["label"] = v.label;
  452. break;
  453. }
  454. }
  455. this.ruleForm.state = [stateMap];
  456. this.ruleForm.tpls = {
  457. form_structure: [],
  458. form_data: [],
  459. };
  460. // 绑定流程任务
  461. this.ruleForm.tasks =
  462. this.processStructureValue.process.task === undefined
  463. ? []
  464. : this.processStructureValue.process.task;
  465. // 追加节点任务
  466. if (
  467. this.processStructureValue.nodes[this.active].task !== undefined &&
  468. this.processStructureValue.nodes[this.active].task.length > 0
  469. ) {
  470. for (var task of this.processStructureValue.nodes[this.active]
  471. .task) {
  472. if (this.ruleForm.tasks.indexOf(task) === -1) {
  473. this.ruleForm.tasks.push(task);
  474. }
  475. }
  476. }
  477. var promiseList = [];
  478. for (var tpl of this.processStructureValue.tpls) {
  479. tpl.form_structure.id = tpl.id;
  480. this.ruleForm.tpls.form_structure.push(tpl.form_structure);
  481. promiseList.push(this.$refs["generateForm-" + tpl.id][0].getData());
  482. }
  483. Promise.all(promiseList)
  484. .then(async (values) => {
  485. this.ruleForm.source =
  486. this.processStructureValue.nodes[this.active].id;
  487. this.ruleForm.tpls.form_data = values;
  488. const formData = values[0];
  489. const tplInfo = this.processStructureValue.tpls[0]; // 默认只用第一个模板
  490. // console.log(this.ruleForm.tpls.form_data);
  491. // 校验数据
  492. const res = await checkCourseReturnFee({
  493. tplInfoId: tplInfo.id,
  494. formData,
  495. });
  496. if (res.code == 200) {
  497. await createWorkOrder(this.ruleForm)
  498. .then((response) => {
  499. if (response.code === 200) {
  500. this.$message.success("工单申请成功");
  501. this.documentState = 1;
  502. this.$router.push({ path: "/process/my-create" });
  503. }
  504. })
  505. .catch(() => {
  506. this.submitDisabled = false;
  507. });
  508. } else {
  509. this.$message.error(res.message);
  510. return;
  511. }
  512. })
  513. .catch(() => {
  514. this.submitDisabled = false;
  515. });
  516. }
  517. });
  518. },
  519. compareData() {},
  520. },
  521. beforeRouteLeave(to, from, next) {
  522. if (this.documentState == 0) {
  523. setTimeout(() => {
  524. // 做是否离开判断?
  525. // 还是做是否保存判断?
  526. this.$confirm("您的申请尚未提交,是否确认返回?", "提示", {
  527. confirmButtonText: "确认",
  528. cancelButtonText: "取消",
  529. type: "warning",
  530. })
  531. .then(() => {
  532. next();
  533. })
  534. .catch(() => {});
  535. }, 200);
  536. } else {
  537. next();
  538. }
  539. },
  540. };
  541. </script>