release.js 39 KB

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