release.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. import {
  2. listByFirstTaskId,
  3. listUserByIds,
  4. listWorkCenter,
  5. listByWorkCenter,
  6. lineByCurrentUser,
  7. taskSave,
  8. taskRevoked,
  9. taskAssignment,
  10. listAssign,
  11. checkAssignConfirm,
  12. resetAssignee,
  13. listByRoutingIds,
  14. listByFactoryId,
  15. checkExists
  16. } from '@/api/mainData/index.js';
  17. import {
  18. releaseWorkOrder,
  19. getcheckLoginUserIsTeamLeader
  20. } from '@/api/workOrder/index.js';
  21. export default {
  22. data() {
  23. return {};
  24. },
  25. methods: {
  26. // 查询班次
  27. getClassesData() {
  28. if (!this.current.factoriesId) return;
  29. listByFactoryId(this.current.factoriesId).then((res) => {
  30. if (!res) return;
  31. this.shiftList = res;
  32. });
  33. },
  34. // 查询是否派单
  35. queryCheckExists() {
  36. let params = {
  37. workOrderId: this.current.id,
  38. workCenterId: 123,
  39. teamId: 345
  40. };
  41. checkExists(params)
  42. .then((res) => {
  43. if (!res) return;
  44. this.isDispatchRow = res;
  45. if (res.hasExists) {
  46. this.form.taskAss = 0;
  47. this.orderDis = true;
  48. this.procTaskDis = false;
  49. // 报工类型 判断
  50. this.form.singleReport = res.dispatchType;
  51. if (res.dispatchType == 1) {
  52. this.batchDis = true;
  53. this.singleDis = false;
  54. } else {
  55. this.singleDis = true;
  56. this.batchDis = false;
  57. }
  58. } else {
  59. this.batchDis = false;
  60. this.singleDis = false;
  61. this.orderDis = false;
  62. this.procTaskDis = false;
  63. }
  64. })
  65. .catch((err) => {
  66. this.$message.error(err.message);
  67. });
  68. },
  69. // 获取当前年月日
  70. getFormattedDate() {
  71. const now = new Date();
  72. const year = now.getFullYear();
  73. const month = String(now.getMonth() + 1).padStart(2, '0');
  74. const date = String(now.getDate()).padStart(2, '0');
  75. return `${year}-${month}-${date}`;
  76. },
  77. // 查询工作中心
  78. async workCenterData() {
  79. // 判断是否存在工序id 有的话就取否则取首工序id
  80. console.log(this.current, 'this.current 查询工作中心');
  81. let id = '';
  82. if (!this.current.taskId || this.current.taskId < 0) {
  83. id = this.current.firstTaskId;
  84. } else {
  85. id = this.current.taskId;
  86. }
  87. // this.current.taskId || this.current.firstTaskId;
  88. console.log(id, 'id 查询工作中心');
  89. const res = await listWorkCenter(id);
  90. this.workCenterList = res;
  91. console.log(this.workCenterList, 'res 333');
  92. if (res.length > 0) {
  93. this.form.factoryName = res[0].factoryName;
  94. this.form.workCenterId = res[0].id;
  95. // 查首工序
  96. await this.changeWork(res[0].id); // 选择工作中心
  97. this.getProductionData(res[0].id); // 查询产线
  98. this.FirstTaskIdFn(); // 查询工位数据
  99. } else {
  100. this.$message.warning(
  101. // `${this.current.firstTaskName}工序没有工作中心,请到主数据工序管理维护工序信息!`
  102. `当前登录人不属于首工序所属工作中心及班组,请切换首工序${this.current.firstTaskName}所在的班组成员派单`
  103. );
  104. }
  105. },
  106. // 查询工序列表数据
  107. changeDispatch(e) {
  108. this.tabsLoading = true;
  109. // listByWorkCenter(this.form.workCenterId)
  110. listByRoutingIds([this.current.produceRoutingId])
  111. .then((res) => {
  112. this.tabsLoading = false;
  113. // 如果没有首工序的数据 就不能选择工序任务派单
  114. if (!res || res.length == 0) {
  115. this.processList = [];
  116. this.form.taskAss = 1;
  117. this.procTaskDis = true;
  118. return;
  119. }
  120. this.procTaskDis = false;
  121. let list = [];
  122. let isExist = false;
  123. let firstTaskindex = '';
  124. res.forEach((item, index) => {
  125. isExist = isExist
  126. ? isExist
  127. : item.sourceTaskId === this.current.firstTaskId;
  128. // 如果有首工序id 存储它的下标
  129. if (isExist) {
  130. if (!firstTaskindex && firstTaskindex !== 0) {
  131. firstTaskindex = index;
  132. }
  133. }
  134. let obj = {
  135. id: item.sourceTaskId, //工序 id
  136. name: item.name, //工序 名称
  137. assignType: 1, // 默认的指派数据
  138. assignName: '工位', // 默认指派数据名称
  139. list: [], // 当前工序下面的指派 绑定的表格
  140. selection: [], // 当前工序下面的指派 选中的数据
  141. code: item.code, // 工序 编码
  142. index: index, // 当前工序数据的下标
  143. radioBun: {
  144. // 指派按钮的操作状态 绑定 默认false(可操作)
  145. stationDis: false, // 工位按钮
  146. staffDis: false, // 人员按钮
  147. lineDis: false // 产线按钮
  148. },
  149. startDate: '', // 开始日期 (当前工序中最早的计划开始时间)
  150. endDate: '' // 结束日期 (当前工序中最晚的计划结束时间)
  151. };
  152. list.push(obj);
  153. });
  154. this.firstTaskindex = firstTaskindex;
  155. // 存在首工序报工
  156. if (isExist) {
  157. this.processList = list;
  158. this.processId = res[0].sourceTaskId;
  159. // this.handleClick({ name: res[0].sourceTaskId });
  160. this.initializeQuery();
  161. } else {
  162. this.processList = [];
  163. this.form.taskAss = 1;
  164. this.procTaskDis = true;
  165. this.$message.warning('当前任务没有首工序报工');
  166. }
  167. })
  168. .catch((err) => {
  169. this.processList = [];
  170. this.tabsLoading = false;
  171. this.$message.error(err.message);
  172. });
  173. },
  174. // 初始化查询 查询全部工序操作过的数据
  175. async initializeQuery() {
  176. try {
  177. // 不存在 班组数据的话 就不调用这个方法
  178. if (!this.form.teamId) {
  179. return;
  180. }
  181. let params = {
  182. workOrderId: this.current.id,
  183. workCenterId: this.form.workCenterId,
  184. teamId: this.form.teamId
  185. };
  186. let processMap = {};
  187. this.processList.map((el, index) => (processMap[el.id] = index));
  188. console.log(this.processList, 'processMap');
  189. const res = await listAssign(params);
  190. let isFirstData = false; // 判断默认第一道工序是否操作过
  191. if (res && res.length > 0) {
  192. res.map((el) => {
  193. let index = processMap[el.taskId];
  194. if (index === 0 && el.assignees && el.assignees.length > 0) {
  195. isFirstData = true; // 操作过
  196. }
  197. // 这里第三个参数传空数组就好了 会自动计算的
  198. setTimeout(() => {
  199. this.operationalData(index, [el], []);
  200. });
  201. });
  202. // 没有操作过 默认获取一下表格数据
  203. if (!isFirstData) {
  204. this.handleClick({ name: this.processId });
  205. }
  206. } else {
  207. this.handleClick({ name: this.processId });
  208. }
  209. console.log(this.processList, '工序列表');
  210. } catch (err) {}
  211. },
  212. // 选择工作中心
  213. async changeWork(e) {
  214. this.form.workCenterId = e;
  215. // this.changeDispatch(); // 查询工序列表
  216. let data = this.workCenterList.find((item) => item.id == e);
  217. this.form.workCenterName = data.name;
  218. this.teamList = data.teamList || []; // 重新获取 班组数据
  219. if (this.teamList.length > 0) {
  220. this.form.teamId = this.teamList[0].id;
  221. await this.changeGroups(this.teamList[0].id); // 获取人员数据方法
  222. } else {
  223. // 如果没有 班组数据 将人员数据清空 并且判断
  224. this.crewList = [];
  225. this.form.teamId = '';
  226. let data = this.processList.find((item) => item.id == this.processId);
  227. if (data.assignType == 2) {
  228. this.$set(data, 'list', []);
  229. }
  230. }
  231. },
  232. // 选择班组 查询人员的数据
  233. async changeGroups(e) {
  234. let data = this.teamList.find((item) => item.id == e);
  235. this.form.teamName = data.name;
  236. try {
  237. const res = await listUserByIds([e]);
  238. this.crewList = res;
  239. // 查看当前的工序数据是不是 选择的人员 是的话同步更改
  240. if (!this.processId || this.processId == 0) {
  241. return;
  242. }
  243. this.handleClick({ name: this.processId });
  244. this.btnInit();
  245. } catch {
  246. this.crewList = [];
  247. }
  248. },
  249. // 工序按钮初始化
  250. btnInit() {
  251. let data = this.processList.find((item) => item.id == this.processId);
  252. this.$set(data.radioBun, 'lineDis', false);
  253. this.$set(data.radioBun, 'staffDis', false);
  254. this.$set(data.radioBun, 'stationDis', false);
  255. this.$set(data, 'assignName', '工位');
  256. this.$set(data, 'assignType', 1);
  257. },
  258. // 获取产线数据
  259. async getProductionData() {
  260. const res = await lineByCurrentUser(this.form.workCenterId);
  261. this.productionList =
  262. res &&
  263. res.map((el) => {
  264. return {
  265. name: el.name,
  266. code: el.code,
  267. id: el.id
  268. };
  269. });
  270. },
  271. // 查询工位数据
  272. FirstTaskIdFn() {
  273. console.log(this.current, 'this.current 查询工位数据');
  274. // let id = this.current.taskId || this.current.firstTaskId;
  275. let id = '';
  276. if (!this.current.taskId || this.current.taskId < 0) {
  277. id = this.current.firstTaskId;
  278. } else {
  279. id = this.current.taskId;
  280. }
  281. console.log(id, 'id 查询工位数据');
  282. listByFirstTaskId(id)
  283. .then((res) => {
  284. this.stationList = res;
  285. this.stationList.forEach((item, index) => {
  286. let substance = item.workstationSubstanceList[0]?.substance;
  287. if (substance) {
  288. this.$set(this.stationList[index], 'assetName', substance.name);
  289. this.$set(this.stationList[index], 'assetCode', substance.code);
  290. this.$set(
  291. this.stationList[index],
  292. 'assetModelType',
  293. substance.category?.category?.modelType
  294. );
  295. this.$set(
  296. this.stationList[index],
  297. 'assetCategoryLevelPath',
  298. substance.category?.category?.categoryLevelPath?.split('-')[0]
  299. );
  300. }
  301. });
  302. this.changeDispatch();
  303. })
  304. .catch((err) => {
  305. this.stationList = [];
  306. this.$message.error(err.message);
  307. });
  308. },
  309. // 重置(单个)
  310. resetData(row, item) {
  311. if (!row.changeId) {
  312. return this.$message.warning('只能对已撤回跟已保存的数据进行重置');
  313. }
  314. this.toolbarLoading = true;
  315. resetAssignee(row.changeId)
  316. .then((res) => {
  317. this.toolbarLoading = false;
  318. if (res) {
  319. this.$message.success('操作成功');
  320. // 更改当前表格数据
  321. this.setCurrentTab(item);
  322. }
  323. })
  324. .catch((err) => {
  325. this.toolbarLoading = false;
  326. this.$message.error(err.message);
  327. });
  328. },
  329. // 撤回的逻辑
  330. getWithdrawT(row, type) {
  331. if (type != 2) {
  332. return true;
  333. }
  334. let isFlag = true;
  335. row.selection.forEach((item) => {
  336. if (!item.status) {
  337. isFlag = false;
  338. return;
  339. }
  340. if (!item.status.code) {
  341. isFlag = false;
  342. }
  343. });
  344. return isFlag;
  345. },
  346. // 派单
  347. dispatch(row, type) {
  348. console.log(row, 'row 333');
  349. console.log(type, 'type');
  350. if (row.selection.length == 0) {
  351. return this.$message.warning('请最少选择一条数据');
  352. }
  353. let isWithdraw = this.getWithdrawT(row, type);
  354. if (!isWithdraw) {
  355. this.$message.warning('只有状态为派单的数据才能进行撤回');
  356. return;
  357. }
  358. let assignees = [];
  359. let changeIds = [];
  360. let flag = true; // 是否填写 校验
  361. row.selection.forEach((item) => {
  362. if (!item.quantity || !item.startTime || !item.endTime) {
  363. flag = false;
  364. return;
  365. }
  366. if (item.quantity == 0) {
  367. this.$message.warning('请检查所选数据的数量不能为0');
  368. digit = false;
  369. return;
  370. }
  371. let Aobj = {
  372. assigneeId: item.id,
  373. quantity: item.quantity,
  374. weight: item.weight,
  375. startTime: item.startTime,
  376. endTime: item.endTime,
  377. assigneeType: row.assignType,
  378. assigneeName: item.name
  379. };
  380. if (item.teamTimeIds) {
  381. Aobj.teamTimeIds = item.teamTimeIds;
  382. }
  383. assignees.push(Aobj);
  384. changeIds.push(item.changeId);
  385. });
  386. // 校验没过 就不往下进行
  387. if (!flag) {
  388. this.$message.warning('请将所选数据的 数量,开始时间,完成时间 填写完毕');
  389. return;
  390. }
  391. let data = null;
  392. if (type == 2) {
  393. data = changeIds;
  394. } else {
  395. data = {
  396. taskId: this.processId,
  397. taskName: row.name,
  398. taskCode: row.code,
  399. teamName: this.form.teamName,
  400. teamId: this.form.teamId,
  401. workCenterId: this.form.workCenterId,
  402. workCenterName: this.form.workCenterName,
  403. workOrderId: this.current.id,
  404. dispatchMethod: 0,
  405. assignees
  406. };
  407. // 先判断是否派单过 有的话直接用前面派单的 类型数据 否则就是自己选择的数据
  408. if (this.isDispatchRow.hasExists) {
  409. data.dispatchType = this.isDispatchRow.dispatchType;
  410. } else {
  411. let singFlag = this.singleReportRadio();
  412. if (!singFlag) return;
  413. data.dispatchType = this.form.singleReport;
  414. }
  415. }
  416. this.toolbarLoading = true;
  417. const api =
  418. type == 1 ? taskAssignment : type == 2 ? taskRevoked : taskSave;
  419. api(data)
  420. .then((res) => {
  421. this.toolbarLoading = false;
  422. if (res) {
  423. this.$message.success('操作成功');
  424. // 更改当前表格数据
  425. this.setCurrentTab(row);
  426. // 查询是否派单
  427. this.queryCheckExists();
  428. }
  429. })
  430. .catch((err) => {
  431. this.toolbarLoading = false;
  432. this.$message.error(err.message);
  433. });
  434. },
  435. cancel() {
  436. this.$emit('update:dispatchVisible', false);
  437. },
  438. // 按钮操作成功后 更改当前的表格数据
  439. setCurrentTab(row) {
  440. let arr = [];
  441. if (row.assignType == 1) {
  442. arr = this.stationList;
  443. } else if (row.assignType == 2) {
  444. arr = this.crewList;
  445. } else {
  446. arr = this.productionList;
  447. }
  448. this.getAssignData(row.index, arr);
  449. },
  450. singleReportRadio() {
  451. if (this.form.singleReport === 0 || this.form.singleReport === 1) {
  452. return true;
  453. }
  454. this.$message.warning('请先选择报工类型');
  455. return false;
  456. },
  457. // 最后提交
  458. async confirm() {
  459. let flag = this.singleReportRadio();
  460. if (!flag) return;
  461. // if (!this.form.singleReport) {
  462. // }
  463. if (!this.form.teamId) {
  464. this.$message.warning('请先选择班组');
  465. return;
  466. }
  467. try {
  468. const isTeamLeader = await getcheckLoginUserIsTeamLeader(this.form.teamId);
  469. if (!isTeamLeader) {
  470. this.toolbarLoading = false;
  471. this.$message.warning('当前班组不是对应组长');
  472. return;
  473. }
  474. } catch (err) {
  475. this.toolbarLoading = false;
  476. this.$message.error('校验组长身份失败:' + err.message);
  477. return;
  478. }
  479. if (this.form.taskAss == 1) {
  480. this.issue();
  481. // 按原来的逻辑
  482. return;
  483. }
  484. // 获取到首工序id 的 绑定表格数据
  485. let data = this.processList[this.firstTaskindex];
  486. // 是否进行首工序派单
  487. let isFirstDispatch = false;
  488. let dispatchArr = []; // 已派单数据
  489. data.list.map((item) => {
  490. if (!item.status) {
  491. return;
  492. }
  493. if (item.status.code == 1) {
  494. isFirstDispatch = true;
  495. dispatchArr.push(item.id);
  496. }
  497. });
  498. // 判断是否进行首工序派单
  499. if (!isFirstDispatch) {
  500. this.$message.warning(`请您先进行首工序任务(${data.name}工序)派单`);
  501. this.handleClick({ name: data.id });
  502. return;
  503. }
  504. let totalSum = 0;
  505. // 判断派单的数据 数量相加是否为 要求生产数量
  506. data.list.map((item) => {
  507. if (item.status && item.status.code == 1) {
  508. totalSum += item.quantity - 0;
  509. }
  510. });
  511. // if (totalSum != this.current.formingNum - 0) {
  512. // this.$message.warning(
  513. // `首工序已派单的数据数量相加需要等于要求生产数量${this.current.formingNum}`
  514. // );
  515. // this.handleClick({ name: data.id });
  516. // return;
  517. // }
  518. this.toolbarLoading = true;
  519. let params = {
  520. teamId: this.form.teamId,
  521. workCenterId: this.form.workCenterId,
  522. workOrderId: this.current.id
  523. };
  524. try {
  525. const res = await checkAssignConfirm(params);
  526. if (!res) {
  527. this.toolbarLoading = false;
  528. return;
  529. }
  530. let paramsD = {
  531. assignType: data.assignType,
  532. singleReport: this.form.singleReport,
  533. teamId: this.form.teamId,
  534. crewIds: data.assignType == 2 ? dispatchArr : [], // 人员 2
  535. workstationIds: data.assignType == 1 ? dispatchArr : [], // 工位 1
  536. id: this.current.id,
  537. planStartTime: this.current.planStartTime,
  538. planEndTime: this.current.planEndTime
  539. };
  540. const response = await releaseWorkOrder(paramsD);
  541. this.toolbarLoading = false;
  542. if (response) {
  543. this.$message.success('操作成功');
  544. this.cancel();
  545. this.$emit('createSuccess');
  546. }
  547. } catch (err) {
  548. this.toolbarLoading = false;
  549. this.$message.error(err.message);
  550. }
  551. },
  552. // 下达
  553. issue() {
  554. if (this.form.assignType == 1) {
  555. if (!this.form.workstationIds || this.form.workstationIds.length == 0) {
  556. this.$message.warning('请选择工位数据');
  557. return;
  558. }
  559. }
  560. if (this.form.assignType == 3) {
  561. if (!this.form.factoryLineIds || this.form.factoryLineIds.length == 0) {
  562. this.$message.warning('请选择产线数据');
  563. return;
  564. }
  565. }
  566. let data = {
  567. assignType: this.form.assignType,
  568. singleReport: this.form.singleReport,
  569. teamId: this.form.teamId,
  570. crewIds: [],
  571. workstationIds: [],
  572. id: this.current.id,
  573. planStartTime: this.current.planStartTime,
  574. planCompleteTime: this.current.planCompleteTime,
  575. factoryLineIds: []
  576. };
  577. if (this.form.assignType == 1) {
  578. data.workstationIds = this.form.workstationIds || [];
  579. } else if (this.form.assignType == 2) {
  580. data.crewIds = this.form.crewIds || [];
  581. } else {
  582. data.factoryLineIds = this.form.factoryLineIds || [];
  583. }
  584. this.toolbarLoading = true;
  585. releaseWorkOrder(data)
  586. .then((res) => {
  587. this.toolbarLoading = false;
  588. if (res) {
  589. this.$message.success('操作成功');
  590. this.cancel();
  591. this.$emit('createSuccess');
  592. }
  593. })
  594. .catch((err) => {
  595. this.toolbarLoading = false;
  596. this.$message.error(err.message);
  597. });
  598. },
  599. // 工序选择
  600. async handleClick(tab) {
  601. let id = tab.name;
  602. this.processId = id;
  603. let data = this.processList.find((item) => item.id == this.processId);
  604. await this.changeRadio(data.assignType, data.index);
  605. },
  606. // 指派选择
  607. async changeRadio(e, index) {
  608. let data = this.processList[index];
  609. if (e == 1) {
  610. this.dynamicName = '工位名称';
  611. data.assignName = '工位';
  612. await this.getAssignData(index, this.stationList);
  613. } else if (e == 2) {
  614. this.dynamicName = '人员名称';
  615. data.assignName = '人员';
  616. await this.getAssignData(index, this.crewList);
  617. } else {
  618. this.dynamicName = '产线名称';
  619. data.assignName = '产线';
  620. await this.getAssignData(index, this.productionList);
  621. }
  622. },
  623. // 指派数据处理
  624. async getAssignData(index, arr) {
  625. let list = JSON.parse(JSON.stringify(arr));
  626. let dataRow = this.processList[index];
  627. // 不存在 班组数据的话 就不调用这个方法
  628. if (!this.form.teamId) {
  629. return;
  630. }
  631. let params = {
  632. workOrderId: this.current.id,
  633. workCenterId: this.form.workCenterId,
  634. teamId: this.form.teamId,
  635. taskId: dataRow.id
  636. };
  637. this.tabLoading = true;
  638. try {
  639. const res = await listAssign(params);
  640. this.tabLoading = false;
  641. // 如果 res 没有数据 说明未对数据进行操作 直接赋值
  642. if (res.length == 0) {
  643. this.$set(dataRow, 'list', list);
  644. return;
  645. }
  646. // 对有操作过的数据进行赋值
  647. this.operationalData(index, res, list);
  648. } catch (err) {
  649. this.tabLoading = false;
  650. this.$message.warning(err.message);
  651. }
  652. },
  653. // 操作过的数据 赋值
  654. operationalData(index, res, list) {
  655. const dataRow = this.processList[index];
  656. // 键值对存储 当前工序 操作的数据 指派的code(键) 数据(list:值)
  657. let arrMap = {};
  658. // 要先判断有没有操作的数据 如果有的话 其它的指派操作置灰
  659. let codeT = null; // 表示有已操作的数据(对应的 code)
  660. res[0].assignees.map((el) => {
  661. let code = el.assigneeType.code;
  662. if (arrMap[code]) {
  663. arrMap[code].arr.push(el);
  664. arrMap[code].bunDis = arrMap[code].bunDis
  665. ? arrMap[code].bunDis
  666. : el.status.desc
  667. ? true
  668. : false;
  669. } else {
  670. arrMap[code] = {
  671. arr: [el],
  672. bunDis: el.status.desc ? true : false
  673. };
  674. }
  675. codeT = codeT ? codeT : el.status.desc ? code : '';
  676. });
  677. let radioBun = {
  678. lineDis: false, // 产线 3
  679. staffDis: false, // 人员 2
  680. stationDis: false // 工位 1
  681. };
  682. // 默认是传递下来的 list 数据 但是如果 codeT有值 说明 工位 人员 产线 有派单数据
  683. // 需要自动切换过去
  684. let listArr = list;
  685. if (codeT) {
  686. if (codeT == 1) {
  687. radioBun.staffDis = true;
  688. radioBun.lineDis = true;
  689. radioBun.stationDis = false;
  690. listArr = JSON.parse(JSON.stringify(this.stationList));
  691. dataRow.assignType = 1;
  692. dataRow.assignName = '工位';
  693. } else if (codeT == 2) {
  694. radioBun.stationDis = true;
  695. radioBun.lineDis = true;
  696. radioBun.staffDis = false;
  697. listArr = JSON.parse(JSON.stringify(this.crewList));
  698. dataRow.assignType = 2;
  699. dataRow.assignName = '人员';
  700. } else {
  701. radioBun.stationDis = true;
  702. radioBun.staffDis = true;
  703. radioBun.lineDis = false;
  704. listArr = JSON.parse(JSON.stringify(this.productionList));
  705. dataRow.assignType = 3;
  706. dataRow.assignName = '产线';
  707. }
  708. }
  709. // 切换完后 对 指派的数组数据进行赋值
  710. let listMap = {};
  711. listArr.map((el, index) => (listMap[el.id] = index));
  712. let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
  713. dataRow.startDate = ''; // 每次计算的时候清空之前的
  714. dataRow.endDate = '';
  715. arrList.map((item) => {
  716. if (item.assigneeType.code == dataRow.assignType) {
  717. let idx = listMap[item.assigneeId];
  718. if (!idx && idx !== 0) {
  719. return;
  720. }
  721. listArr[idx].status = item.status;
  722. listArr[idx].startTime = item.startTime;
  723. listArr[idx].endTime = item.endTime;
  724. listArr[idx].quantity = item.quantity;
  725. listArr[idx].weight = item.weight;
  726. listArr[idx].changeId = item.id;
  727. listArr[idx].teamTimeIds = item.teamTimeIds;
  728. this.compareAndSetTime(listArr[idx], dataRow);
  729. this.compareEndSetTime(listArr[idx], dataRow);
  730. }
  731. });
  732. // 这里重新调用一个方法 计算出 startDate endDate
  733. this.$set(dataRow, 'list', listArr);
  734. this.$set(dataRow, 'radioBun', radioBun);
  735. this.$set(dataRow, 'selection', []);
  736. let tab = `tableRef${[dataRow.index]}`;
  737. this.$refs[tab][0].setSelectedRowKeys([]);
  738. console.log(dataRow, 'dataRow +++++');
  739. },
  740. // 时间比较与赋值方法 开始时间
  741. compareAndSetTime(data, dataRow) {
  742. // 如果startDate为空,直接赋值为startTime
  743. if (!dataRow.startDate) {
  744. dataRow.startDate = data['startTime'];
  745. return;
  746. }
  747. // 转换为Date对象进行比较
  748. const startTimeDate = new Date(data['startTime']);
  749. const startDateDate = new Date(dataRow.startDate);
  750. // 比较时间(getTime()获取时间戳)
  751. if (startTimeDate.getTime() < startDateDate.getTime()) {
  752. dataRow.startDate = data['startTime'];
  753. }
  754. },
  755. // 时间比较与赋值方法 结束时间时间
  756. compareEndSetTime(data, dataRow) {
  757. // 如果startDate为空,直接赋值为endTime
  758. if (!dataRow.endDate) {
  759. dataRow.endDate = data['endTime'];
  760. return;
  761. }
  762. // 转换为Date对象进行比较
  763. const endTimeDate = new Date(data['endTime']);
  764. const endDateDate = new Date(dataRow.endDate);
  765. // 比较时间(getTime()获取时间戳)
  766. if (endTimeDate.getTime() > endDateDate.getTime()) {
  767. dataRow.endDate = data['endTime'];
  768. }
  769. },
  770. assignRadio(e) {},
  771. // 数量正则 quantity
  772. handleQuantityInput(e, row, item) {
  773. // 过滤非数字字符(包括负号)
  774. let value = e.replace(/[^\d]/g, '');
  775. // 限制不能以 0 开头(除非是 0 本身)
  776. if (value.startsWith('0') && value.length > 1) {
  777. value = value.slice(1);
  778. }
  779. // 更新绑定值
  780. row.quantity = value;
  781. this.calculateQuantity(row, item);
  782. this.bringWeight(row.quantity, row);
  783. this.selectedListData(row, item);
  784. },
  785. // 自动算重量
  786. bringWeight(value, row) {
  787. if (!this.current.formingWeight) {
  788. this.$set(row, 'weight', 0);
  789. return;
  790. }
  791. let weight =
  792. (this.current.formingWeight / this.current.formingNum) * value;
  793. if (weight > 0) {
  794. weight = weight.toFixed(4) - 0;
  795. }
  796. this.$set(row, 'weight', weight);
  797. },
  798. calculateQuantity(row, item) {
  799. // 如果没有该字段 就不做判断
  800. if (!this.current.formingNum) {
  801. return;
  802. }
  803. let total = 0;
  804. item.list.forEach((el) => {
  805. if (el.quantity) {
  806. total = total + (el.quantity - 0);
  807. }
  808. });
  809. if (total > this.current.formingNum - 0) {
  810. this.$message.warning('列表数量相加不能大于目标要求生产数量');
  811. row.quantity = 0;
  812. }
  813. },
  814. // 计算重量
  815. calculateWeight(row, item) {
  816. // 如果没有该字段 就不做判断
  817. if (!this.current.formingWeight) {
  818. return;
  819. }
  820. let total = 0;
  821. item.list.forEach((el) => {
  822. if (el.weight) {
  823. total = total + (el.weight - 0);
  824. }
  825. });
  826. if (total > this.current.formingWeight - 0) {
  827. this.$message.warning('列表数量相加不能大于目标要求生产数量');
  828. row.weight = 0;
  829. }
  830. },
  831. // 重量正则 weight
  832. handleWeightInput(e, row, item) {
  833. // 过滤非数字和非小数点字符(包括负号)
  834. let value = e.replace(/[-+^\d.]/g, '');
  835. value = e.replace(/[^\d.]/g, '');
  836. // 限制只能有一个小数点
  837. const dotCount = (value.match(/\./g) || []).length;
  838. if (dotCount > 1) {
  839. value = value.slice(0, value.lastIndexOf('.'));
  840. }
  841. // 限制不能以小数点开头
  842. if (value.startsWith('.')) {
  843. value = '0' + value;
  844. }
  845. // 更新绑定值
  846. row.weight = value;
  847. this.calculateWeight(row, item);
  848. this.selectedListData(row, item);
  849. },
  850. // 选中班次
  851. shiftSelection(e, row, item) {
  852. // this.$refs.tableRef0[0].setSelectedRowKeys(row.id);
  853. // let data = this.shiftList.find((item) => item.id == e);
  854. this.selectedListData(row, item);
  855. let data = this.shifTimeData(e, row);
  856. let startTime = `${this.dateValue} ${data.startTime}`;
  857. let endTime = `${this.dateValue} ${data.endTime}`;
  858. this.$set(row, 'startTime', startTime);
  859. this.$set(row, 'endTime', endTime);
  860. this.handleStartTimeChange(row, item);
  861. this.handleEndTimeChange(row, item);
  862. },
  863. // 默认选中当前更改数据
  864. selectedListData(row, item) {
  865. let data = item.selection.find((el) => el.id == row.id);
  866. if (!data) {
  867. let ids = item.selection.map((el) => el.id);
  868. ids.push(row.id);
  869. let tab = `tableRef${[item.index]}`;
  870. this.$refs[tab][0].setSelectedRowKeys(ids);
  871. }
  872. },
  873. // 多选班次时间数据
  874. shifTimeData(e, row) {
  875. if (!e || e.length == 0) {
  876. return {
  877. startTime: row.startTime,
  878. endTime: row.endTime
  879. };
  880. }
  881. let startTime = '';
  882. let endTime = '';
  883. e.map((el) => {
  884. let obj = this.shiftList.find((item) => item.id == el);
  885. if (!startTime) {
  886. startTime = obj.startTime;
  887. }
  888. if (!endTime) {
  889. endTime = obj.endTime;
  890. }
  891. // 获取更小的
  892. startTime =
  893. this.compareTime(startTime, obj.startTime) !== -1
  894. ? obj.startTime
  895. : startTime;
  896. // 获取更大的
  897. endTime =
  898. this.compareTime(endTime, obj.endTime) !== 1 ? obj.endTime : endTime;
  899. });
  900. return {
  901. startTime,
  902. endTime
  903. };
  904. },
  905. // 将HH:mm:ss格式的时间转换为总秒数
  906. timeToSeconds(timeStr) {
  907. const [hours, minutes, seconds] = timeStr.split(':').map(Number);
  908. return hours * 3600 + minutes * 60 + seconds;
  909. },
  910. // this.$refs.table.setSelectedRowKeys(ids);
  911. // 比较两个时间的大小
  912. compareTime(time1, time2) {
  913. const sec1 = this.timeToSeconds(time1);
  914. const sec2 = this.timeToSeconds(time2);
  915. if (sec1 > sec2) {
  916. return 1; // time1 更大
  917. } else if (sec1 < sec2) {
  918. return -1; // time2 更大
  919. } else {
  920. return 0; // 两个时间相等
  921. }
  922. },
  923. // 【开始时间变化时】触发
  924. handleStartTimeChange(row, item) {
  925. if (!row.startTime) {
  926. return;
  927. }
  928. this.selectedListData(row, item);
  929. // 这一道工序的开始时间 不能小于前一道工序的结束时间
  930. const startTime = new Date(row.startTime); // 开始时间
  931. if (item.index !== 0) {
  932. // let frontIdx = item.index - 1;
  933. let frontIdx = this.calculateIndex(item.index).startIdx;
  934. if (frontIdx !== 'none') {
  935. let frontName = this.processList[frontIdx].name;
  936. let time = this.processList[frontIdx].endDate;
  937. const frontTime = new Date(time); // 前面工序的结束时间
  938. if (time && startTime < frontTime) {
  939. this.$message.closeAll();
  940. this.$message.info(
  941. `开始时间不能小于前面工序${frontName}的结束时间${time}`
  942. );
  943. // 判断是否 配置时间更改规则
  944. if (this.time_calc_code == '1') {
  945. row.startTime = time;
  946. }
  947. return;
  948. }
  949. }
  950. }
  951. // 这一道工序的开始时间更不能大于后一道工序的开始时间
  952. if (item.index !== this.processList.length - 1) {
  953. // let latterIdx = item.index + 1;
  954. let latterIdx = this.calculateIndex(item.index).endIdx;
  955. if (latterIdx !== 'none') {
  956. let time = this.processList[latterIdx].startDate;
  957. let latterName = this.processList[latterIdx].name;
  958. const latterTime = new Date(time); // 下一道工序的结束时间
  959. if (time && startTime > latterTime) {
  960. this.$message.closeAll();
  961. this.$message.info(
  962. `开始时间不能大于后面工序${latterName}的开始时间${time}`
  963. );
  964. // 判断是否 配置时间更改规则
  965. if (this.time_calc_code == '1') {
  966. row.startTime = '';
  967. }
  968. return;
  969. }
  970. }
  971. }
  972. // 校验 是否 大于结束时间 wda
  973. this.checkEndTimeValid(row);
  974. },
  975. // 当更改一个工序开始时间 结束时间的时候
  976. // 开始时间 不能小于之前工序的结束时间 ( 要先去上一道工序找 是否存在结束时间 不存在就再往前找 直到 第一道工序 )
  977. // 结束时间 不能大于后面工序的开始时间 ( 要先去后一道工序找 是否存在开始时间 不存在就再往后找 直到 最后一道工序 )
  978. // 计算出当前下标数据 的前后 有 开始时间 结束时间的数据下标
  979. calculateIndex(index) {
  980. let startIdx = 'none';
  981. let endIdx = 'none';
  982. // 前面工序下标
  983. for (let i = index - 1; i >= 0; i--) {
  984. let row = this.processList[i];
  985. if (row && row.endDate) {
  986. startIdx = i;
  987. break;
  988. }
  989. }
  990. // 后面工序的下标
  991. for (let i = index + 1; i <= this.processList.length; i++) {
  992. let row = this.processList[i];
  993. if (row && row.startDate) {
  994. endIdx = i;
  995. break;
  996. }
  997. }
  998. return {
  999. startIdx,
  1000. endIdx
  1001. };
  1002. },
  1003. // 【结束时间变化时】触发
  1004. handleEndTimeChange(row, item) {
  1005. if (!row.endTime) {
  1006. return;
  1007. }
  1008. this.selectedListData(row, item);
  1009. const endTime = new Date(row.endTime); // 结束时间
  1010. // 当前工序的结束时间 不能大于后一道工序的开始时间
  1011. if (item.index !== this.processList.length - 1) {
  1012. let latterIdx = this.calculateIndex(item.index).endIdx;
  1013. if (latterIdx !== 'none') {
  1014. let latterName = this.processList[latterIdx].name;
  1015. let time = this.processList[latterIdx].startDate;
  1016. const latterTime = new Date(time); // 后面工序的开始时间
  1017. if (time && endTime > latterTime) {
  1018. this.$message.closeAll();
  1019. this.$message.info(
  1020. `结束时间不能大于后面工序${latterName}的开始时间${time}`
  1021. );
  1022. // 判断是否 配置时间更改规则
  1023. if (this.time_calc_code == '1') {
  1024. row.endTime = time;
  1025. }
  1026. return;
  1027. }
  1028. }
  1029. }
  1030. // 这一道工序的开始时间更不能小于于前一道工序的结束时间
  1031. if (item.index !== 0) {
  1032. let frontIdx = this.calculateIndex(item.index).startIdx;
  1033. if (frontIdx !== 'none') {
  1034. let frontName = this.processList[frontIdx].name;
  1035. let time = this.processList[frontIdx].endDate;
  1036. const frontTime = new Date(time); // 上一道工序的结束时间
  1037. if (time && endTime < frontTime) {
  1038. this.$message.closeAll();
  1039. this.$message.info(
  1040. `结束时间不能小于前面工序${frontName}的结束时间${time}`
  1041. );
  1042. // 判断是否 配置时间更改规则
  1043. if (this.time_calc_code == '1') {
  1044. row.endTime = '';
  1045. }
  1046. return;
  1047. }
  1048. }
  1049. }
  1050. this.checkEndTimeValid(row, item);
  1051. },
  1052. // 时间校验
  1053. checkEndTimeValid(row) {
  1054. const { startTime: start, endTime: end } = row;
  1055. // if (!start || !end) return; // 开始/结束时间未填,跳过
  1056. const startTime = new Date(start); // 开始时间
  1057. const endTime = new Date(end); // 结束时间
  1058. if (endTime < startTime) {
  1059. row.endTime = new Date(startTime); // 修正为开始时间
  1060. this.$message.info('结束时间不能早于开始时间,已自动设为开始时间');
  1061. }
  1062. }
  1063. }
  1064. };