diff --git a/src/views/modules/yieldReport/com_finish_roll.vue b/src/views/modules/yieldReport/com_finish_roll.vue index 9597dac..c493527 100644 --- a/src/views/modules/yieldReport/com_finish_roll.vue +++ b/src/views/modules/yieldReport/com_finish_roll.vue @@ -25,9 +25,8 @@ {{buttons.closeButton}} - - - 考勤修改 + + 考勤修改 diff --git a/src/views/modules/yieldReport/com_switch_operator.vue b/src/views/modules/yieldReport/com_switch_operator.vue index f1b4421..0dadc2a 100644 --- a/src/views/modules/yieldReport/com_switch_operator.vue +++ b/src/views/modules/yieldReport/com_switch_operator.vue @@ -327,7 +327,7 @@ export default { this.titleCon = isAttendanceMode ? '考勤修改' : this.labels.componentTitle;//重置标题 }, - // 加载操作员列表 + // 加载操作员列表(只查询在岗人员 is_on_duty = 'Y') loadOperatorList() { if (!this.currentSchedule.orderNo || !this.currentSchedule.seqNo) { return; @@ -337,7 +337,7 @@ export default { orderNo: this.currentSchedule.orderNo, itemNo: this.currentSchedule.itemNo, seqNo: this.currentSchedule.seqNo, - isOnDuty: 'Y' + isOnDuty: 'Y' // 只查询在岗人员 }; getOperatorList2(params).then(({ data }) => { if (data && data.code === 0) { @@ -408,20 +408,30 @@ export default { }); }, - // 更新单行操作员时间(下岗) + // 下岗操作 updateOperatorTime(row) { - // 校验时间 - const validateResult = this.validateOperatorTime(row); - if (!validateResult.valid) { - this.$message.error(validateResult.message); - return; - } - - this.$confirm('确定更新该操作员的上下岗时间吗?', '提示', { + this.$confirm('确定让该操作员下岗吗?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { + // 如果用户没有选择下岗时间,使用当前时间 + let offDutyTime = row.offDutyTime; + if (!offDutyTime) { + const now = new Date(); + offDutyTime = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`; + } + + // 校验下岗时间不能早于上岗时间 + if (row.onDutyTime && offDutyTime) { + const onDuty = new Date(row.onDutyTime); + const offDuty = new Date(offDutyTime); + if (offDuty < onDuty) { + this.$message.error('下岗时间不能早于上岗时间!'); + return; + } + } + const params = { id: row.id, site: this.$store.state.user.site, @@ -429,20 +439,19 @@ export default { itemNo: this.currentSchedule.itemNo, seqNo: this.currentSchedule.seqNo, operator: row.operator, - onDutyTime: row.onDutyTime, - offDutyTime: row.offDutyTime + offDutyTime: offDutyTime }; - updateOperatorTime(params).then(({ data }) => { + removeOperatorOnDuty(params).then(({ data }) => { if (data && data.code === 0) { - this.$message.success('操作员时间更新成功!'); + this.$message.success('操作员下岗成功!'); // 刷新列表 this.loadOperatorList(); } else { - this.$message.error(data.msg || '操作员时间更新失败!'); + this.$message.error(data.msg || '操作员下岗失败!'); } }).catch(() => { - this.$message.error('操作员时间更新失败!'); + this.$message.error('操作员下岗失败!'); }); }).catch(() => { // 取消操作 @@ -451,9 +460,9 @@ export default { // 校验操作员时间 validateOperatorTime(row) { - // 允许上岗时间为空(跳过校验) + // 上岗时间不能为空 if (!row.onDutyTime) { - return { valid: true }; + return { valid: false, message: '上岗时间不能为空!' }; } const now = new Date(); @@ -533,54 +542,82 @@ export default { // 批量更新操作员时间(返回Promise) batchUpdateOperatorTimeSync() { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { // 如果列表为空,直接返回 if (!this.operatorList || this.operatorList.length === 0) { resolve(); return; } - // 校验所有行的时间 - for (let i = 0; i < this.operatorList.length; i++) { - const row = this.operatorList[i]; - const validateResult = this.validateOperatorTime(row); - if (!validateResult.valid) { - this.$message.error(`第 ${i + 1} 行:${validateResult.message}`); - reject(); - return; + try { + // 分为两组:需要下岗的 和 只需要更新上岗时间的 + const offDutyList = []; // 需要下岗的 + const updateOnDutyList = []; // 只更新上岗时间的 + + for (let i = 0; i < this.operatorList.length; i++) { + const row = this.operatorList[i]; + + // 上岗时间不能为空 + if (!row.onDutyTime) { + this.$message.error(`第 ${i + 1} 行:上岗时间不能为空!`); + reject(); + return; + } + + if (row.offDutyTime) { + // 有下岗时间,需要校验并执行下岗操作 + const onDuty = new Date(row.onDutyTime); + const offDuty = new Date(row.offDutyTime); + + if (offDuty < onDuty) { + this.$message.error(`第 ${i + 1} 行:下岗时间不能早于上岗时间!`); + reject(); + return; + } + + offDutyList.push({ + id: row.id, + operator: row.operator, + offDutyTime: row.offDutyTime + }); + } else { + // 没有下岗时间,只更新上岗时间 + updateOnDutyList.push({ + id: row.id, + operator: row.operator, + onDutyTime: row.onDutyTime + }); + } } - } - - // 准备批量更新的数据 - const operatorListData = this.operatorList.map(row => ({ - id: row.id, - operator: row.operator, - onDutyTime: row.onDutyTime, - offDutyTime: row.offDutyTime - })); - const params = { - site: this.$store.state.user.site, - orderNo: this.currentSchedule.orderNo, - itemNo: this.currentSchedule.itemNo, - seqNo: this.currentSchedule.seqNo, - operatorList: operatorListData - }; + // 调用后端批量处理 + const params = { + site: this.$store.state.user.site, + orderNo: this.currentSchedule.orderNo, + itemNo: this.currentSchedule.itemNo, + seqNo: this.currentSchedule.seqNo, + offDutyList: offDutyList, + updateOnDutyList: updateOnDutyList + }; - batchUpdateOperatorTime(params).then(({ data }) => { - if (data && data.code === 0) { - this.$message.success('考勤信息批量更新成功!'); - // 刷新列表 - this.loadOperatorList(); - resolve(); - } else { - this.$message.error(data.msg || '考勤信息批量更新失败!'); + batchUpdateOperatorTime(params).then(({ data }) => { + if (data && data.code === 0) { + this.$message.success('考勤信息批量更新成功!'); + // 刷新列表 + this.loadOperatorList(); + resolve(); + } else { + this.$message.error(data.msg || '考勤信息批量更新失败!'); + reject(); + } + }).catch(() => { + this.$message.error('考勤信息批量更新失败!'); reject(); - } - }).catch(() => { - this.$message.error('考勤信息批量更新失败!'); - reject(); - }); + }); + } catch (error) { + this.$message.error('批量更新操作员时间失败!'); + reject(error); + } }); },