release.js 37 KB

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