| | |
| | | placeholder="请选择班组成员" |
| | | > |
| | | <el-option |
| | | v-for="user in userTeamOptions" |
| | | v-for="user in reportForm.userIdsList" |
| | | :key="user.userId" |
| | | :label="user.nickName" |
| | | :value="{ userId: user.userId, userName: user.nickName }" |
| | |
| | | </el-form-item> |
| | | </el-col> |
| | | |
| | | <el-col :span="12"> |
| | | <el-form-item label="机台" prop="deviceId"> |
| | | <el-select |
| | | v-model="reportForm.deviceId" |
| | | placeholder="请选择机台" |
| | | filterable |
| | | clearable |
| | | @change="(val) => handleDeviceChange(val)" |
| | | :disabled="isDetail" |
| | | > |
| | | <el-option |
| | | v-for="item in deviceOptions" |
| | | :key="item.id" |
| | | :label="item.deviceName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <!-- <el-col :span="12">--> |
| | | <!-- <el-form-item label="机台" prop="deviceId">--> |
| | | <!-- <el-select--> |
| | | <!-- v-model="reportForm.deviceId"--> |
| | | <!-- placeholder="请选择机台"--> |
| | | <!-- filterable--> |
| | | <!-- clearable--> |
| | | <!-- @change="(val) => handleDeviceChange(val)"--> |
| | | <!-- :disabled="isDetail"--> |
| | | <!-- >--> |
| | | <!-- <el-option--> |
| | | <!-- v-for="item in deviceOptions"--> |
| | | <!-- :key="item.id"--> |
| | | <!-- :label="item.deviceName"--> |
| | | <!-- :value="item.id"--> |
| | | <!-- />--> |
| | | <!-- </el-select>--> |
| | | <!-- </el-form-item>--> |
| | | <!-- </el-col>--> |
| | | |
| | | <el-col :span="12"> |
| | | <el-form-item label="审核人" prop="auditUserId"> |
| | |
| | | </template> |
| | | </el-dialog> |
| | | <el-dialog v-model="scheduleDialogVisible" |
| | | :title="`生产排产(工单编号:${currentReportRowData?.workOrderNo || '-'})`" |
| | | :title="scheduleDialogTitle" |
| | | width="1000px" |
| | | :close-on-click-modal="false"> |
| | | <div class="schedule-panel"> |
| | | <el-row style="margin-bottom: 12px;"> |
| | | <el-row v-if="!isScheduleHistoryMode" style="margin-bottom: 12px;"> |
| | | <el-col> |
| | | <el-button type="primary" plain :disabled="scheduleLoading || scheduleSaving" @click="addScheduleRow"> |
| | | 新增一行 |
| | | </el-button> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <el-table :data="scheduleRows" border style="width: 100%" v-loading="scheduleLoading"> |
| | | <el-table-column type="index" label="序号" width="70" align="center" /> |
| | | |
| | | <el-table-column type="index" label="序号" width="70" align="center" :index="indexMethod" /> |
| | | <el-table-column label="本次上机机台" min-width="220"> |
| | | <template #default="{ row }"> |
| | | <el-select |
| | |
| | | filterable |
| | | clearable |
| | | style="width: 100%" |
| | | :disabled="scheduleSaving" |
| | | :disabled="scheduleSaving || isScheduleHistoryMode" |
| | | @change="val => handleScheduleDeviceChange(val, row)" |
| | | > |
| | | <el-option |
| | |
| | | |
| | | <el-table-column label="本次上机人" min-width="220"> |
| | | <template #default="{ row }"> |
| | | <div v-if="isScheduleHistoryMode" class="schedule-user-tags"> |
| | | <el-tag |
| | | v-for="(userId, index) in row.userIds" |
| | | :key="`${userId}-${index}`" |
| | | type="primary" |
| | | > |
| | | {{ resolveScheduleUserName(userId) }} |
| | | </el-tag> |
| | | <span v-if="!row.userIds?.length">-</span> |
| | | </div> |
| | | <el-select |
| | | v-else |
| | | v-model="row.userIds" |
| | | placeholder="请选择上机人" |
| | | filterable |
| | |
| | | format="YYYY-MM-DD HH:mm:ss" |
| | | placeholder="请选择上机时间" |
| | | style="width: 100%" |
| | | :disabled="scheduleSaving" |
| | | :disabled="scheduleSaving || isScheduleHistoryMode" |
| | | /> |
| | | </template> |
| | | </el-table-column> |
| | | |
| | | <el-table-column label="操作" width="110" align="center"> |
| | | <el-table-column v-if="!isScheduleHistoryMode" label="操作" width="110" align="center"> |
| | | <template #default="{ row }"> |
| | | <el-button |
| | | link |
| | |
| | | </el-table> |
| | | |
| | | <Pagination |
| | | v-show="schedulePage.total > 0" |
| | | v-show="isScheduleHistoryMode && schedulePage.total > 0" |
| | | style="margin-top: 12px" |
| | | :total="schedulePage.total" |
| | | :page="schedulePage.current" |
| | |
| | | |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button type="primary" :loading="scheduleSaving" @click="handleSaveSchedule">保存排产</el-button> |
| | | <el-button :disabled="scheduleSaving" @click="scheduleDialogVisible = false">取消</el-button> |
| | | <template v-if="isScheduleHistoryMode"> |
| | | <el-button @click="scheduleDialogVisible = false">关闭</el-button> |
| | | </template> |
| | | <template v-else> |
| | | <el-button type="primary" :loading="scheduleSaving" @click="handleSaveSchedule">保存排产</el-button> |
| | | <el-button :disabled="scheduleSaving" @click="scheduleDialogVisible = false">取消</el-button> |
| | | </template> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | |
| | | import {ElMessageBox, ElMessage} from "element-plus"; |
| | | import Pagination from "@/components/PIMTable/Pagination.vue"; |
| | | import dayjs from "dayjs"; |
| | | import { processList } from '@/api/productionManagement/productionProcess.js' |
| | | import { |
| | | productWorkOrderPage, |
| | | updateProductWorkOrder, |
| | |
| | | return [val]; |
| | | }; |
| | | |
| | | const isCurrentUserReportWorker = (row) => { |
| | | const isCurrentUserInUserIds = (row) => { |
| | | const uid = String(currentUserId.value || ""); |
| | | if (!uid) return false; |
| | | if (!row) return false; |
| | | |
| | | const candidateIds = [ |
| | | row.reportUserIds, |
| | | row.reportWorkerIds, |
| | | row.userIdList, |
| | | row.reportUserId, |
| | | row.userId, |
| | | ] |
| | | .flatMap((v) => normalizeArray(v)) |
| | | .map((v) => String(v)) |
| | | const ids = normalizeArray(row?.userIds) |
| | | .map(id => String(id)) |
| | | .filter(Boolean); |
| | | |
| | | if (candidateIds.includes(uid)) return true; |
| | | |
| | | const candidateNames = [ |
| | | row.userNames, |
| | | row.reportUserNames, |
| | | row.reportWorkerNames, |
| | | row.userName, |
| | | ] |
| | | .flatMap((v) => normalizeArray(v)) |
| | | .map((v) => String(v)) |
| | | .filter(Boolean); |
| | | |
| | | if (currentUserName.value && candidateNames.includes(currentUserName.value)) { |
| | | return true; |
| | | } |
| | | |
| | | if (Array.isArray(row.reportWorkerList)) { |
| | | const list = row.reportWorkerList |
| | | .map((item) => String(item?.userId ?? item?.id ?? "")) |
| | | .filter(Boolean); |
| | | if (list.includes(uid)) return true; |
| | | const nameList = row.reportWorkerList |
| | | .map((item) => String(item?.userName ?? item?.nickName ?? "")) |
| | | .filter(Boolean); |
| | | if (currentUserName.value && nameList.includes(currentUserName.value)) return true; |
| | | } |
| | | |
| | | return false; |
| | | return ids.includes(uid); |
| | | }; |
| | | |
| | | const canOperateByReportWorker = computed(() => { |
| | |
| | | return; |
| | | } |
| | | |
| | | const first = scheduleRows.value[0] || {}; |
| | | const deviceId = first.deviceId || currentReportRowData.value?.deviceId || ""; |
| | | const userOptions = deviceId ? buildScheduleUserOptionsByDeviceId(deviceId) : [...baseScheduleUsers.value]; |
| | | const defaultUserId = userOptions[0]?.userId ? String(userOptions[0].userId) : ""; |
| | | |
| | | scheduleRows.value.push( |
| | | createScheduleRow({ |
| | | id: "", |
| | | deviceId, |
| | | deviceName: first.deviceName || currentReportRowData.value?.deviceName || "", |
| | | userIds: defaultUserId ? [defaultUserId] : [], |
| | | deviceId:"", |
| | | deviceName:"", |
| | | userIds: [], |
| | | startTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
| | | }) |
| | | ); |
| | |
| | | if (!workOrderRow?.id) { |
| | | schedulePage.current = 1; |
| | | schedulePage.total = 0; |
| | | scheduleRows.value = [createScheduleRow({})]; |
| | | scheduleRows.value = []; |
| | | return; |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | const rows = buildScheduleRowsFromRecords(records); |
| | | |
| | | scheduleRows.value = rows.length > 0 ? rows : [createScheduleRow({})]; |
| | | const rows = records.map(record => mapMachineRecordToScheduleRow(record)); |
| | | scheduleRows.value = rows; |
| | | } catch (error) { |
| | | console.error("获取排产记录失败", error); |
| | | schedulePage.total = 0; |
| | | scheduleRows.value = [createScheduleRow({})]; |
| | | scheduleRows.value = []; |
| | | ElMessage.error("获取排产记录失败"); |
| | | } finally { |
| | | scheduleLoading.value = false; |
| | |
| | | }; |
| | | |
| | | const removeScheduleRow = async (row) => { |
| | | if (!row) return; |
| | | if (!row || isScheduleHistoryMode.value) return; |
| | | |
| | | if (!row.id) { |
| | | scheduleRows.value = scheduleRows.value.filter((item) => item !== row); |
| | | if (!scheduleRows.value.length) { |
| | | scheduleRows.value = [createScheduleRow({})]; |
| | | addScheduleRow(); |
| | | } |
| | | return; |
| | | } |
| | |
| | | }; |
| | | |
| | | const handleSchedulePagination = ({page, limit}) => { |
| | | if (!isScheduleHistoryMode.value) return; |
| | | schedulePage.current = page; |
| | | schedulePage.size = limit; |
| | | refreshScheduleRows(); |
| | |
| | | return payload; |
| | | }; |
| | | |
| | | const indexMethod = (index) => { |
| | | return (schedulePage.current - 1) * schedulePage.size + index + 1; |
| | | }; |
| | | |
| | | const scheduleDialogMode = ref("create"); |
| | | const isScheduleHistoryMode = computed(() => scheduleDialogMode.value === "history"); |
| | | const scheduleDialogTitle = computed(() => |
| | | `${isScheduleHistoryMode.value ? "排产记录" : "生产排产"}(工单编号:${currentReportRowData.value?.workOrderNo || "-"})` |
| | | ); |
| | | |
| | | const mapMachineRecordToScheduleRow = (record) => { |
| | | const id = record?.id ?? ""; |
| | | const deviceId = record?.machineId ?? record?.deviceId ?? ""; |
| | |
| | | ); |
| | | }; |
| | | |
| | | const resetCreateScheduleRows = () => { |
| | | schedulePage.current = 1; |
| | | schedulePage.total = 0; |
| | | scheduleRows.value = []; |
| | | addScheduleRow(); |
| | | }; |
| | | |
| | | const openScheduleDialog = async (row) => { |
| | | scheduleDialogMode.value = "create"; |
| | | currentReportRowData.value = row; |
| | | baseScheduleUsers.value = buildBaseScheduleUsersByRow(row); |
| | | userTemp.value = [...baseScheduleUsers.value]; |
| | | scheduleDialogVisible.value = true; |
| | | resetCreateScheduleRows(); |
| | | }; |
| | | |
| | | const openHistoryTimelineDialog = async (row) => { |
| | | scheduleDialogMode.value = "history"; |
| | | currentReportRowData.value = row; |
| | | baseScheduleUsers.value = buildBaseScheduleUsersByRow(row); |
| | | userTemp.value = [...baseScheduleUsers.value]; |
| | | schedulePage.current = 1; |
| | | schedulePage.total = 0; |
| | | scheduleRows.value = []; |
| | | scheduleDialogVisible.value = true; |
| | | |
| | |
| | | }; |
| | | |
| | | const handleSaveSchedule = async () => { |
| | | if (isScheduleHistoryMode.value) return; |
| | | if (scheduleSaving.value) return; |
| | | if (!validateScheduleRows()) return; |
| | | |
| | |
| | | } |
| | | |
| | | proxy.$modal.msgSuccess("排产已保存"); |
| | | await refreshScheduleRows(); |
| | | resetCreateScheduleRows(); |
| | | getList(); |
| | | } catch (error) { |
| | | console.error("保存排产失败", error); |
| | |
| | | }, |
| | | { |
| | | label: "操作", |
| | | width: "200", |
| | | width: "220", |
| | | align: "center", |
| | | dataType: "action", |
| | | fixed: "right", |
| | |
| | | clickFun: row => { |
| | | showReportDialog(row); |
| | | }, |
| | | // 用户当前id |
| | | disabled: row => row.completeQuantity >= row.planQuantity || |
| | | !isCurrentUserInUserIds(row) |
| | | }, |
| | | { |
| | | name: "生产排产", |
| | | clickFun: row => { |
| | | if (!row.canSchedule) { |
| | | ElMessage.warning("当前用户不在该工序人员中,不能生产排产"); |
| | | return; |
| | | } |
| | | openScheduleDialog(row); |
| | | }, |
| | | disabled: row => !row.canSchedule || row.completeQuantity >= row.planQuantity |
| | | }, |
| | | { |
| | | name: "排产记录", |
| | | clickFun: row => { |
| | | if (!row.canSchedule) { |
| | | ElMessage.warning("当前用户不在该工序人员中,不能查看排产记录"); |
| | | return; |
| | | } |
| | | openHistoryTimelineDialog(row); |
| | | }, |
| | | disabled: row => !row.canSchedule |
| | | } |
| | | // { |
| | | // name:"审核", |
| | | // color: "#f56c6c", |
| | |
| | | if (isNaN(num)) { |
| | | return; |
| | | } |
| | | // 如果超过待生产数量 |
| | | if (num > reportForm.planQuantity) { |
| | | proxy.$modal.msgWarning("本次生产数量不能大于待生产数量"); |
| | | reportForm.quantity = reportForm.planQuantity; |
| | | return; |
| | | } |
| | | // 如果小于1,清除 |
| | | if (num < 1) { |
| | | reportForm.quantity = null; |
| | |
| | | page.size = obj.limit; |
| | | getList(); |
| | | }; |
| | | const getList = () => { |
| | | const getList = async () => { |
| | | tableLoading.value = true; |
| | | const params = {...searchForm.value, ...page}; |
| | | productWorkOrderPage(params) |
| | | .then(res => { |
| | | tableLoading.value = false; |
| | | tableData.value = res.data.records; |
| | | page.total = res.data.total; |
| | | }) |
| | | .catch(() => { |
| | | tableLoading.value = false; |
| | | }); |
| | | |
| | | try { |
| | | await ensureCurrentUser(); |
| | | await processLists(); |
| | | |
| | | const params = { ...searchForm.value, ...page }; |
| | | const res = await productWorkOrderPage(params); |
| | | |
| | | const records = Array.isArray(res?.data?.records) ? res.data.records : []; |
| | | |
| | | tableData.value = records.map(row => ({ |
| | | ...row, |
| | | canSchedule: canScheduleByWorkOrderNo(row) |
| | | })); |
| | | |
| | | page.total = res?.data?.total || 0; |
| | | } finally { |
| | | tableLoading.value = false; |
| | | } |
| | | }; |
| | | |
| | | // 下载并打印工单流转卡(文件流) |
| | |
| | | }; |
| | | |
| | | const showReportDialog = row => { |
| | | // if (!isCurrentUserReportWorker(row)) { |
| | | // ElMessage.warning("当前用户不是该工单的报工人,无法报工"); |
| | | // return; |
| | | // } |
| | | |
| | | currentReportRowData.value = row; |
| | | reportForm.planQuantity = row.planQuantity - row.completeQuantity; |
| | | reportForm.quantity = |
| | | row.quantity !== undefined && row.quantity !== null ? row.quantity : null; |
| | | reportForm.quantity = row.planQuantity - row.completeQuantity; |
| | | reportForm.productProcessRouteItemId = row.productProcessRouteItemId; |
| | | reportForm.workOrderId = row.id; |
| | | reportForm.reportWork = row.reportWork; |
| | |
| | | reportForm.replenishQty = 0; |
| | | reportForm.teamList = []; |
| | | reportForm.scrapQty = 0; |
| | | reportForm.userIds = row.userIds || []; |
| | | |
| | | const ids = (row.userIds || "") |
| | | .split(",") |
| | | .map(id => id.trim()) |
| | | .filter(Boolean); |
| | | |
| | | reportForm.userIdsList = userTeamOptions.value |
| | | .filter(item => ids.includes(String(item.userId))) |
| | | .map(item => ({ |
| | | userId: item.userId, |
| | | nickName: item.nickName |
| | | })); |
| | | |
| | | |
| | | nextTick(() => { |
| | | reportFormRef.value?.clearValidate(); |
| | |
| | | return; |
| | | } |
| | | |
| | | if (!reportForm.startTime || !reportForm.endTime) { |
| | | ElMessageBox.alert("开始时间和结束时间不能为空", "提示", { |
| | | confirmButtonText: "确定", |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | if (dayjs(reportForm.startTime).isSame(dayjs(reportForm.endTime)) || dayjs(reportForm.startTime).isAfter(dayjs(reportForm.endTime))) { |
| | | ElMessageBox.alert("开始时间必须小于结束时间", "提示", { |
| | | confirmButtonText: "确定", |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | const submitData = { |
| | | ...reportForm, |
| | | quantity: quantity, |
| | |
| | | } |
| | | } |
| | | |
| | | onMounted(() => { |
| | | ensureCurrentUser(); |
| | | getList(); |
| | | const processData = ref([]); |
| | | |
| | | // 查询所有工序 |
| | | const processLists = async () => { |
| | | console.log(processData.value) |
| | | if (processData.value.length > 0) { |
| | | return processData.value; |
| | | } |
| | | const res = await processList(); |
| | | |
| | | processData.value = Array.isArray(res?.data) ? res.data : []; |
| | | return processData.value; |
| | | }; |
| | | |
| | | // 判断当前用户是否能排产 |
| | | const canScheduleByWorkOrderNo = (row) => { |
| | | if (!row) return false; |
| | | |
| | | const uid = String(currentUserId.value || ""); |
| | | if (!uid) return false; |
| | | |
| | | const currentProcess = processData.value.find(item => |
| | | String(item.id) === String(row.processId) |
| | | ); |
| | | |
| | | if (!currentProcess) return false; |
| | | |
| | | const ids = normalizeArray(currentProcess.userIds) |
| | | .map(id => String(id).trim()) |
| | | .filter(Boolean); |
| | | |
| | | return ids.includes(uid); |
| | | }; |
| | | |
| | | onMounted(async () => { |
| | | await ensureCurrentUser(); |
| | | await processLists(); |
| | | await getList(); |
| | | getUserList(); |
| | | getDeviceList(); |
| | | }); |
| | |
| | | justify-content: flex-start; |
| | | } |
| | | } |
| | | |
| | | .schedule-user-tags { |
| | | display: flex; |
| | | flex-wrap: wrap; |
| | | gap: 8px; |
| | | min-height: 32px; |
| | | align-items: center; |
| | | } |
| | | </style> |
| | | |
| | | <style lang="scss"> |