release.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. import {
  2. listByFirstTaskId,
  3. listUserByIds,
  4. listWorkCenter,
  5. listByWorkCenter,
  6. lineByCurrentUser,
  7. taskSave,
  8. taskRevoked,
  9. taskAssignment,
  10. listAssign,
  11. checkAssignConfirm,
  12. checkAssignSourceType,
  13. resetAssignee,
  14. listByRoutingIds,
  15. listByFactoryId,
  16. checkExists,
  17. parameterGetByCode
  18. } from '@/api/mainData/index.js';
  19. import {
  20. releaseWorkOrder,
  21. getcheckLoginUserIsTeamLeader,
  22. getUserInfo
  23. } from '@/api/workOrder/index.js';
  24. // import { }
  25. export default {
  26. data() {
  27. return {
  28. isTpye: ''
  29. };
  30. },
  31. created() {
  32. // console.log('组件传入的选项:', this.$options.mixinOptions);
  33. this.isTpye = this.$options.mixinOptions.type;
  34. },
  35. methods: {
  36. // 查询班次
  37. getClassesData() {
  38. if (!this.current.factoriesId) return;
  39. listByFactoryId(this.current.factoriesId).then((res) => {
  40. if (!res) return;
  41. this.shiftList = res;
  42. });
  43. },
  44. // 查询是否派单
  45. queryCheckExists() {
  46. let params = {
  47. workOrderId: this.current.id,
  48. workCenterId: 123,
  49. teamId: 345
  50. };
  51. checkExists(params)
  52. .then((res) => {
  53. if (!res) return;
  54. this.isDispatchRow = res;
  55. if (res.hasExists) {
  56. this.form.taskAss = 0;
  57. this.orderDis = true;
  58. this.procTaskDis = false;
  59. // 报工类型 判断
  60. this.form.singleReport = res.dispatchType;
  61. if (res.dispatchType == 1) {
  62. this.batchDis = true;
  63. this.singleDis = false;
  64. } else {
  65. this.singleDis = true;
  66. this.batchDis = false;
  67. }
  68. } else {
  69. this.batchDis = false;
  70. this.singleDis = false;
  71. this.orderDis = false;
  72. this.procTaskDis = false;
  73. }
  74. })
  75. .catch((err) => {
  76. this.$message.error(err.message);
  77. });
  78. },
  79. // 获取当前年月日
  80. getFormattedDate() {
  81. const now = new Date();
  82. const year = now.getFullYear();
  83. const month = String(now.getMonth() + 1).padStart(2, '0');
  84. const date = String(now.getDate()).padStart(2, '0');
  85. return `${year}-${month}-${date}`;
  86. },
  87. // 查询工作中心
  88. async workCenterData() {
  89. // 判断是否存在工序id 有的话就取否则取首工序id
  90. console.log(this.current, 'this.current 查询工作中心');
  91. let id = '';
  92. if (!this.current.taskId || this.current.taskId < 0) {
  93. id = this.current.firstTaskId;
  94. } else {
  95. id = this.current.taskId;
  96. }
  97. if (this.current?.factoryName) {
  98. this.form.factoryName = this.current.factoryName;
  99. }
  100. // this.current.taskId || this.current.firstTaskId;
  101. const res = await listWorkCenter(id);
  102. console.log(res, 'ressss');
  103. const userData = await getUserInfo(this.$store.state.user.info.userId);
  104. this.workCenterList = res;
  105. if (res.length > 0) {
  106. // this.form.factoryName = res[0].factoryName;
  107. this.form.workCenterId = res[0].id;
  108. if (this.isTpye == 'add') {
  109. if (userData.centerList.length == 0) {
  110. this.form.isDisable = true;
  111. return this.$message.warning(
  112. `当前登录人没有配置所属中心,请先去主数据给该登录人配置所属中心`
  113. );
  114. }
  115. if (userData.centerList.length != 0) {
  116. // centerId
  117. if (res.length != 0) {
  118. const data = userData.centerList.filter(
  119. (it) => it.centerId == res[0].id
  120. );
  121. if (data.length == 0) {
  122. this.form.isDisable = true;
  123. return this.$message.warning(`当前登录人没有权限给该工单派单`);
  124. }
  125. }
  126. }
  127. }
  128. // 查首工序
  129. await this.changeWork(res[0].id); // 选择工作中心
  130. this.getProductionData(res[0].id); // 查询产线
  131. this.FirstTaskIdFn(); // 查询工位数据
  132. } else {
  133. this.$message.warning(
  134. // `${this.current.firstTaskName}工序没有工作中心,请到主数据工序管理维护工序信息!`
  135. `当前登录人不属于首工序所属工作中心及班组,请切换首工序${this.current.firstTaskName}所在的班组成员派单`
  136. );
  137. }
  138. },
  139. // 查询工序列表数据
  140. changeDispatch(e) {
  141. this.tabsLoading = true;
  142. // listByWorkCenter(this.form.workCenterId)
  143. listByRoutingIds([this.current.produceRoutingId])
  144. .then((res) => {
  145. this.tabsLoading = false;
  146. // 如果没有首工序的数据 就不能选择工序任务派单
  147. if (!res || res.length == 0) {
  148. this.processList = [];
  149. this.form.taskAss = 1;
  150. this.procTaskDis = true;
  151. return;
  152. }
  153. this.procTaskDis = false;
  154. let list = [];
  155. let isExist = false;
  156. let firstTaskindex = '';
  157. res.forEach((item, index) => {
  158. isExist = isExist
  159. ? isExist
  160. : item.sourceTaskId === this.current.firstTaskId;
  161. // 如果有首工序id 存储它的下标
  162. if (isExist) {
  163. if (!firstTaskindex && firstTaskindex !== 0) {
  164. firstTaskindex = index;
  165. }
  166. }
  167. let obj = {
  168. id: item.sourceTaskId, //工序 id
  169. name: item.name, //工序 名称
  170. assignType: 1, // 默认的指派数据
  171. assignName: '工位', // 默认指派数据名称
  172. list: [], // 当前工序下面的指派 绑定的表格
  173. selection: [], // 当前工序下面的指派 选中的数据f
  174. code: item.code, // 工序 编码
  175. index: index, // 当前工序数据的下标
  176. radioBun: {
  177. // 指派按钮的操作状态 绑定 默认false(可操作)
  178. stationDis: false, // 工位按钮
  179. staffDis: false, // 人员按钮
  180. lineDis: false // 产线按钮
  181. },
  182. isDisable:
  183. this.form.workCenterId == item.workCenterId ? true : false,
  184. startDate: '', // 开始日期 (当前工序中最早的计划开始时间)
  185. endDate: '', // 结束日期 (当前工序中最晚的计划结束时间)
  186. workCenterId: item.workCenterId,
  187. workCenterName: item.workCenterName
  188. };
  189. list.push(obj);
  190. });
  191. this.firstTaskindex = firstTaskindex;
  192. // 存在首工序报工
  193. if (isExist) {
  194. this.processList = list;
  195. this.processId = res[0].sourceTaskId;
  196. // this.handleClick({ name: res[0].sourceTaskId });
  197. this.initializeQuery();
  198. } else {
  199. this.processList = [];
  200. this.form.taskAss = 1;
  201. this.procTaskDis = true;
  202. this.$message.warning('当前任务没有首工序报工');
  203. }
  204. })
  205. .catch((err) => {
  206. this.processList = [];
  207. this.tabsLoading = false;
  208. this.$message.error(err.message);
  209. });
  210. },
  211. // 初始化查询 查询全部工序操作过的数据
  212. async initializeQuery() {
  213. try {
  214. // 不存在 班组数据的话 就不调用这个方法
  215. if (!this.form.teamId) {
  216. return;
  217. }
  218. let params = {
  219. workOrderId: this.current.id,
  220. workCenterId: this.form.workCenterId,
  221. teamId: this.form.teamId
  222. };
  223. let processMap = {};
  224. this.processList.map((el, index) => (processMap[el.id] = index));
  225. console.log(this.processList, 'processMap');
  226. const res = await listAssign(params);
  227. let isFirstData = false; // 判断默认第一道工序是否操作过
  228. if (res && res.length > 0) {
  229. res.map((el) => {
  230. let index = processMap[el.taskId];
  231. if (index === 0 && el.assignees && el.assignees.length > 0) {
  232. isFirstData = true; // 操作过
  233. }
  234. // 这里第三个参数传空数组就好了 会自动计算的
  235. setTimeout(() => {
  236. this.operationalData(index, [el], []);
  237. });
  238. });
  239. // 没有操作过 默认获取一下表格数据
  240. if (!isFirstData) {
  241. this.handleClick({ name: this.processId });
  242. }
  243. } else {
  244. this.handleClick({ name: this.processId });
  245. }
  246. console.log(this.processList, '工序列表');
  247. } catch (err) {}
  248. },
  249. // 选择工作中心
  250. async changeWork(e) {
  251. this.form.workCenterId = e;
  252. // this.changeDispatch(); // 查询工序列表
  253. let data = this.workCenterList.find((item) => item.id == e);
  254. this.form.workCenterName = data.name;
  255. this.teamList = data.teamList || []; // 重新获取 班组数据
  256. if (this.teamList.length > 0) {
  257. this.form.teamId = this.teamList[0].id;
  258. await this.changeGroups(this.teamList[0].id); // 获取人员数据方法
  259. } else {
  260. // 如果没有 班组数据 将人员数据清空 并且判断
  261. this.crewList = [];
  262. this.form.teamId = '';
  263. this.setTeamLeaderName(null); // 清空班组长
  264. let data = this.processList.find((item) => item.id == this.processId);
  265. if (data.assignType == 2) {
  266. this.$set(data, 'list', []);
  267. }
  268. }
  269. },
  270. // 设置班组长显示 (班组数据里的 leaderUserName)
  271. setTeamLeaderName(team) {
  272. this.$set(
  273. this.form,
  274. 'leaderUserName',
  275. (team && team.leaderUserName) || ''
  276. );
  277. this.$set(this.form, 'leaderUserId', (team && team.leaderUserId) || '');
  278. },
  279. // 选择班组 查询人员的数据
  280. async changeGroups(e) {
  281. let data = this.teamList.find((item) => item.id == e);
  282. this.form.teamName = data.name;
  283. this.setTeamLeaderName(data); // 显示班组长
  284. try {
  285. const res = await listUserByIds([e]);
  286. this.crewList = res;
  287. // 查看当前的工序数据是不是 选择的人员 是的话同步更改
  288. if (!this.processId || this.processId == 0) {
  289. return;
  290. }
  291. this.handleClick({ name: this.processId });
  292. this.btnInit();
  293. } catch {
  294. this.crewList = [];
  295. }
  296. },
  297. // 工序按钮初始化
  298. btnInit() {
  299. let data = this.processList.find((item) => item.id == this.processId);
  300. this.$set(data.radioBun, 'lineDis', false);
  301. this.$set(data.radioBun, 'staffDis', false);
  302. this.$set(data.radioBun, 'stationDis', false);
  303. this.$set(data, 'assignName', '工位');
  304. this.$set(data, 'assignType', 1);
  305. },
  306. // 获取产线数据
  307. async getProductionData() {
  308. const res = await lineByCurrentUser(this.form.workCenterId);
  309. this.productionList =
  310. res &&
  311. res.map((el) => {
  312. return {
  313. name: el.name,
  314. code: el.code,
  315. id: el.id
  316. };
  317. });
  318. },
  319. // 查询工位数据
  320. async FirstTaskIdFn(taskId) {
  321. console.log(taskId, 'taskId 查询工位数据');
  322. console.log(this.current, 'this.current 查询工位数据');
  323. // let id = this.current.taskId || this.current.firstTaskId;
  324. let id = '';
  325. if (this.isTpye == 'detail') {
  326. id = this.current.firstTaskId;
  327. } else {
  328. if (!this.current.taskId || this.current.taskId < 0) {
  329. id = this.current.firstTaskId;
  330. } else {
  331. id = this.current.taskId;
  332. }
  333. }
  334. await listByFirstTaskId(taskId ? taskId : id)
  335. .then((res) => {
  336. this.stationList = res;
  337. this.stationList.forEach((item, index) => {
  338. let substance = item.workstationSubstanceList[0]?.substance;
  339. if (substance) {
  340. this.$set(this.stationList[index], 'assetName', substance.name);
  341. this.$set(this.stationList[index], 'assetCode', substance.code);
  342. this.$set(
  343. this.stationList[index],
  344. 'assetModelType',
  345. substance.category?.category?.modelType
  346. );
  347. this.$set(
  348. this.stationList[index],
  349. 'assetCategoryLevelPath',
  350. substance.category?.category?.categoryLevelPath?.split('-')[0]
  351. );
  352. }
  353. });
  354. console.log(this.stationList, '5522200');
  355. console.log(this.isTask, '88555');
  356. if (this.isTask) {
  357. this.changeDispatch();
  358. }
  359. })
  360. .catch((err) => {
  361. this.stationList = [];
  362. this.$message.error(err.message);
  363. });
  364. },
  365. canDeleteAddedStation(row) {
  366. const statusCode = Number(row?.status?.code);
  367. return row?.isNew === 1 && statusCode !== 0 && statusCode !== 1;
  368. },
  369. refreshProcessDateRange(item) {
  370. this.$set(item, 'startDate', '');
  371. this.$set(item, 'endDate', '');
  372. const list = Array.isArray(item?.list) ? item.list : [];
  373. list.forEach((row) => {
  374. if (row.startTime) {
  375. this.compareAndSetTime(row, item);
  376. }
  377. if (row.endTime) {
  378. this.compareEndSetTime(row, item);
  379. }
  380. });
  381. },
  382. deleteRow(row, item) {
  383. if (!this.canDeleteAddedStation(row)) {
  384. return this.$message.warning(
  385. '只有通过添加工位新增且状态不是保存或派单的数据才能删除'
  386. );
  387. }
  388. const list = Array.isArray(item?.list) ? item.list : [];
  389. const nextList = list.filter((it) => it.id !== row.id);
  390. const nextSelection = Array.isArray(item?.selection)
  391. ? item.selection.filter((it) => it.id !== row.id)
  392. : [];
  393. this.$set(item, 'list', nextList);
  394. this.$set(item, 'selection', nextSelection);
  395. this.refreshProcessDateRange(item);
  396. this.$nextTick(() => {
  397. const tab = `tableRef${item.index}`;
  398. const tableRefs = this.$refs[tab];
  399. if (!tableRefs || !tableRefs[0]) {
  400. return;
  401. }
  402. tableRefs[0].setSelectedRowKeys(nextSelection.map((it) => it.id));
  403. });
  404. this.$message.success('删除成功');
  405. },
  406. applyResetViewState(row, item) {
  407. const list = Array.isArray(item?.list) ? item.list : [];
  408. const target = list.find((it) => it.id === row.id);
  409. if (!target) {
  410. return false;
  411. }
  412. this.$set(target, 'status', null);
  413. this.$set(target, 'changeId', '');
  414. return true;
  415. },
  416. // 重置(单个)
  417. resetData(row, item) {
  418. if (!row.changeId) {
  419. return this.$message.warning('只能对已撤回跟已保存的数据进行重置');
  420. }
  421. this.toolbarLoading = true;
  422. resetAssignee(row.changeId)
  423. .then((res) => {
  424. this.toolbarLoading = false;
  425. if (res) {
  426. this.$message.success('操作成功');
  427. if (row.isNew === 1 && this.applyResetViewState(row, item)) {
  428. return;
  429. }
  430. // 更改当前表格数据
  431. this.setCurrentTab(item);
  432. }
  433. })
  434. .catch((err) => {
  435. this.toolbarLoading = false;
  436. this.$message.error(err.message);
  437. });
  438. },
  439. // 撤回的逻辑
  440. getWithdrawT(row, type) {
  441. if (type != 2) {
  442. return true;
  443. }
  444. let isFlag = true;
  445. row.selection.forEach((item) => {
  446. if (!item.status) {
  447. isFlag = false;
  448. return;
  449. }
  450. if (!item.status.code) {
  451. isFlag = false;
  452. }
  453. });
  454. return isFlag;
  455. },
  456. // 派单
  457. async dispatch(row, type) {
  458. console.log(row, 'row 333');
  459. console.log(type, 'type');
  460. if (row.selection.length == 0) {
  461. return this.$message.warning('请最少选择一条数据');
  462. }
  463. let isWithdraw = this.getWithdrawT(row, type);
  464. if (!isWithdraw) {
  465. this.$message.warning('只有状态为派单的数据才能进行撤回');
  466. return;
  467. }
  468. let assignees = [];
  469. let changeIds = [];
  470. let flag = true; // 是否填写 校验
  471. console.log(row.selection, '选中的数据');
  472. row.selection.forEach((item) => {
  473. if (!item.quantity || !item.startTime || !item.endTime) {
  474. flag = false;
  475. return;
  476. }
  477. if (item.quantity == 0) {
  478. this.$message.warning('请检查所选数据的数量不能为0');
  479. digit = false;
  480. return;
  481. }
  482. console.log(item, '数据');
  483. let Aobj = {
  484. assigneeId: item.id,
  485. quantity: item.quantity,
  486. weight: item.weight,
  487. startTime: item.startTime,
  488. endTime: item.endTime,
  489. assigneeType: row.assignType,
  490. assigneeName: item.name,
  491. measuringUnit: this.current.measuringUnit,
  492. isNew: item.isNew ? item.isNew : '',
  493. deviceId:
  494. item.extInfo && item.extInfo.assetId ? item.extInfo.assetId : '',
  495. deviceName:
  496. item.extInfo && item.extInfo.assetName
  497. ? item.extInfo.assetName
  498. : '',
  499. workStationId: item.id,
  500. workStationName: item.name
  501. };
  502. if (item.teamTimeIds) {
  503. Aobj.teamTimeIds = item.teamTimeIds;
  504. }
  505. assignees.push(Aobj);
  506. changeIds.push(item.changeId);
  507. });
  508. // 校验没过 就不往下进行
  509. if (!flag) {
  510. this.$message.warning('请将所选数据的 数量,开始时间,完成时间 填写完毕');
  511. return;
  512. }
  513. let data = null;
  514. if (type == 2) {
  515. data = changeIds;
  516. } else {
  517. data = {
  518. taskId: this.processId,
  519. taskName: row.name,
  520. taskCode: row.code,
  521. teamName: this.form.teamName,
  522. teamId: this.form.teamId,
  523. workCenterId: this.form.workCenterId,
  524. workCenterName: this.form.workCenterName,
  525. workOrderId: this.current.id,
  526. dispatchMethod: 0,
  527. dispatchingMethod: this.form.taskAss,
  528. assignType: this.form.assignType,
  529. singleReport: this.form.singleReport,
  530. assignees
  531. };
  532. // 先判断是否派单过 有的话直接用前面派单的 类型数据 否则就是自己选择的数据
  533. if (this.isDispatchRow.hasExists) {
  534. data.dispatchType = this.isDispatchRow.dispatchType;
  535. } else {
  536. let singFlag = this.singleReportRadio();
  537. if (!singFlag) return;
  538. data.dispatchType = this.form.singleReport;
  539. }
  540. }
  541. this.toolbarLoading = true;
  542. try {
  543. if (!(await this.validateDispatchSourceConflict(data, type))) {
  544. this.toolbarLoading = false;
  545. return;
  546. }
  547. } catch (err) {
  548. this.toolbarLoading = false;
  549. this.$message.error(err.message);
  550. return;
  551. }
  552. const api =
  553. type == 1 ? taskAssignment : type == 2 ? taskRevoked : taskSave;
  554. api(data)
  555. .then((res) => {
  556. this.toolbarLoading = false;
  557. if (res) {
  558. this.$message.success('操作成功');
  559. // 更改当前表格数据
  560. this.setCurrentTab(row);
  561. // 查询是否派单
  562. this.queryCheckExists();
  563. }
  564. })
  565. .catch((err) => {
  566. this.toolbarLoading = false;
  567. this.$message.error(err.message);
  568. });
  569. },
  570. //添加工位
  571. addStation(item, index) {
  572. console.log(item, index);
  573. this.$refs.chooseStationRef.open(
  574. this.form.workCenterId,
  575. item.list,
  576. index,
  577. 2,
  578. this.form.teamId
  579. );
  580. },
  581. chooseStationList(list, index) {
  582. const process = this.processList?.[index];
  583. if (!process) {
  584. console.warn(`processList[${index}] 不存在`);
  585. return;
  586. }
  587. const oldList = structuredClone(
  588. Array.isArray(process.list) ? process.list : []
  589. );
  590. list.forEach((item) => {
  591. item.isNew = 1;
  592. item.assetCode = item.extInfo.assetCode;
  593. item.assetId = item.extInfo.assetId;
  594. item.assetName = item.extInfo.assetName;
  595. });
  596. console.log(list, '选择的工位数据');
  597. const newList = structuredClone(Array.isArray(list) ? list : []);
  598. this.$set(this.processList[index], 'list', [...oldList, ...newList]);
  599. },
  600. hasUndeliveredDispatchTask() {
  601. if (!Array.isArray(this.processList)) {
  602. return false;
  603. }
  604. return this.processList.some((process) =>
  605. (process.list || []).some(
  606. (row) => row?.status && Number(row.status.code) === 1
  607. )
  608. );
  609. },
  610. closeDispatchDialog(done) {
  611. this.$emit('update:dispatchVisible', false);
  612. if (typeof done === 'function') {
  613. done();
  614. }
  615. },
  616. cancel(done) {
  617. if (!this.hasUndeliveredDispatchTask()) {
  618. this.closeDispatchDialog(done);
  619. return;
  620. }
  621. this.$confirm('当前存在已派单但未下发的任务,是否仍要退出?', '提示', {
  622. type: 'warning',
  623. confirmButtonText: '确定',
  624. cancelButtonText: '取消'
  625. })
  626. .then(() => {
  627. this.closeDispatchDialog(done);
  628. })
  629. .catch(() => {});
  630. },
  631. // 按钮操作成功后 更改当前的表格数据
  632. setCurrentTab(row) {
  633. let arr = [];
  634. if (row.assignType == 1) {
  635. arr = this.stationList;
  636. } else if (row.assignType == 2) {
  637. arr = this.crewList;
  638. } else {
  639. arr = this.productionList;
  640. }
  641. this.getAssignData(row.index, arr);
  642. },
  643. singleReportRadio() {
  644. if (this.form.singleReport === 0 || this.form.singleReport === 1) {
  645. return true;
  646. }
  647. this.$message.warning('请先选择报工类型');
  648. return false;
  649. },
  650. async validateDispatchSourceConflict(data, type) {
  651. const actionType = Number(type);
  652. if (actionType !== 1 && actionType !== 3) {
  653. return true;
  654. }
  655. const checked = await checkAssignSourceType(data);
  656. const checkedResult =
  657. checked && typeof checked === 'object' ? checked.result : checked;
  658. const checkedMessage =
  659. checked && typeof checked === 'object' ? checked.message : '';
  660. if (checkedResult === true) {
  661. this.$message.warning(
  662. checkedMessage || '当前派单数据存在冲突,请调整后再操作'
  663. );
  664. }
  665. return true;
  666. },
  667. // 最后提交
  668. async confirm() {
  669. let flag = this.singleReportRadio();
  670. if (!flag) return;
  671. // if (!this.form.singleReport) {
  672. // }
  673. if (!this.form.teamId) {
  674. this.$message.warning('请先选择班组');
  675. return;
  676. }
  677. let permissionRes = await parameterGetByCode({
  678. code: 'production_order_dispatch_permission'
  679. });
  680. this.processingRequired = permissionRes.value || 0; // 兜底:若接口返回空,默认设为 0
  681. console.log(this.processingRequired);
  682. if (this.processingRequired == '1') {
  683. try {
  684. const isTeamLeader = await getcheckLoginUserIsTeamLeader(
  685. this.form.teamId
  686. );
  687. if (!isTeamLeader) {
  688. this.toolbarLoading = false;
  689. this.$message.warning('当前班组不是对应组长');
  690. return; // 校验不通过,终止后续流程
  691. }
  692. } catch (err) {
  693. this.toolbarLoading = false;
  694. this.$message.error('校验组长身份失败:' + err.message);
  695. return; // 校验报错,终止后续流程
  696. }
  697. }
  698. if (this.form.taskAss == 1) {
  699. this.issue();
  700. // 按原来的逻辑
  701. return;
  702. }
  703. // 获取到首工序id 的 绑定表格数据
  704. let data = this.processList[this.firstTaskindex];
  705. // 是否进行首工序派单
  706. let isFirstDispatch = false;
  707. let dispatchArr = []; // 已派单数据
  708. data.list.map((item) => {
  709. if (!item.status) {
  710. return;
  711. }
  712. if (item.status.code == 1) {
  713. isFirstDispatch = true;
  714. dispatchArr.push(item.id);
  715. }
  716. });
  717. // 判断是否进行首工序派单
  718. if (!isFirstDispatch) {
  719. this.$message.warning(`请您先进行首工序任务(${data.name}工序)派单`);
  720. this.handleClick({ name: data.id });
  721. return;
  722. }
  723. let totalSum = 0;
  724. // 判断派单的数据 数量相加是否为 要求生产数量
  725. data.list.map((item) => {
  726. if (item.status && item.status.code == 1) {
  727. totalSum += item.quantity - 0;
  728. }
  729. });
  730. // if (totalSum != this.current.formingNum - 0) {
  731. // this.$message.warning(
  732. // `首工序已派单的数据数量相加需要等于要求生产数量${this.current.formingNum}`
  733. // );
  734. // this.handleClick({ name: data.id });
  735. // return;
  736. // }
  737. this.toolbarLoading = true;
  738. let params = {
  739. teamId: this.form.teamId,
  740. workCenterId: this.form.workCenterId,
  741. workOrderId: this.current.id
  742. };
  743. try {
  744. const res = await checkAssignConfirm(params);
  745. if (!res) {
  746. this.toolbarLoading = false;
  747. return;
  748. }
  749. let paramsD = {
  750. assignType: data.assignType,
  751. singleReport: this.form.singleReport,
  752. teamId: this.form.teamId,
  753. dispatchingMethod: this.form.taskAss,
  754. crewIds: data.assignType == 2 ? dispatchArr : [], // 人员 2
  755. workstationIds: data.assignType == 1 ? dispatchArr : [], // 工位 1
  756. factoryLineIds: data.assignType == 3 ? dispatchArr : [], // 产线 3
  757. id: this.current.id,
  758. planStartTime: this.current.planStartTime,
  759. planEndTime: this.current.planEndTime
  760. };
  761. const response = await releaseWorkOrder(paramsD);
  762. this.toolbarLoading = false;
  763. if (response) {
  764. this.$message.success('操作成功');
  765. this.closeDispatchDialog();
  766. this.$emit('createSuccess');
  767. }
  768. } catch (err) {
  769. this.toolbarLoading = false;
  770. // this.$message.error(err.message);
  771. }
  772. },
  773. // 下达
  774. issue() {
  775. if (this.form.assignType == 1) {
  776. if (!this.form.workstationIds || this.form.workstationIds.length == 0) {
  777. this.$message.warning('请选择工位数据');
  778. return;
  779. }
  780. }
  781. if (this.form.assignType == 3) {
  782. if (!this.form.factoryLineIds || this.form.factoryLineIds.length == 0) {
  783. this.$message.warning('请选择产线数据');
  784. return;
  785. }
  786. }
  787. let data = {
  788. assignType: this.form.assignType,
  789. singleReport: this.form.singleReport,
  790. teamId: this.form.teamId,
  791. dispatchingMethod: this.form.taskAss,
  792. crewIds: [],
  793. workstationIds: [],
  794. id: this.current.id,
  795. planStartTime: this.current.planStartTime,
  796. planCompleteTime: this.current.planCompleteTime,
  797. factoryLineIds: []
  798. };
  799. if (this.form.assignType == 1) {
  800. data.workstationIds = this.form.workstationIds || [];
  801. } else if (this.form.assignType == 2) {
  802. data.crewIds = this.form.crewIds || [];
  803. } else {
  804. data.factoryLineIds = this.form.factoryLineIds || [];
  805. }
  806. this.toolbarLoading = true;
  807. releaseWorkOrder(data)
  808. .then((res) => {
  809. this.toolbarLoading = false;
  810. if (res) {
  811. this.$message.success('操作成功');
  812. this.closeDispatchDialog();
  813. this.$emit('createSuccess');
  814. }
  815. })
  816. .catch((err) => {
  817. this.toolbarLoading = false;
  818. // this.$message.error(err.message);
  819. });
  820. },
  821. // 工序选择
  822. async handleClick(tab) {
  823. let id = tab.name;
  824. this.processId = id;
  825. this.isTask = false;
  826. await this.FirstTaskIdFn(id);
  827. let data = this.processList.find((item) => item.id == this.processId);
  828. await this.changeRadio(data.assignType, data.index);
  829. },
  830. // 指派选择
  831. async changeRadio(e, index) {
  832. let data = this.processList[index];
  833. if (e == 1) {
  834. this.dynamicName = '工位名称';
  835. data.assignName = '工位';
  836. await this.getAssignData(index, this.stationList);
  837. } else if (e == 2) {
  838. this.dynamicName = '人员名称';
  839. data.assignName = '人员';
  840. await this.getAssignData(index, this.crewList);
  841. } else {
  842. this.dynamicName = '产线名称';
  843. data.assignName = '产线';
  844. await this.getAssignData(index, this.productionList);
  845. }
  846. },
  847. // 指派数据处理
  848. async getAssignData(index, arr) {
  849. let list = JSON.parse(JSON.stringify(arr));
  850. let dataRow = this.processList[index];
  851. // 不存在 班组数据的话 就不调用这个方法
  852. if (!this.form.teamId) {
  853. return;
  854. }
  855. let params = {
  856. workOrderId: this.current.id,
  857. workCenterId: this.form.workCenterId,
  858. teamId: this.form.teamId,
  859. taskId: dataRow.id
  860. };
  861. this.tabLoading = true;
  862. try {
  863. const res = await listAssign(params);
  864. this.tabLoading = false;
  865. // 如果 res 没有数据 说明未对数据进行操作 直接赋值
  866. if (res.length == 0) {
  867. this.$set(dataRow, 'list', list);
  868. return;
  869. }
  870. // 对有操作过的数据进行赋值
  871. this.operationalData(index, res, list);
  872. } catch (err) {
  873. this.tabLoading = false;
  874. this.$message.warning(err.message);
  875. }
  876. },
  877. // 操作过的数据 赋值
  878. // operationalData(index, res, list) {
  879. // const dataRow = this.processList[index];
  880. // // 键值对存储 当前工序 操作的数据 指派的code(键) 数据(list:值)
  881. // let arrMap = {};
  882. // // 要先判断有没有操作的数据 如果有的话 其它的指派操作置灰
  883. // let codeT = null; // 表示有已操作的数据(对应的 code)
  884. // res[0].assignees.map((el) => {
  885. // let code = el.assigneeType.code;
  886. // if (arrMap[code]) {
  887. // arrMap[code].arr.push(el);
  888. // arrMap[code].bunDis = arrMap[code].bunDis
  889. // ? arrMap[code].bunDis
  890. // : el.status.desc
  891. // ? true
  892. // : false;
  893. // } else {
  894. // arrMap[code] = {
  895. // arr: [el],
  896. // bunDis: el.status.desc ? true : false
  897. // };
  898. // }
  899. // codeT = codeT ? codeT : el.status.desc ? code : '';
  900. // });
  901. // let radioBun = {
  902. // lineDis: false, // 产线 3
  903. // staffDis: false, // 人员 2
  904. // stationDis: false // 工位 1
  905. // };
  906. // // 默认是传递下来的 list 数据 但是如果 codeT有值 说明 工位 人员 产线 有派单数据
  907. // // 需要自动切换过去
  908. // let listArr = list;
  909. // if (codeT) {
  910. // if (codeT == 1) {
  911. // radioBun.staffDis = true;
  912. // radioBun.lineDis = true;
  913. // radioBun.stationDis = false;
  914. // listArr = JSON.parse(JSON.stringify(this.stationList));
  915. // dataRow.assignType = 1;
  916. // dataRow.assignName = '工位';
  917. // } else if (codeT == 2) {
  918. // radioBun.stationDis = true;
  919. // radioBun.lineDis = true;
  920. // radioBun.staffDis = false;
  921. // listArr = JSON.parse(JSON.stringify(this.crewList));
  922. // dataRow.assignType = 2;
  923. // dataRow.assignName = '人员';
  924. // } else {
  925. // radioBun.stationDis = true;
  926. // radioBun.staffDis = true;
  927. // radioBun.lineDis = false;
  928. // listArr = JSON.parse(JSON.stringify(this.productionList));
  929. // dataRow.assignType = 3;
  930. // dataRow.assignName = '产线';
  931. // }
  932. // }
  933. // // 切换完后 对 指派的数组数据进行赋值
  934. // let listMap = {};
  935. // listArr.map((el, index) => (listMap[el.id] = index));
  936. // let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
  937. // dataRow.startDate = ''; // 每次计算的时候清空之前的
  938. // dataRow.endDate = '';
  939. // if (listArr.length == 0) return;
  940. // // listArr.forEach((it) => {
  941. // // if (it.disposalStatus || it.disposalStatus == 0) {
  942. // arrList.map((item) => {
  943. // if (item.assigneeType.code == dataRow.assignType) {
  944. // let idx = listMap[item.assigneeId];
  945. // if (!idx && idx !== 0) {
  946. // return;
  947. // }
  948. // listArr[idx].status = item.status;
  949. // listArr[idx].startTime = item.startTime;
  950. // listArr[idx].endTime = item.endTime;
  951. // listArr[idx].quantity = item.quantity;
  952. // listArr[idx].weight = item.weight;
  953. // listArr[idx].changeId = item.id;
  954. // listArr[idx].teamTimeIds = item.teamTimeIds;
  955. // this.compareAndSetTime(listArr[idx], dataRow);
  956. // this.compareEndSetTime(listArr[idx], dataRow);
  957. // }
  958. // });
  959. // // }
  960. // // });
  961. // // 这里重新调用一个方法 计算出 startDate endDate
  962. // this.$set(dataRow, 'list', listArr);
  963. // this.$set(dataRow, 'radioBun', radioBun);
  964. // this.$set(dataRow, 'selection', []);
  965. // let tab = `tableRef${[dataRow.index]}`;
  966. // this.$refs[tab][0].setSelectedRowKeys([]);
  967. // console.log(dataRow, 'dataRow +++++');
  968. // },
  969. operationalData(index, res, list) {
  970. const dataRow = this.processList[index];
  971. const oldList = structuredClone(
  972. Array.isArray(dataRow.list) ? dataRow.list : []
  973. );
  974. let arrMap = {};
  975. let codeT = null;
  976. res[0].assignees.map((el) => {
  977. let code = el.assigneeType.code;
  978. if (arrMap[code]) {
  979. arrMap[code].arr.push(el);
  980. arrMap[code].bunDis = arrMap[code].bunDis
  981. ? arrMap[code].bunDis
  982. : el.status.desc
  983. ? true
  984. : false;
  985. } else {
  986. arrMap[code] = { arr: [el], bunDis: el.status.desc ? true : false };
  987. }
  988. codeT = codeT ? codeT : el.status.desc ? code : '';
  989. });
  990. let radioBun = { lineDis: false, staffDis: false, stationDis: false };
  991. let listArr = list;
  992. if (codeT) {
  993. if (codeT == 1) {
  994. radioBun.staffDis = true;
  995. radioBun.lineDis = true;
  996. radioBun.stationDis = false;
  997. listArr = JSON.parse(JSON.stringify(this.stationList));
  998. dataRow.assignType = 1;
  999. dataRow.assignName = '工位';
  1000. } else if (codeT == 2) {
  1001. radioBun.stationDis = true;
  1002. radioBun.lineDis = true;
  1003. radioBun.staffDis = false;
  1004. listArr = JSON.parse(JSON.stringify(this.crewList));
  1005. dataRow.assignType = 2;
  1006. dataRow.assignName = '人员';
  1007. } else {
  1008. radioBun.stationDis = true;
  1009. radioBun.staffDis = true;
  1010. radioBun.lineDis = false;
  1011. listArr = JSON.parse(JSON.stringify(this.productionList));
  1012. dataRow.assignType = 3;
  1013. dataRow.assignName = '产线';
  1014. }
  1015. }
  1016. if (Number(dataRow.assignType) === 1) {
  1017. listArr = this.mergeAddedStationRows(oldList, listArr);
  1018. }
  1019. let listMap = {};
  1020. listArr.map((el, idx) => (listMap[el.id] = idx));
  1021. let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
  1022. dataRow.startDate = '';
  1023. dataRow.endDate = '';
  1024. arrList.map((item) => {
  1025. if (item.assigneeType.code == dataRow.assignType) {
  1026. let idx = listMap[item.assigneeId];
  1027. if (!idx && idx !== 0) return;
  1028. listArr[idx].status = item.status;
  1029. listArr[idx].startTime = item.startTime;
  1030. listArr[idx].endTime = item.endTime;
  1031. listArr[idx].quantity = item.quantity;
  1032. listArr[idx].weight = item.weight;
  1033. listArr[idx].changeId = item.id;
  1034. listArr[idx].teamTimeIds = item.teamTimeIds;
  1035. this.compareAndSetTime(listArr[idx], dataRow);
  1036. this.compareEndSetTime(listArr[idx], dataRow);
  1037. }
  1038. });
  1039. // ====== 修复:合并新增工位 ======
  1040. const finalList = this.mergeNewRows(oldList, listArr);
  1041. this.$set(dataRow, 'list', finalList);
  1042. this.$set(dataRow, 'radioBun', radioBun);
  1043. this.$set(dataRow, 'selection', []);
  1044. // let tab = `tableRef${[dataRow.index]}`;
  1045. // this.$refs[tab][0].setSelectedRowKeys([]);
  1046. this.$nextTick(() => {
  1047. const tab = `tableRef${dataRow.index}`;
  1048. const tableRefs = this.$refs[tab];
  1049. if (!tableRefs || !tableRefs[0]) {
  1050. console.warn(`table ref ${tab} not ready`);
  1051. return;
  1052. }
  1053. tableRefs[0].setSelectedRowKeys([]);
  1054. });
  1055. },
  1056. mergeAddedStationRows(oldList, newList) {
  1057. const existIds = new Set((newList || []).map((i) => i.id));
  1058. const addedRows = (oldList || []).filter(
  1059. (i) => i.isNew === 1 && !existIds.has(i.id)
  1060. );
  1061. return [...newList, ...addedRows];
  1062. },
  1063. mergeNewRows(oldList, newList) {
  1064. const existIds = new Set(newList.map((i) => i.id));
  1065. const tempRows = oldList.filter(
  1066. (i) => i.isNew === 1 && !i.changeId && !existIds.has(i.id)
  1067. );
  1068. return [...newList, ...tempRows];
  1069. },
  1070. // 省略时间校验、派单、重置、数量重量处理、班次选择等方法
  1071. // 可以保留原本的逻辑
  1072. // 时间比较与赋值方法 开始时间
  1073. compareAndSetTime(data, dataRow) {
  1074. // 如果startDate为空,直接赋值为startTime
  1075. if (!dataRow.startDate) {
  1076. dataRow.startDate = data['startTime'];
  1077. return;
  1078. }
  1079. // 转换为Date对象进行比较
  1080. const startTimeDate = new Date(data['startTime']);
  1081. const startDateDate = new Date(dataRow.startDate);
  1082. // 比较时间(getTime()获取时间戳)
  1083. if (startTimeDate.getTime() < startDateDate.getTime()) {
  1084. dataRow.startDate = data['startTime'];
  1085. }
  1086. },
  1087. // 时间比较与赋值方法 结束时间时间
  1088. compareEndSetTime(data, dataRow) {
  1089. // 如果startDate为空,直接赋值为endTime
  1090. if (!dataRow.endDate) {
  1091. dataRow.endDate = data['endTime'];
  1092. return;
  1093. }
  1094. // 转换为Date对象进行比较
  1095. const endTimeDate = new Date(data['endTime']);
  1096. const endDateDate = new Date(dataRow.endDate);
  1097. // 比较时间(getTime()获取时间戳)
  1098. if (endTimeDate.getTime() > endDateDate.getTime()) {
  1099. dataRow.endDate = data['endTime'];
  1100. }
  1101. },
  1102. assignRadio(e) {},
  1103. // 数量正则 quantity
  1104. handleQuantityInput(e, row, item) {
  1105. // 过滤非数字字符(包括负号)
  1106. let value = e.replace(/[^\d]/g, '');
  1107. // 限制不能以 0 开头(除非是 0 本身)
  1108. if (value.startsWith('0') && value.length > 1) {
  1109. value = value.slice(1);
  1110. }
  1111. // 更新绑定值
  1112. row.quantity = value;
  1113. this.calculateQuantity(row, item);
  1114. this.bringWeight(row.quantity, row);
  1115. this.selectedListData(row, item);
  1116. },
  1117. // 自动算重量
  1118. bringWeight(value, row) {
  1119. if (!this.current.formingWeight) {
  1120. this.$set(row, 'weight', 0);
  1121. return;
  1122. }
  1123. let weight =
  1124. (this.current.formingWeight / this.current.formingNum) * value;
  1125. if (weight > 0) {
  1126. weight = weight.toFixed(4) - 0;
  1127. }
  1128. this.$set(row, 'weight', weight);
  1129. },
  1130. calculateQuantity(row, item) {
  1131. // 如果没有该字段 就不做判断
  1132. if (!this.current.formingNum) {
  1133. return;
  1134. }
  1135. let total = 0;
  1136. item.list.forEach((el) => {
  1137. if (el.quantity) {
  1138. total = total + (el.quantity - 0);
  1139. }
  1140. });
  1141. if (total > this.current.formingNum - 0) {
  1142. this.$message.warning('列表数量相加不能大于目标要求生产数量');
  1143. row.quantity = 0;
  1144. }
  1145. },
  1146. // 计算重量
  1147. calculateWeight(row, item) {
  1148. // 如果没有该字段 就不做判断
  1149. if (!this.current.formingWeight) {
  1150. return;
  1151. }
  1152. let total = 0;
  1153. item.list.forEach((el) => {
  1154. if (el.weight) {
  1155. total = total + (el.weight - 0);
  1156. }
  1157. });
  1158. if (total > this.current.formingWeight - 0) {
  1159. this.$message.warning('列表数量相加不能大于目标要求生产数量');
  1160. row.weight = 0;
  1161. }
  1162. },
  1163. // 重量正则 weight
  1164. handleWeightInput(e, row, item) {
  1165. // 过滤非数字和非小数点字符(包括负号)
  1166. let value = e.replace(/[-+^\d.]/g, '');
  1167. value = e.replace(/[^\d.]/g, '');
  1168. // 限制只能有一个小数点
  1169. const dotCount = (value.match(/\./g) || []).length;
  1170. if (dotCount > 1) {
  1171. value = value.slice(0, value.lastIndexOf('.'));
  1172. }
  1173. // 限制不能以小数点开头
  1174. if (value.startsWith('.')) {
  1175. value = '0' + value;
  1176. }
  1177. // 更新绑定值
  1178. row.weight = value;
  1179. this.calculateWeight(row, item);
  1180. this.selectedListData(row, item);
  1181. },
  1182. // 选中班次
  1183. shiftSelection(e, row, item) {
  1184. // this.$refs.tableRef0[0].setSelectedRowKeys(row.id);
  1185. // let data = this.shiftList.find((item) => item.id == e);
  1186. // this.selectedListData(row, item);
  1187. let data = this.shifTimeData(e, row);
  1188. let startTime = `${this.dateValue} ${data.startTime}` + `:00`;
  1189. let endTime = `${this.dateValue} ${data.endTime}` + `:00`;
  1190. this.$set(row, 'startTime', startTime);
  1191. this.$set(row, 'endTime', endTime);
  1192. this.handleStartTimeChange(row, item);
  1193. this.handleEndTimeChange(row, item);
  1194. },
  1195. // 默认选中当前更改数据
  1196. selectedListData(row, item) {
  1197. let data = item.selection.find((el) => el.id == row.id);
  1198. if (!data) {
  1199. let ids = item.selection.map((el) => el.id);
  1200. ids.push(row.id);
  1201. let tab = `tableRef${[item.index]}`;
  1202. this.$refs[tab][0].setSelectedRowKeys(ids);
  1203. }
  1204. },
  1205. // 多选班次时间数据
  1206. shifTimeData(e, row) {
  1207. if (!e || e.length == 0) {
  1208. return {
  1209. startTime: row.startTime,
  1210. endTime: row.endTime
  1211. };
  1212. }
  1213. let startTime = '';
  1214. let endTime = '';
  1215. e.map((el) => {
  1216. let obj = this.shiftList.find((item) => item.id == el);
  1217. if (!startTime) {
  1218. startTime = obj.startTime;
  1219. }
  1220. if (!endTime) {
  1221. endTime = obj.endTime;
  1222. }
  1223. // 获取更小的
  1224. startTime =
  1225. this.compareTime(startTime, obj.startTime) !== -1
  1226. ? obj.startTime
  1227. : startTime;
  1228. // 获取更大的
  1229. endTime =
  1230. this.compareTime(endTime, obj.endTime) !== 1 ? obj.endTime : endTime;
  1231. });
  1232. return {
  1233. startTime,
  1234. endTime
  1235. };
  1236. },
  1237. // 将HH:mm:ss格式的时间转换为总秒数
  1238. timeToSeconds(timeStr) {
  1239. const [hours, minutes, seconds] = timeStr.split(':').map(Number);
  1240. return hours * 3600 + minutes * 60 + seconds;
  1241. },
  1242. // this.$refs.table.setSelectedRowKeys(ids);
  1243. // 比较两个时间的大小
  1244. compareTime(time1, time2) {
  1245. const sec1 = this.timeToSeconds(time1);
  1246. const sec2 = this.timeToSeconds(time2);
  1247. if (sec1 > sec2) {
  1248. return 1; // time1 更大
  1249. } else if (sec1 < sec2) {
  1250. return -1; // time2 更大
  1251. } else {
  1252. return 0; // 两个时间相等
  1253. }
  1254. },
  1255. // 【开始时间变化时】触发
  1256. handleStartTimeChange(row, item) {
  1257. if (!row.startTime) {
  1258. return;
  1259. }
  1260. if (!this.checkPlanTimeRange(row, 'startTime', '计划开始时间')) {
  1261. return;
  1262. }
  1263. this.selectedListData(row, item);
  1264. // 这一道工序的开始时间 不能小于前一道工序的结束时间
  1265. const startTime = new Date(row.startTime); // 开始时间
  1266. if (item.index !== 0) {
  1267. // let frontIdx = item.index - 1;
  1268. let frontIdx = this.calculateIndex(item.index).startIdx;
  1269. if (frontIdx !== 'none') {
  1270. let frontName = this.processList[frontIdx].name;
  1271. let time = this.processList[frontIdx].endDate;
  1272. const frontTime = new Date(time); // 前面工序的结束时间
  1273. if (time && startTime < frontTime) {
  1274. this.$message.closeAll();
  1275. this.$message.info(
  1276. `开始时间不能小于前面工序${frontName}的结束时间${time}`
  1277. );
  1278. // 判断是否 配置时间更改规则
  1279. if (this.time_calc_code == '1') {
  1280. row.startTime = time;
  1281. }
  1282. return;
  1283. }
  1284. }
  1285. }
  1286. // 这一道工序的开始时间更不能大于后一道工序的开始时间
  1287. if (item.index !== this.processList.length - 1) {
  1288. // let latterIdx = item.index + 1;
  1289. let latterIdx = this.calculateIndex(item.index).endIdx;
  1290. if (latterIdx !== 'none') {
  1291. let time = this.processList[latterIdx].startDate;
  1292. let latterName = this.processList[latterIdx].name;
  1293. const latterTime = new Date(time); // 下一道工序的结束时间
  1294. if (time && startTime > latterTime) {
  1295. this.$message.closeAll();
  1296. this.$message.info(
  1297. `开始时间不能大于后面工序${latterName}的开始时间${time}`
  1298. );
  1299. // 判断是否 配置时间更改规则
  1300. if (this.time_calc_code == '1') {
  1301. row.startTime = '';
  1302. }
  1303. return;
  1304. }
  1305. }
  1306. }
  1307. // 校验 是否 大于结束时间 wda
  1308. this.checkEndTimeValid(row);
  1309. },
  1310. // 当更改一个工序开始时间 结束时间的时候
  1311. // 开始时间 不能小于之前工序的结束时间 ( 要先去上一道工序找 是否存在结束时间 不存在就再往前找 直到 第一道工序 )
  1312. // 结束时间 不能大于后面工序的开始时间 ( 要先去后一道工序找 是否存在开始时间 不存在就再往后找 直到 最后一道工序 )
  1313. // 计算出当前下标数据 的前后 有 开始时间 结束时间的数据下标
  1314. calculateIndex(index) {
  1315. let startIdx = 'none';
  1316. let endIdx = 'none';
  1317. // 前面工序下标
  1318. for (let i = index - 1; i >= 0; i--) {
  1319. let row = this.processList[i];
  1320. if (row && row.endDate) {
  1321. startIdx = i;
  1322. break;
  1323. }
  1324. }
  1325. // 后面工序的下标
  1326. for (let i = index + 1; i <= this.processList.length; i++) {
  1327. let row = this.processList[i];
  1328. if (row && row.startDate) {
  1329. endIdx = i;
  1330. break;
  1331. }
  1332. }
  1333. return {
  1334. startIdx,
  1335. endIdx
  1336. };
  1337. },
  1338. // 【结束时间变化时】触发
  1339. handleEndTimeChange(row, item) {
  1340. if (!row.endTime) {
  1341. return;
  1342. }
  1343. if (!this.checkPlanTimeRange(row, 'endTime', '计划完成时间')) {
  1344. return;
  1345. }
  1346. this.selectedListData(row, item);
  1347. const endTime = new Date(row.endTime); // 结束时间
  1348. // 当前工序的结束时间 不能大于后一道工序的开始时间
  1349. if (item.index !== this.processList.length - 1) {
  1350. let latterIdx = this.calculateIndex(item.index).endIdx;
  1351. if (latterIdx !== 'none') {
  1352. let latterName = this.processList[latterIdx].name;
  1353. let time = this.processList[latterIdx].startDate;
  1354. const latterTime = new Date(time); // 后面工序的开始时间
  1355. if (time && endTime > latterTime) {
  1356. this.$message.closeAll();
  1357. this.$message.info(
  1358. `结束时间不能大于后面工序${latterName}的开始时间${time}`
  1359. );
  1360. // 判断是否 配置时间更改规则
  1361. if (this.time_calc_code == '1') {
  1362. row.endTime = time;
  1363. }
  1364. return;
  1365. }
  1366. }
  1367. }
  1368. // 这一道工序的开始时间更不能小于于前一道工序的结束时间
  1369. if (item.index !== 0) {
  1370. let frontIdx = this.calculateIndex(item.index).startIdx;
  1371. if (frontIdx !== 'none') {
  1372. let frontName = this.processList[frontIdx].name;
  1373. let time = this.processList[frontIdx].endDate;
  1374. const frontTime = new Date(time); // 上一道工序的结束时间
  1375. if (time && endTime < frontTime) {
  1376. this.$message.closeAll();
  1377. this.$message.info(
  1378. `结束时间不能小于前面工序${frontName}的结束时间${time}`
  1379. );
  1380. // 判断是否 配置时间更改规则
  1381. if (this.time_calc_code == '1') {
  1382. row.endTime = '';
  1383. }
  1384. return;
  1385. }
  1386. }
  1387. }
  1388. this.checkEndTimeValid(row, item);
  1389. },
  1390. // 校验时间是否在生产计划范围内,不符合则提示并清空当前字段
  1391. checkPlanTimeRange(row, field, label) {
  1392. const currentTime = row[field];
  1393. if (!currentTime) return true;
  1394. const { planStartTime, planCompleteTime } = this.current || {};
  1395. const chooseTime = new Date(currentTime);
  1396. if (planStartTime && chooseTime < new Date(planStartTime)) {
  1397. this.$message.closeAll();
  1398. this.$message.info(`${label}不能小于计划开始时间${planStartTime}`);
  1399. row[field] = '';
  1400. return false;
  1401. }
  1402. if (planCompleteTime && chooseTime > new Date(planCompleteTime)) {
  1403. this.$message.closeAll();
  1404. this.$message.info(`${label}不能大于计划结束时间${planCompleteTime}`);
  1405. row[field] = '';
  1406. return false;
  1407. }
  1408. return true;
  1409. },
  1410. // 时间校验
  1411. checkEndTimeValid(row) {
  1412. const { startTime: start, endTime: end } = row;
  1413. if (!start || !end) return;
  1414. const startTime = new Date(start); // 开始时间
  1415. const endTime = new Date(end); // 结束时间
  1416. if (endTime < startTime) {
  1417. row.endTime = '';
  1418. this.$message.closeAll();
  1419. this.$message.info('计划完成时间不能小于计划开始时间');
  1420. }
  1421. }
  1422. }
  1423. };