| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474 |
- import {
- listByFirstTaskId,
- listUserByIds,
- listWorkCenter,
- listByWorkCenter,
- lineByCurrentUser,
- taskSave,
- taskRevoked,
- taskAssignment,
- listAssign,
- checkAssignConfirm,
- checkAssignSourceType,
- resetAssignee,
- listByRoutingIds,
- listByFactoryId,
- checkExists,
- parameterGetByCode
- } from '@/api/mainData/index.js';
- import {
- releaseWorkOrder,
- getcheckLoginUserIsTeamLeader,
- getUserInfo
- } from '@/api/workOrder/index.js';
- // import { }
- export default {
- data() {
- return {
- isTpye: ''
- };
- },
- created() {
- // console.log('组件传入的选项:', this.$options.mixinOptions);
- this.isTpye = this.$options.mixinOptions.type;
- },
- methods: {
- // 查询班次
- getClassesData() {
- if (!this.current.factoriesId) return;
- listByFactoryId(this.current.factoriesId).then((res) => {
- if (!res) return;
- this.shiftList = res;
- });
- },
- // 查询是否派单
- queryCheckExists() {
- let params = {
- workOrderId: this.current.id,
- workCenterId: 123,
- teamId: 345
- };
- checkExists(params)
- .then((res) => {
- if (!res) return;
- this.isDispatchRow = res;
- if (res.hasExists) {
- this.form.taskAss = 0;
- this.orderDis = true;
- this.procTaskDis = false;
- // 报工类型 判断
- this.form.singleReport = res.dispatchType;
- if (res.dispatchType == 1) {
- this.batchDis = true;
- this.singleDis = false;
- } else {
- this.singleDis = true;
- this.batchDis = false;
- }
- } else {
- this.batchDis = false;
- this.singleDis = false;
- this.orderDis = false;
- this.procTaskDis = false;
- }
- })
- .catch((err) => {
- this.$message.error(err.message);
- });
- },
- // 获取当前年月日
- getFormattedDate() {
- const now = new Date();
- const year = now.getFullYear();
- const month = String(now.getMonth() + 1).padStart(2, '0');
- const date = String(now.getDate()).padStart(2, '0');
- return `${year}-${month}-${date}`;
- },
- // 查询工作中心
- async workCenterData() {
- // 判断是否存在工序id 有的话就取否则取首工序id
- console.log(this.current, 'this.current 查询工作中心');
- let id = '';
- if (!this.current.taskId || this.current.taskId < 0) {
- id = this.current.firstTaskId;
- } else {
- id = this.current.taskId;
- }
- if (this.current?.factoryName) {
- this.form.factoryName = this.current.factoryName;
- }
- // this.current.taskId || this.current.firstTaskId;
- const res = await listWorkCenter(id);
- console.log(res, 'ressss');
- const userData = await getUserInfo(this.$store.state.user.info.userId);
- this.workCenterList = res;
- if (res.length > 0) {
- // this.form.factoryName = res[0].factoryName;
- this.form.workCenterId = res[0].id;
- if (this.isTpye == 'add') {
- if (userData.centerList.length == 0) {
- this.form.isDisable = true;
- return this.$message.warning(
- `当前登录人没有配置所属中心,请先去主数据给该登录人配置所属中心`
- );
- }
- if (userData.centerList.length != 0) {
- // centerId
- if (res.length != 0) {
- const data = userData.centerList.filter(
- (it) => it.centerId == res[0].id
- );
- if (data.length == 0) {
- this.form.isDisable = true;
- return this.$message.warning(`当前登录人没有权限给该工单派单`);
- }
- }
- }
- }
- // 查首工序
- await this.changeWork(res[0].id); // 选择工作中心
- this.getProductionData(res[0].id); // 查询产线
- this.FirstTaskIdFn(); // 查询工位数据
- } else {
- this.$message.warning(
- // `${this.current.firstTaskName}工序没有工作中心,请到主数据工序管理维护工序信息!`
- `当前登录人不属于首工序所属工作中心及班组,请切换首工序${this.current.firstTaskName}所在的班组成员派单`
- );
- }
- },
- // 查询工序列表数据
- changeDispatch(e) {
- this.tabsLoading = true;
- // listByWorkCenter(this.form.workCenterId)
- listByRoutingIds([this.current.produceRoutingId])
- .then((res) => {
- this.tabsLoading = false;
- // 如果没有首工序的数据 就不能选择工序任务派单
- if (!res || res.length == 0) {
- this.processList = [];
- this.form.taskAss = 1;
- this.procTaskDis = true;
- return;
- }
- this.procTaskDis = false;
- let list = [];
- let isExist = false;
- let firstTaskindex = '';
- res.forEach((item, index) => {
- isExist = isExist
- ? isExist
- : item.sourceTaskId === this.current.firstTaskId;
- // 如果有首工序id 存储它的下标
- if (isExist) {
- if (!firstTaskindex && firstTaskindex !== 0) {
- firstTaskindex = index;
- }
- }
- let obj = {
- id: item.sourceTaskId, //工序 id
- name: item.name, //工序 名称
- assignType: 1, // 默认的指派数据
- assignName: '工位', // 默认指派数据名称
- list: [], // 当前工序下面的指派 绑定的表格
- selection: [], // 当前工序下面的指派 选中的数据f
- code: item.code, // 工序 编码
- index: index, // 当前工序数据的下标
- radioBun: {
- // 指派按钮的操作状态 绑定 默认false(可操作)
- stationDis: false, // 工位按钮
- staffDis: false, // 人员按钮
- lineDis: false // 产线按钮
- },
- isDisable:
- this.form.workCenterId == item.workCenterId ? true : false,
- startDate: '', // 开始日期 (当前工序中最早的计划开始时间)
- endDate: '', // 结束日期 (当前工序中最晚的计划结束时间)
- workCenterId: item.workCenterId,
- workCenterName: item.workCenterName
- };
- list.push(obj);
- });
- this.firstTaskindex = firstTaskindex;
- // 存在首工序报工
- if (isExist) {
- this.processList = list;
- this.processId = res[0].sourceTaskId;
- // this.handleClick({ name: res[0].sourceTaskId });
- this.initializeQuery();
- } else {
- this.processList = [];
- this.form.taskAss = 1;
- this.procTaskDis = true;
- this.$message.warning('当前任务没有首工序报工');
- }
- })
- .catch((err) => {
- this.processList = [];
- this.tabsLoading = false;
- this.$message.error(err.message);
- });
- },
- // 初始化查询 查询全部工序操作过的数据
- async initializeQuery() {
- try {
- // 不存在 班组数据的话 就不调用这个方法
- if (!this.form.teamId) {
- return;
- }
- let params = {
- workOrderId: this.current.id,
- workCenterId: this.form.workCenterId,
- teamId: this.form.teamId
- };
- let processMap = {};
- this.processList.map((el, index) => (processMap[el.id] = index));
- console.log(this.processList, 'processMap');
- const res = await listAssign(params);
- let isFirstData = false; // 判断默认第一道工序是否操作过
- if (res && res.length > 0) {
- res.map((el) => {
- let index = processMap[el.taskId];
- if (index === 0 && el.assignees && el.assignees.length > 0) {
- isFirstData = true; // 操作过
- }
- // 这里第三个参数传空数组就好了 会自动计算的
- setTimeout(() => {
- this.operationalData(index, [el], []);
- });
- });
- // 没有操作过 默认获取一下表格数据
- if (!isFirstData) {
- this.handleClick({ name: this.processId });
- }
- } else {
- this.handleClick({ name: this.processId });
- }
- console.log(this.processList, '工序列表');
- } catch (err) {}
- },
- // 选择工作中心
- async changeWork(e) {
- this.form.workCenterId = e;
- // this.changeDispatch(); // 查询工序列表
- let data = this.workCenterList.find((item) => item.id == e);
- this.form.workCenterName = data.name;
- this.teamList = data.teamList || []; // 重新获取 班组数据
- if (this.teamList.length > 0) {
- this.form.teamId = this.teamList[0].id;
- await this.changeGroups(this.teamList[0].id); // 获取人员数据方法
- } else {
- // 如果没有 班组数据 将人员数据清空 并且判断
- this.crewList = [];
- this.form.teamId = '';
- this.setTeamLeaderName(null); // 清空班组长
- let data = this.processList.find((item) => item.id == this.processId);
- if (data.assignType == 2) {
- this.$set(data, 'list', []);
- }
- }
- },
- // 设置班组长显示 (班组数据里的 leaderUserName)
- setTeamLeaderName(team) {
- this.$set(
- this.form,
- 'leaderUserName',
- (team && team.leaderUserName) || ''
- );
- this.$set(this.form, 'leaderUserId', (team && team.leaderUserId) || '');
- },
- // 选择班组 查询人员的数据
- async changeGroups(e) {
- let data = this.teamList.find((item) => item.id == e);
- this.form.teamName = data.name;
- this.setTeamLeaderName(data); // 显示班组长
- try {
- const res = await listUserByIds([e]);
- this.crewList = res;
- // 查看当前的工序数据是不是 选择的人员 是的话同步更改
- if (!this.processId || this.processId == 0) {
- return;
- }
- this.handleClick({ name: this.processId });
- this.btnInit();
- } catch {
- this.crewList = [];
- }
- },
- // 工序按钮初始化
- btnInit() {
- let data = this.processList.find((item) => item.id == this.processId);
- this.$set(data.radioBun, 'lineDis', false);
- this.$set(data.radioBun, 'staffDis', false);
- this.$set(data.radioBun, 'stationDis', false);
- this.$set(data, 'assignName', '工位');
- this.$set(data, 'assignType', 1);
- },
- // 获取产线数据
- async getProductionData() {
- const res = await lineByCurrentUser(this.form.workCenterId);
- this.productionList =
- res &&
- res.map((el) => {
- return {
- name: el.name,
- code: el.code,
- id: el.id
- };
- });
- },
- // 查询工位数据
- async FirstTaskIdFn(taskId) {
- console.log(taskId, 'taskId 查询工位数据');
- console.log(this.current, 'this.current 查询工位数据');
- // let id = this.current.taskId || this.current.firstTaskId;
- let id = '';
- if (this.isTpye == 'detail') {
- id = this.current.firstTaskId;
- } else {
- if (!this.current.taskId || this.current.taskId < 0) {
- id = this.current.firstTaskId;
- } else {
- id = this.current.taskId;
- }
- }
- await listByFirstTaskId(taskId ? taskId : id)
- .then((res) => {
- this.stationList = res;
- this.stationList.forEach((item, index) => {
- let substance = item.workstationSubstanceList[0]?.substance;
- if (substance) {
- this.$set(this.stationList[index], 'assetName', substance.name);
- this.$set(this.stationList[index], 'assetCode', substance.code);
- this.$set(
- this.stationList[index],
- 'assetModelType',
- substance.category?.category?.modelType
- );
- this.$set(
- this.stationList[index],
- 'assetCategoryLevelPath',
- substance.category?.category?.categoryLevelPath?.split('-')[0]
- );
- }
- });
- console.log(this.stationList, '5522200');
- console.log(this.isTask, '88555');
- if (this.isTask) {
- this.changeDispatch();
- }
- })
- .catch((err) => {
- this.stationList = [];
- this.$message.error(err.message);
- });
- },
- canDeleteAddedStation(row) {
- const statusCode = Number(row?.status?.code);
- return row?.isNew === 1 && statusCode !== 0 && statusCode !== 1;
- },
- refreshProcessDateRange(item) {
- this.$set(item, 'startDate', '');
- this.$set(item, 'endDate', '');
- const list = Array.isArray(item?.list) ? item.list : [];
- list.forEach((row) => {
- if (row.startTime) {
- this.compareAndSetTime(row, item);
- }
- if (row.endTime) {
- this.compareEndSetTime(row, item);
- }
- });
- },
- deleteRow(row, item) {
- if (!this.canDeleteAddedStation(row)) {
- return this.$message.warning(
- '只有通过添加工位新增且状态不是保存或派单的数据才能删除'
- );
- }
- const list = Array.isArray(item?.list) ? item.list : [];
- const nextList = list.filter((it) => it.id !== row.id);
- const nextSelection = Array.isArray(item?.selection)
- ? item.selection.filter((it) => it.id !== row.id)
- : [];
- this.$set(item, 'list', nextList);
- this.$set(item, 'selection', nextSelection);
- this.refreshProcessDateRange(item);
- this.$nextTick(() => {
- const tab = `tableRef${item.index}`;
- const tableRefs = this.$refs[tab];
- if (!tableRefs || !tableRefs[0]) {
- return;
- }
- tableRefs[0].setSelectedRowKeys(nextSelection.map((it) => it.id));
- });
- this.$message.success('删除成功');
- },
- applyResetViewState(row, item) {
- const list = Array.isArray(item?.list) ? item.list : [];
- const target = list.find((it) => it.id === row.id);
- if (!target) {
- return false;
- }
- this.$set(target, 'status', null);
- this.$set(target, 'changeId', '');
- return true;
- },
- // 重置(单个)
- resetData(row, item) {
- if (!row.changeId) {
- return this.$message.warning('只能对已撤回跟已保存的数据进行重置');
- }
- this.toolbarLoading = true;
- resetAssignee(row.changeId)
- .then((res) => {
- this.toolbarLoading = false;
- if (res) {
- this.$message.success('操作成功');
- if (row.isNew === 1 && this.applyResetViewState(row, item)) {
- return;
- }
- // 更改当前表格数据
- this.setCurrentTab(item);
- }
- })
- .catch((err) => {
- this.toolbarLoading = false;
- this.$message.error(err.message);
- });
- },
- // 撤回的逻辑
- getWithdrawT(row, type) {
- if (type != 2) {
- return true;
- }
- let isFlag = true;
- row.selection.forEach((item) => {
- if (!item.status) {
- isFlag = false;
- return;
- }
- if (!item.status.code) {
- isFlag = false;
- }
- });
- return isFlag;
- },
- // 派单
- async dispatch(row, type) {
- console.log(row, 'row 333');
- console.log(type, 'type');
- if (row.selection.length == 0) {
- return this.$message.warning('请最少选择一条数据');
- }
- let isWithdraw = this.getWithdrawT(row, type);
- if (!isWithdraw) {
- this.$message.warning('只有状态为派单的数据才能进行撤回');
- return;
- }
- let assignees = [];
- let changeIds = [];
- let flag = true; // 是否填写 校验
- console.log(row.selection, '选中的数据');
- row.selection.forEach((item) => {
- if (!item.quantity || !item.startTime || !item.endTime) {
- flag = false;
- return;
- }
- if (item.quantity == 0) {
- this.$message.warning('请检查所选数据的数量不能为0');
- digit = false;
- return;
- }
- console.log(item, '数据');
- let Aobj = {
- assigneeId: item.id,
- quantity: item.quantity,
- weight: item.weight,
- startTime: item.startTime,
- endTime: item.endTime,
- assigneeType: row.assignType,
- assigneeName: item.name,
- measuringUnit: this.current.measuringUnit,
- isNew: item.isNew ? item.isNew : '',
- deviceId:
- item.extInfo && item.extInfo.assetId ? item.extInfo.assetId : '',
- deviceName:
- item.extInfo && item.extInfo.assetName
- ? item.extInfo.assetName
- : '',
- workStationId: item.id,
- workStationName: item.name
- };
- if (item.teamTimeIds) {
- Aobj.teamTimeIds = item.teamTimeIds;
- }
- assignees.push(Aobj);
- changeIds.push(item.changeId);
- });
- // 校验没过 就不往下进行
- if (!flag) {
- this.$message.warning('请将所选数据的 数量,开始时间,完成时间 填写完毕');
- return;
- }
- let data = null;
- if (type == 2) {
- data = changeIds;
- } else {
- data = {
- taskId: this.processId,
- taskName: row.name,
- taskCode: row.code,
- teamName: this.form.teamName,
- teamId: this.form.teamId,
- workCenterId: this.form.workCenterId,
- workCenterName: this.form.workCenterName,
- workOrderId: this.current.id,
- dispatchMethod: 0,
- dispatchingMethod: this.form.taskAss,
- assignType: this.form.assignType,
- singleReport: this.form.singleReport,
- assignees
- };
- // 先判断是否派单过 有的话直接用前面派单的 类型数据 否则就是自己选择的数据
- if (this.isDispatchRow.hasExists) {
- data.dispatchType = this.isDispatchRow.dispatchType;
- } else {
- let singFlag = this.singleReportRadio();
- if (!singFlag) return;
- data.dispatchType = this.form.singleReport;
- }
- }
- this.toolbarLoading = true;
- try {
- if (!(await this.validateDispatchSourceConflict(data, type))) {
- this.toolbarLoading = false;
- return;
- }
- } catch (err) {
- this.toolbarLoading = false;
- this.$message.error(err.message);
- return;
- }
- const api =
- type == 1 ? taskAssignment : type == 2 ? taskRevoked : taskSave;
- api(data)
- .then((res) => {
- this.toolbarLoading = false;
- if (res) {
- this.$message.success('操作成功');
- // 更改当前表格数据
- this.setCurrentTab(row);
- // 查询是否派单
- this.queryCheckExists();
- }
- })
- .catch((err) => {
- this.toolbarLoading = false;
- this.$message.error(err.message);
- });
- },
- //添加工位
- addStation(item, index) {
- console.log(item, index);
- this.$refs.chooseStationRef.open(
- this.form.workCenterId,
- item.list,
- index,
- 2,
- this.form.teamId
- );
- },
- chooseStationList(list, index) {
- const process = this.processList?.[index];
- if (!process) {
- console.warn(`processList[${index}] 不存在`);
- return;
- }
- const oldList = structuredClone(
- Array.isArray(process.list) ? process.list : []
- );
- list.forEach((item) => {
- item.isNew = 1;
- item.assetCode = item.extInfo.assetCode;
- item.assetId = item.extInfo.assetId;
- item.assetName = item.extInfo.assetName;
- });
- console.log(list, '选择的工位数据');
- const newList = structuredClone(Array.isArray(list) ? list : []);
- this.$set(this.processList[index], 'list', [...oldList, ...newList]);
- },
- hasUndeliveredDispatchTask() {
- if (!Array.isArray(this.processList)) {
- return false;
- }
- return this.processList.some((process) =>
- (process.list || []).some(
- (row) => row?.status && Number(row.status.code) === 1
- )
- );
- },
- closeDispatchDialog(done) {
- this.$emit('update:dispatchVisible', false);
- if (typeof done === 'function') {
- done();
- }
- },
- cancel(done) {
- if (!this.hasUndeliveredDispatchTask()) {
- this.closeDispatchDialog(done);
- return;
- }
- this.$confirm('当前存在已派单但未下发的任务,是否仍要退出?', '提示', {
- type: 'warning',
- confirmButtonText: '确定',
- cancelButtonText: '取消'
- })
- .then(() => {
- this.closeDispatchDialog(done);
- })
- .catch(() => {});
- },
- // 按钮操作成功后 更改当前的表格数据
- setCurrentTab(row) {
- let arr = [];
- if (row.assignType == 1) {
- arr = this.stationList;
- } else if (row.assignType == 2) {
- arr = this.crewList;
- } else {
- arr = this.productionList;
- }
- this.getAssignData(row.index, arr);
- },
- singleReportRadio() {
- if (this.form.singleReport === 0 || this.form.singleReport === 1) {
- return true;
- }
- this.$message.warning('请先选择报工类型');
- return false;
- },
- async validateDispatchSourceConflict(data, type) {
- const actionType = Number(type);
- if (actionType !== 1 && actionType !== 3) {
- return true;
- }
- const checked = await checkAssignSourceType(data);
- const checkedResult =
- checked && typeof checked === 'object' ? checked.result : checked;
- const checkedMessage =
- checked && typeof checked === 'object' ? checked.message : '';
- if (checkedResult === true) {
- this.$message.warning(
- checkedMessage || '当前派单数据存在冲突,请调整后再操作'
- );
- }
- return true;
- },
- // 最后提交
- async confirm() {
- let flag = this.singleReportRadio();
- if (!flag) return;
- // if (!this.form.singleReport) {
- // }
- if (!this.form.teamId) {
- this.$message.warning('请先选择班组');
- return;
- }
- let permissionRes = await parameterGetByCode({
- code: 'production_order_dispatch_permission'
- });
- this.processingRequired = permissionRes.value || 0; // 兜底:若接口返回空,默认设为 0
- console.log(this.processingRequired);
- if (this.processingRequired == '1') {
- try {
- const isTeamLeader = await getcheckLoginUserIsTeamLeader(
- this.form.teamId
- );
- if (!isTeamLeader) {
- this.toolbarLoading = false;
- this.$message.warning('当前班组不是对应组长');
- return; // 校验不通过,终止后续流程
- }
- } catch (err) {
- this.toolbarLoading = false;
- this.$message.error('校验组长身份失败:' + err.message);
- return; // 校验报错,终止后续流程
- }
- }
- if (this.form.taskAss == 1) {
- this.issue();
- // 按原来的逻辑
- return;
- }
- // 获取到首工序id 的 绑定表格数据
- let data = this.processList[this.firstTaskindex];
- // 是否进行首工序派单
- let isFirstDispatch = false;
- let dispatchArr = []; // 已派单数据
- data.list.map((item) => {
- if (!item.status) {
- return;
- }
- if (item.status.code == 1) {
- isFirstDispatch = true;
- dispatchArr.push(item.id);
- }
- });
- // 判断是否进行首工序派单
- if (!isFirstDispatch) {
- this.$message.warning(`请您先进行首工序任务(${data.name}工序)派单`);
- this.handleClick({ name: data.id });
- return;
- }
- let totalSum = 0;
- // 判断派单的数据 数量相加是否为 要求生产数量
- data.list.map((item) => {
- if (item.status && item.status.code == 1) {
- totalSum += item.quantity - 0;
- }
- });
- // if (totalSum != this.current.formingNum - 0) {
- // this.$message.warning(
- // `首工序已派单的数据数量相加需要等于要求生产数量${this.current.formingNum}`
- // );
- // this.handleClick({ name: data.id });
- // return;
- // }
- this.toolbarLoading = true;
- let params = {
- teamId: this.form.teamId,
- workCenterId: this.form.workCenterId,
- workOrderId: this.current.id
- };
- try {
- const res = await checkAssignConfirm(params);
- if (!res) {
- this.toolbarLoading = false;
- return;
- }
- let paramsD = {
- assignType: data.assignType,
- singleReport: this.form.singleReport,
- teamId: this.form.teamId,
- dispatchingMethod: this.form.taskAss,
- crewIds: data.assignType == 2 ? dispatchArr : [], // 人员 2
- workstationIds: data.assignType == 1 ? dispatchArr : [], // 工位 1
- factoryLineIds: data.assignType == 3 ? dispatchArr : [], // 产线 3
- id: this.current.id,
- planStartTime: this.current.planStartTime,
- planEndTime: this.current.planEndTime
- };
- const response = await releaseWorkOrder(paramsD);
- this.toolbarLoading = false;
- if (response) {
- this.$message.success('操作成功');
- this.closeDispatchDialog();
- this.$emit('createSuccess');
- }
- } catch (err) {
- this.toolbarLoading = false;
- // this.$message.error(err.message);
- }
- },
- // 下达
- issue() {
- if (this.form.assignType == 1) {
- if (!this.form.workstationIds || this.form.workstationIds.length == 0) {
- this.$message.warning('请选择工位数据');
- return;
- }
- }
- if (this.form.assignType == 3) {
- if (!this.form.factoryLineIds || this.form.factoryLineIds.length == 0) {
- this.$message.warning('请选择产线数据');
- return;
- }
- }
- let data = {
- assignType: this.form.assignType,
- singleReport: this.form.singleReport,
- teamId: this.form.teamId,
- dispatchingMethod: this.form.taskAss,
- crewIds: [],
- workstationIds: [],
- id: this.current.id,
- planStartTime: this.current.planStartTime,
- planCompleteTime: this.current.planCompleteTime,
- factoryLineIds: []
- };
- if (this.form.assignType == 1) {
- data.workstationIds = this.form.workstationIds || [];
- } else if (this.form.assignType == 2) {
- data.crewIds = this.form.crewIds || [];
- } else {
- data.factoryLineIds = this.form.factoryLineIds || [];
- }
- this.toolbarLoading = true;
- releaseWorkOrder(data)
- .then((res) => {
- this.toolbarLoading = false;
- if (res) {
- this.$message.success('操作成功');
- this.closeDispatchDialog();
- this.$emit('createSuccess');
- }
- })
- .catch((err) => {
- this.toolbarLoading = false;
- // this.$message.error(err.message);
- });
- },
- // 工序选择
- async handleClick(tab) {
- let id = tab.name;
- this.processId = id;
- this.isTask = false;
- await this.FirstTaskIdFn(id);
- let data = this.processList.find((item) => item.id == this.processId);
- await this.changeRadio(data.assignType, data.index);
- },
- // 指派选择
- async changeRadio(e, index) {
- let data = this.processList[index];
- if (e == 1) {
- this.dynamicName = '工位名称';
- data.assignName = '工位';
- await this.getAssignData(index, this.stationList);
- } else if (e == 2) {
- this.dynamicName = '人员名称';
- data.assignName = '人员';
- await this.getAssignData(index, this.crewList);
- } else {
- this.dynamicName = '产线名称';
- data.assignName = '产线';
- await this.getAssignData(index, this.productionList);
- }
- },
- // 指派数据处理
- async getAssignData(index, arr) {
- let list = JSON.parse(JSON.stringify(arr));
- let dataRow = this.processList[index];
- // 不存在 班组数据的话 就不调用这个方法
- if (!this.form.teamId) {
- return;
- }
- let params = {
- workOrderId: this.current.id,
- workCenterId: this.form.workCenterId,
- teamId: this.form.teamId,
- taskId: dataRow.id
- };
- this.tabLoading = true;
- try {
- const res = await listAssign(params);
- this.tabLoading = false;
- // 如果 res 没有数据 说明未对数据进行操作 直接赋值
- if (res.length == 0) {
- this.$set(dataRow, 'list', list);
- return;
- }
- // 对有操作过的数据进行赋值
- this.operationalData(index, res, list);
- } catch (err) {
- this.tabLoading = false;
- this.$message.warning(err.message);
- }
- },
- // 操作过的数据 赋值
- // operationalData(index, res, list) {
- // const dataRow = this.processList[index];
- // // 键值对存储 当前工序 操作的数据 指派的code(键) 数据(list:值)
- // let arrMap = {};
- // // 要先判断有没有操作的数据 如果有的话 其它的指派操作置灰
- // let codeT = null; // 表示有已操作的数据(对应的 code)
- // res[0].assignees.map((el) => {
- // let code = el.assigneeType.code;
- // if (arrMap[code]) {
- // arrMap[code].arr.push(el);
- // arrMap[code].bunDis = arrMap[code].bunDis
- // ? arrMap[code].bunDis
- // : el.status.desc
- // ? true
- // : false;
- // } else {
- // arrMap[code] = {
- // arr: [el],
- // bunDis: el.status.desc ? true : false
- // };
- // }
- // codeT = codeT ? codeT : el.status.desc ? code : '';
- // });
- // let radioBun = {
- // lineDis: false, // 产线 3
- // staffDis: false, // 人员 2
- // stationDis: false // 工位 1
- // };
- // // 默认是传递下来的 list 数据 但是如果 codeT有值 说明 工位 人员 产线 有派单数据
- // // 需要自动切换过去
- // let listArr = list;
- // if (codeT) {
- // if (codeT == 1) {
- // radioBun.staffDis = true;
- // radioBun.lineDis = true;
- // radioBun.stationDis = false;
- // listArr = JSON.parse(JSON.stringify(this.stationList));
- // dataRow.assignType = 1;
- // dataRow.assignName = '工位';
- // } else if (codeT == 2) {
- // radioBun.stationDis = true;
- // radioBun.lineDis = true;
- // radioBun.staffDis = false;
- // listArr = JSON.parse(JSON.stringify(this.crewList));
- // dataRow.assignType = 2;
- // dataRow.assignName = '人员';
- // } else {
- // radioBun.stationDis = true;
- // radioBun.staffDis = true;
- // radioBun.lineDis = false;
- // listArr = JSON.parse(JSON.stringify(this.productionList));
- // dataRow.assignType = 3;
- // dataRow.assignName = '产线';
- // }
- // }
- // // 切换完后 对 指派的数组数据进行赋值
- // let listMap = {};
- // listArr.map((el, index) => (listMap[el.id] = index));
- // let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
- // dataRow.startDate = ''; // 每次计算的时候清空之前的
- // dataRow.endDate = '';
- // if (listArr.length == 0) return;
- // // listArr.forEach((it) => {
- // // if (it.disposalStatus || it.disposalStatus == 0) {
- // arrList.map((item) => {
- // if (item.assigneeType.code == dataRow.assignType) {
- // let idx = listMap[item.assigneeId];
- // if (!idx && idx !== 0) {
- // return;
- // }
- // listArr[idx].status = item.status;
- // listArr[idx].startTime = item.startTime;
- // listArr[idx].endTime = item.endTime;
- // listArr[idx].quantity = item.quantity;
- // listArr[idx].weight = item.weight;
- // listArr[idx].changeId = item.id;
- // listArr[idx].teamTimeIds = item.teamTimeIds;
- // this.compareAndSetTime(listArr[idx], dataRow);
- // this.compareEndSetTime(listArr[idx], dataRow);
- // }
- // });
- // // }
- // // });
- // // 这里重新调用一个方法 计算出 startDate endDate
- // this.$set(dataRow, 'list', listArr);
- // this.$set(dataRow, 'radioBun', radioBun);
- // this.$set(dataRow, 'selection', []);
- // let tab = `tableRef${[dataRow.index]}`;
- // this.$refs[tab][0].setSelectedRowKeys([]);
- // console.log(dataRow, 'dataRow +++++');
- // },
- operationalData(index, res, list) {
- const dataRow = this.processList[index];
- const oldList = structuredClone(
- Array.isArray(dataRow.list) ? dataRow.list : []
- );
- let arrMap = {};
- let codeT = null;
- res[0].assignees.map((el) => {
- let code = el.assigneeType.code;
- if (arrMap[code]) {
- arrMap[code].arr.push(el);
- arrMap[code].bunDis = arrMap[code].bunDis
- ? arrMap[code].bunDis
- : el.status.desc
- ? true
- : false;
- } else {
- arrMap[code] = { arr: [el], bunDis: el.status.desc ? true : false };
- }
- codeT = codeT ? codeT : el.status.desc ? code : '';
- });
- let radioBun = { lineDis: false, staffDis: false, stationDis: false };
- let listArr = list;
- if (codeT) {
- if (codeT == 1) {
- radioBun.staffDis = true;
- radioBun.lineDis = true;
- radioBun.stationDis = false;
- listArr = JSON.parse(JSON.stringify(this.stationList));
- dataRow.assignType = 1;
- dataRow.assignName = '工位';
- } else if (codeT == 2) {
- radioBun.stationDis = true;
- radioBun.lineDis = true;
- radioBun.staffDis = false;
- listArr = JSON.parse(JSON.stringify(this.crewList));
- dataRow.assignType = 2;
- dataRow.assignName = '人员';
- } else {
- radioBun.stationDis = true;
- radioBun.staffDis = true;
- radioBun.lineDis = false;
- listArr = JSON.parse(JSON.stringify(this.productionList));
- dataRow.assignType = 3;
- dataRow.assignName = '产线';
- }
- }
- if (Number(dataRow.assignType) === 1) {
- listArr = this.mergeAddedStationRows(oldList, listArr);
- }
- let listMap = {};
- listArr.map((el, idx) => (listMap[el.id] = idx));
- let arrList = codeT ? arrMap[codeT].arr : res[0].assignees;
- dataRow.startDate = '';
- dataRow.endDate = '';
- arrList.map((item) => {
- if (item.assigneeType.code == dataRow.assignType) {
- let idx = listMap[item.assigneeId];
- if (!idx && idx !== 0) return;
- listArr[idx].status = item.status;
- listArr[idx].startTime = item.startTime;
- listArr[idx].endTime = item.endTime;
- listArr[idx].quantity = item.quantity;
- listArr[idx].weight = item.weight;
- listArr[idx].changeId = item.id;
- listArr[idx].teamTimeIds = item.teamTimeIds;
- this.compareAndSetTime(listArr[idx], dataRow);
- this.compareEndSetTime(listArr[idx], dataRow);
- }
- });
- // ====== 修复:合并新增工位 ======
- const finalList = this.mergeNewRows(oldList, listArr);
- this.$set(dataRow, 'list', finalList);
- this.$set(dataRow, 'radioBun', radioBun);
- this.$set(dataRow, 'selection', []);
- // let tab = `tableRef${[dataRow.index]}`;
- // this.$refs[tab][0].setSelectedRowKeys([]);
- this.$nextTick(() => {
- const tab = `tableRef${dataRow.index}`;
- const tableRefs = this.$refs[tab];
- if (!tableRefs || !tableRefs[0]) {
- console.warn(`table ref ${tab} not ready`);
- return;
- }
- tableRefs[0].setSelectedRowKeys([]);
- });
- },
- mergeAddedStationRows(oldList, newList) {
- const existIds = new Set((newList || []).map((i) => i.id));
- const addedRows = (oldList || []).filter(
- (i) => i.isNew === 1 && !existIds.has(i.id)
- );
- return [...newList, ...addedRows];
- },
- mergeNewRows(oldList, newList) {
- const existIds = new Set(newList.map((i) => i.id));
- const tempRows = oldList.filter(
- (i) => i.isNew === 1 && !i.changeId && !existIds.has(i.id)
- );
- return [...newList, ...tempRows];
- },
- // 省略时间校验、派单、重置、数量重量处理、班次选择等方法
- // 可以保留原本的逻辑
- // 时间比较与赋值方法 开始时间
- compareAndSetTime(data, dataRow) {
- // 如果startDate为空,直接赋值为startTime
- if (!dataRow.startDate) {
- dataRow.startDate = data['startTime'];
- return;
- }
- // 转换为Date对象进行比较
- const startTimeDate = new Date(data['startTime']);
- const startDateDate = new Date(dataRow.startDate);
- // 比较时间(getTime()获取时间戳)
- if (startTimeDate.getTime() < startDateDate.getTime()) {
- dataRow.startDate = data['startTime'];
- }
- },
- // 时间比较与赋值方法 结束时间时间
- compareEndSetTime(data, dataRow) {
- // 如果startDate为空,直接赋值为endTime
- if (!dataRow.endDate) {
- dataRow.endDate = data['endTime'];
- return;
- }
- // 转换为Date对象进行比较
- const endTimeDate = new Date(data['endTime']);
- const endDateDate = new Date(dataRow.endDate);
- // 比较时间(getTime()获取时间戳)
- if (endTimeDate.getTime() > endDateDate.getTime()) {
- dataRow.endDate = data['endTime'];
- }
- },
- assignRadio(e) {},
- // 数量正则 quantity
- handleQuantityInput(e, row, item) {
- // 过滤非数字字符(包括负号)
- let value = e.replace(/[^\d]/g, '');
- // 限制不能以 0 开头(除非是 0 本身)
- if (value.startsWith('0') && value.length > 1) {
- value = value.slice(1);
- }
- // 更新绑定值
- row.quantity = value;
- this.calculateQuantity(row, item);
- this.bringWeight(row.quantity, row);
- this.selectedListData(row, item);
- },
- // 自动算重量
- bringWeight(value, row) {
- if (!this.current.formingWeight) {
- this.$set(row, 'weight', 0);
- return;
- }
- let weight =
- (this.current.formingWeight / this.current.formingNum) * value;
- if (weight > 0) {
- weight = weight.toFixed(4) - 0;
- }
- this.$set(row, 'weight', weight);
- },
- calculateQuantity(row, item) {
- // 如果没有该字段 就不做判断
- if (!this.current.formingNum) {
- return;
- }
- let total = 0;
- item.list.forEach((el) => {
- if (el.quantity) {
- total = total + (el.quantity - 0);
- }
- });
- if (total > this.current.formingNum - 0) {
- this.$message.warning('列表数量相加不能大于目标要求生产数量');
- row.quantity = 0;
- }
- },
- // 计算重量
- calculateWeight(row, item) {
- // 如果没有该字段 就不做判断
- if (!this.current.formingWeight) {
- return;
- }
- let total = 0;
- item.list.forEach((el) => {
- if (el.weight) {
- total = total + (el.weight - 0);
- }
- });
- if (total > this.current.formingWeight - 0) {
- this.$message.warning('列表数量相加不能大于目标要求生产数量');
- row.weight = 0;
- }
- },
- // 重量正则 weight
- handleWeightInput(e, row, item) {
- // 过滤非数字和非小数点字符(包括负号)
- let value = e.replace(/[-+^\d.]/g, '');
- value = e.replace(/[^\d.]/g, '');
- // 限制只能有一个小数点
- const dotCount = (value.match(/\./g) || []).length;
- if (dotCount > 1) {
- value = value.slice(0, value.lastIndexOf('.'));
- }
- // 限制不能以小数点开头
- if (value.startsWith('.')) {
- value = '0' + value;
- }
- // 更新绑定值
- row.weight = value;
- this.calculateWeight(row, item);
- this.selectedListData(row, item);
- },
- // 选中班次
- shiftSelection(e, row, item) {
- // this.$refs.tableRef0[0].setSelectedRowKeys(row.id);
- // let data = this.shiftList.find((item) => item.id == e);
- // this.selectedListData(row, item);
- let data = this.shifTimeData(e, row);
- let startTime = `${this.dateValue} ${data.startTime}` + `:00`;
- let endTime = `${this.dateValue} ${data.endTime}` + `:00`;
- this.$set(row, 'startTime', startTime);
- this.$set(row, 'endTime', endTime);
- this.handleStartTimeChange(row, item);
- this.handleEndTimeChange(row, item);
- },
- // 默认选中当前更改数据
- selectedListData(row, item) {
- let data = item.selection.find((el) => el.id == row.id);
- if (!data) {
- let ids = item.selection.map((el) => el.id);
- ids.push(row.id);
- let tab = `tableRef${[item.index]}`;
- this.$refs[tab][0].setSelectedRowKeys(ids);
- }
- },
- // 多选班次时间数据
- shifTimeData(e, row) {
- if (!e || e.length == 0) {
- return {
- startTime: row.startTime,
- endTime: row.endTime
- };
- }
- let startTime = '';
- let endTime = '';
- e.map((el) => {
- let obj = this.shiftList.find((item) => item.id == el);
- if (!startTime) {
- startTime = obj.startTime;
- }
- if (!endTime) {
- endTime = obj.endTime;
- }
- // 获取更小的
- startTime =
- this.compareTime(startTime, obj.startTime) !== -1
- ? obj.startTime
- : startTime;
- // 获取更大的
- endTime =
- this.compareTime(endTime, obj.endTime) !== 1 ? obj.endTime : endTime;
- });
- return {
- startTime,
- endTime
- };
- },
- // 将HH:mm:ss格式的时间转换为总秒数
- timeToSeconds(timeStr) {
- const [hours, minutes, seconds] = timeStr.split(':').map(Number);
- return hours * 3600 + minutes * 60 + seconds;
- },
- // this.$refs.table.setSelectedRowKeys(ids);
- // 比较两个时间的大小
- compareTime(time1, time2) {
- const sec1 = this.timeToSeconds(time1);
- const sec2 = this.timeToSeconds(time2);
- if (sec1 > sec2) {
- return 1; // time1 更大
- } else if (sec1 < sec2) {
- return -1; // time2 更大
- } else {
- return 0; // 两个时间相等
- }
- },
- // 【开始时间变化时】触发
- handleStartTimeChange(row, item) {
- if (!row.startTime) {
- return;
- }
- if (!this.checkPlanTimeRange(row, 'startTime', '计划开始时间')) {
- return;
- }
- this.selectedListData(row, item);
- // 这一道工序的开始时间 不能小于前一道工序的结束时间
- const startTime = new Date(row.startTime); // 开始时间
- if (item.index !== 0) {
- // let frontIdx = item.index - 1;
- let frontIdx = this.calculateIndex(item.index).startIdx;
- if (frontIdx !== 'none') {
- let frontName = this.processList[frontIdx].name;
- let time = this.processList[frontIdx].endDate;
- const frontTime = new Date(time); // 前面工序的结束时间
- if (time && startTime < frontTime) {
- this.$message.closeAll();
- this.$message.info(
- `开始时间不能小于前面工序${frontName}的结束时间${time}`
- );
- // 判断是否 配置时间更改规则
- if (this.time_calc_code == '1') {
- row.startTime = time;
- }
- return;
- }
- }
- }
- // 这一道工序的开始时间更不能大于后一道工序的开始时间
- if (item.index !== this.processList.length - 1) {
- // let latterIdx = item.index + 1;
- let latterIdx = this.calculateIndex(item.index).endIdx;
- if (latterIdx !== 'none') {
- let time = this.processList[latterIdx].startDate;
- let latterName = this.processList[latterIdx].name;
- const latterTime = new Date(time); // 下一道工序的结束时间
- if (time && startTime > latterTime) {
- this.$message.closeAll();
- this.$message.info(
- `开始时间不能大于后面工序${latterName}的开始时间${time}`
- );
- // 判断是否 配置时间更改规则
- if (this.time_calc_code == '1') {
- row.startTime = '';
- }
- return;
- }
- }
- }
- // 校验 是否 大于结束时间 wda
- this.checkEndTimeValid(row);
- },
- // 当更改一个工序开始时间 结束时间的时候
- // 开始时间 不能小于之前工序的结束时间 ( 要先去上一道工序找 是否存在结束时间 不存在就再往前找 直到 第一道工序 )
- // 结束时间 不能大于后面工序的开始时间 ( 要先去后一道工序找 是否存在开始时间 不存在就再往后找 直到 最后一道工序 )
- // 计算出当前下标数据 的前后 有 开始时间 结束时间的数据下标
- calculateIndex(index) {
- let startIdx = 'none';
- let endIdx = 'none';
- // 前面工序下标
- for (let i = index - 1; i >= 0; i--) {
- let row = this.processList[i];
- if (row && row.endDate) {
- startIdx = i;
- break;
- }
- }
- // 后面工序的下标
- for (let i = index + 1; i <= this.processList.length; i++) {
- let row = this.processList[i];
- if (row && row.startDate) {
- endIdx = i;
- break;
- }
- }
- return {
- startIdx,
- endIdx
- };
- },
- // 【结束时间变化时】触发
- handleEndTimeChange(row, item) {
- if (!row.endTime) {
- return;
- }
- if (!this.checkPlanTimeRange(row, 'endTime', '计划完成时间')) {
- return;
- }
- this.selectedListData(row, item);
- const endTime = new Date(row.endTime); // 结束时间
- // 当前工序的结束时间 不能大于后一道工序的开始时间
- if (item.index !== this.processList.length - 1) {
- let latterIdx = this.calculateIndex(item.index).endIdx;
- if (latterIdx !== 'none') {
- let latterName = this.processList[latterIdx].name;
- let time = this.processList[latterIdx].startDate;
- const latterTime = new Date(time); // 后面工序的开始时间
- if (time && endTime > latterTime) {
- this.$message.closeAll();
- this.$message.info(
- `结束时间不能大于后面工序${latterName}的开始时间${time}`
- );
- // 判断是否 配置时间更改规则
- if (this.time_calc_code == '1') {
- row.endTime = time;
- }
- return;
- }
- }
- }
- // 这一道工序的开始时间更不能小于于前一道工序的结束时间
- if (item.index !== 0) {
- let frontIdx = this.calculateIndex(item.index).startIdx;
- if (frontIdx !== 'none') {
- let frontName = this.processList[frontIdx].name;
- let time = this.processList[frontIdx].endDate;
- const frontTime = new Date(time); // 上一道工序的结束时间
- if (time && endTime < frontTime) {
- this.$message.closeAll();
- this.$message.info(
- `结束时间不能小于前面工序${frontName}的结束时间${time}`
- );
- // 判断是否 配置时间更改规则
- if (this.time_calc_code == '1') {
- row.endTime = '';
- }
- return;
- }
- }
- }
- this.checkEndTimeValid(row, item);
- },
- // 校验时间是否在生产计划范围内,不符合则提示并清空当前字段
- checkPlanTimeRange(row, field, label) {
- const currentTime = row[field];
- if (!currentTime) return true;
- const { planStartTime, planCompleteTime } = this.current || {};
- const chooseTime = new Date(currentTime);
- if (planStartTime && chooseTime < new Date(planStartTime)) {
- this.$message.closeAll();
- this.$message.info(`${label}不能小于计划开始时间${planStartTime}`);
- row[field] = '';
- return false;
- }
- if (planCompleteTime && chooseTime > new Date(planCompleteTime)) {
- this.$message.closeAll();
- this.$message.info(`${label}不能大于计划结束时间${planCompleteTime}`);
- row[field] = '';
- return false;
- }
- return true;
- },
- // 时间校验
- checkEndTimeValid(row) {
- const { startTime: start, endTime: end } = row;
- if (!start || !end) return;
- const startTime = new Date(start); // 开始时间
- const endTime = new Date(end); // 结束时间
- if (endTime < startTime) {
- row.endTime = '';
- this.$message.closeAll();
- this.$message.info('计划完成时间不能小于计划开始时间');
- }
- }
- }
- };
|