<template>
|
<view class="work-order">
|
<!-- 通用页面头部 -->
|
<PageHeader title="生产工单" @back="goBack" />
|
|
<!-- 搜索区域 -->
|
<view class="search-section">
|
<view class="search-bar">
|
<view class="search-input">
|
<up-input
|
class="search-text"
|
placeholder="请输入工单编号搜索"
|
v-model="searchForm.workOrderNo"
|
@confirm="handleQuery"
|
clearable
|
/>
|
</view>
|
|
<view class="filter-button" @click="handleQuery">
|
<up-icon name="search" size="24" color="#999"></up-icon>
|
</view>
|
</view>
|
</view>
|
|
<!-- 工单列表 -->
|
<scroll-view
|
scroll-y
|
class="ledger-list"
|
v-if="tableData.length > 0"
|
lower-threshold="80"
|
@scrolltolower="loadMore"
|
>
|
<view v-for="(item, index) in tableData" :key="item.id || index" class="ledger-item" @click="showTransferCard(item)">
|
<view class="item-header">
|
<view class="item-left">
|
<view class="document-icon">
|
<up-icon name="file-text" size="16" color="#ffffff"></up-icon>
|
</view>
|
<text class="item-id">{{ item.workOrderNo || '无' }}</text>
|
</view>
|
<view class="item-right">
|
<text class="item-tag tag-type">{{ item.workOrderType || '无' }}</text>
|
</view>
|
</view>
|
|
<up-divider></up-divider>
|
|
<view class="item-details">
|
<view class="detail-row">
|
<text class="detail-label">产品名称</text>
|
<text class="detail-value">{{ item.productName || '无' }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">规格型号</text>
|
<text class="detail-value">{{ item.model || '无' }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">工序名称 / 计量单位</text>
|
<text class="detail-value">{{ item.processName || '无' }} / {{ item.unit || '无' }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">需求/完成数量</text>
|
<text class="detail-value">{{ item.planQuantity || '无' }} / {{ item.completeQuantity || '无' }}</text>
|
</view>
|
|
<view class="progress-section">
|
<text class="detail-label">完成进度</text>
|
<view class="progress-bar">
|
<up-line-progress
|
:percentage="toProgressPercentage(item.completionStatus)"
|
activeColor="#2979ff"
|
:showText="true"
|
></up-line-progress>
|
</view>
|
</view>
|
</view>
|
|
<view class="item-actions" v-if="!isEnded(item)">
|
<up-button
|
text="报工"
|
size="mini"
|
type="success"
|
:disabled="!canEndProduction(item)"
|
@click.stop="openEndReport(item)"
|
/>
|
</view>
|
</view>
|
<up-loadmore :status="loadStatus" />
|
</scroll-view>
|
|
<view v-else-if="!loading" class="no-data">
|
<up-empty mode="data" text="暂无工单数据"></up-empty>
|
</view>
|
|
<!-- 流转卡弹窗 -->
|
<up-popup :show="transferCardVisible" mode="center" @close="transferCardVisible = false" round="10">
|
<view class="qr-popup">
|
<text class="qr-info" v-if="transferCardRowData">{{ transferCardRowData.workOrderNo || '-' }}</text>
|
<view class="transfer-records">
|
<view class="transfer-records-header">
|
<text class="transfer-records-title">报工审核记录</text>
|
<text class="transfer-records-count">共 {{ transferCardRecords.length }} 条</text>
|
</view>
|
<view v-if="transferCardLoading" class="transfer-records-loading">加载中...</view>
|
<view v-else-if="transferCardRecords.length > 0" class="transfer-records-list">
|
<view
|
v-for="(record, index) in transferCardRecords"
|
:key="record.id || index"
|
class="transfer-record-item"
|
>
|
<view class="transfer-record-top">
|
<view class="transfer-record-top-main">
|
<text class="transfer-record-no">{{ record.productNo || `报工记录${index + 1}` }}</text>
|
<text class="transfer-record-sub">
|
{{ record.process || '-' }} / {{ record.deviceName || '-' }}
|
</text>
|
</view>
|
<text class="audit-status-tag" :class="`audit-status-${getAuditStatusType(record.auditStatus)}`">
|
{{ getAuditStatusLabel(record.auditStatus) }}
|
</text>
|
</view>
|
<view class="transfer-record-grid">
|
<view
|
v-for="field in transferRecordFields"
|
:key="field.prop"
|
class="transfer-record-cell"
|
:class="{ 'is-wide': field.wide }"
|
>
|
<text class="transfer-record-label">{{ field.label }}</text>
|
<view v-if="field.prop === 'teamNames'" class="transfer-record-content">
|
<view v-if="getTeamNameList(record.teamNames).length > 0" class="transfer-tag-list">
|
<text
|
v-for="name in getTeamNameList(record.teamNames)"
|
:key="name"
|
class="transfer-name-tag"
|
>
|
{{ name }}
|
</text>
|
</view>
|
<text v-else class="transfer-record-value">-</text>
|
</view>
|
<view v-else-if="field.prop === 'auditStatus'" class="transfer-record-content">
|
<text class="audit-status-tag" :class="`audit-status-${getAuditStatusType(record.auditStatus)}`">
|
{{ getAuditStatusLabel(record.auditStatus) }}
|
</text>
|
</view>
|
<text v-else class="transfer-record-value">
|
{{ formatTransferRecordValue(record, field.prop) }}
|
</text>
|
</view>
|
</view>
|
</view>
|
</view>
|
<view v-else class="transfer-records-empty">暂无报工审核记录</view>
|
</view>
|
<up-button text="关闭" @click="transferCardVisible = false" style="margin-top: 20px;"></up-button>
|
</view>
|
</up-popup>
|
|
<!-- 报工弹窗 -->
|
<up-popup
|
v-model:show="endReportVisible"
|
mode="bottom"
|
:round="20"
|
:safeAreaInsetBottom="true"
|
@close="closeEndReport"
|
>
|
<view class="report-modal">
|
<view class="modal-header">
|
<view class="modal-header-left">
|
<text class="modal-title">报工</text>
|
<text class="modal-subtitle" v-if="endReportRow">
|
{{ endReportRow.workOrderNo || '-' }} · {{ endReportRow.deviceName || '-' }}
|
</text>
|
</view>
|
<view class="close-btn" @click="closeEndReport">
|
<up-icon name="close" size="20" color="#999"></up-icon>
|
</view>
|
</view>
|
|
<scroll-view class="modal-content" scroll-y>
|
<!-- <view class="report-summary" v-if="endReportRow">
|
<view class="summary-left">
|
<text class="summary-title">{{ endReportRow.productName || '-' }}</text>
|
<text class="summary-sub">{{ endReportRow.processName || '-' }} · {{ endReportRow.model || '-' }}</text>
|
</view>
|
<view class="summary-right">
|
<text class="summary-num">{{ endReportForm.planQuantity || '0' }}</text>
|
<text class="summary-label">待生产</text>
|
</view>
|
</view> -->
|
|
<up-form :model="endReportForm" labelWidth="120">
|
<view class="form-section">
|
<text class="section-title">数量信息</text>
|
<up-form-item label="待生产数量">
|
<up-input v-model="endReportForm.planQuantity" disabled />
|
</up-form-item>
|
<up-form-item label="本次生产数量" required>
|
<up-input v-model="endReportForm.quantity" />
|
</up-form-item>
|
<up-form-item label="补产数量">
|
<up-input v-model="endReportForm.replenishQty" type="number" placeholder="请输入" />
|
</up-form-item>
|
<up-form-item label="报废数量">
|
<up-input v-model="endReportForm.scrapQty" type="number" placeholder="请输入" />
|
</up-form-item>
|
<up-form-item label="开始时间" required>
|
<up-input
|
v-model="endReportForm.startTime"
|
readonly
|
placeholder="请选择开始时间"
|
@click="startTimePickerVisible = true"
|
/>
|
</up-form-item>
|
|
<up-form-item label="结束时间" required>
|
<up-input
|
v-model="endReportForm.endTime"
|
readonly
|
placeholder="请选择结束时间"
|
@click="endTimePickerVisible = true"
|
/>
|
</up-form-item>
|
</view>
|
|
<view class="form-section">
|
<up-form-item label="机台" required>
|
<up-input
|
v-model="endReportForm.deviceName"
|
readonly
|
placeholder="请选择"
|
@click="openDevicePicker"
|
suffixIcon="arrow-down"
|
/>
|
</up-form-item>
|
<up-form-item label="班组人员">
|
<up-input
|
v-model="teamDisplayText"
|
readonly
|
placeholder="请选择(可多选)"
|
@click="openTeamPicker"
|
suffixIcon="arrow-down"
|
/>
|
</up-form-item>
|
<up-form-item label="审核人" required>
|
<up-input
|
v-model="endReportForm.auditUserName"
|
readonly
|
placeholder="请选择"
|
@click="openAuditPicker"
|
suffixIcon="arrow-down"
|
/>
|
</up-form-item>
|
</view>
|
</up-form>
|
<view style="height: 24px;"></view>
|
</scroll-view>
|
|
<view class="modal-footer">
|
<up-button
|
text="取消"
|
type="info"
|
plain
|
@click="closeEndReport"
|
:customStyle="{ marginRight: '12px', flex: 1 }"
|
/>
|
<up-button text="提交" type="primary" @click="submitEndReport" :customStyle="{ flex: 1 }" />
|
</view>
|
</view>
|
</up-popup>
|
|
<!-- 班组选择弹窗 -->
|
<up-popup v-model:show="teamPickerVisible" mode="bottom" :round="20" :safeAreaInsetBottom="true">
|
<view class="team-modal">
|
<view class="modal-header">
|
<text class="modal-title">选择班组成员</text>
|
<view class="close-btn" @click="teamPickerVisible = false">
|
<up-icon name="close" size="20" color="#999"></up-icon>
|
</view>
|
</view>
|
<scroll-view class="team-content" scroll-y>
|
<up-checkbox-group v-model="teamCheckedIds" placement="column">
|
<up-checkbox
|
v-for="u in userOptions"
|
:key="u.value"
|
:label="u.name"
|
:name="String(u.value)"
|
:customStyle="{ marginBottom: '10px' }"
|
/>
|
</up-checkbox-group>
|
</scroll-view>
|
<view class="modal-footer">
|
<up-button text="取消" type="info" plain @click="teamPickerVisible = false" />
|
<up-button text="确定" type="primary" @click="confirmTeamPicker" />
|
</view>
|
</view>
|
</up-popup>
|
|
<!-- 审核人选择器 -->
|
<up-action-sheet
|
:show="auditPickerVisible"
|
:actions="auditActions"
|
title="选择审核人"
|
@select="onAuditSelect"
|
@close="auditPickerVisible = false"
|
/>
|
<up-action-sheet
|
:show="devicePickerVisible"
|
:actions="deviceActions"
|
title="选择机台"
|
@select="onDeviceSelect"
|
@close="devicePickerVisible = false"
|
/>
|
|
<!-- 时间选择器 -->
|
<up-datetime-picker
|
:show="startTimePickerVisible"
|
v-model="startTimeValue"
|
mode="datetime"
|
@confirm="onStartTimeConfirm"
|
@cancel="startTimePickerVisible = false"
|
/>
|
<up-datetime-picker
|
:show="endTimePickerVisible"
|
v-model="endTimeValue"
|
mode="datetime"
|
@confirm="onEndTimeConfirm"
|
@cancel="endTimePickerVisible = false"
|
/>
|
|
<!-- 附件组件 -->
|
<FilesDia ref="workOrderFilesRef" />
|
</view>
|
</template>
|
|
<script setup>
|
import { ref, reactive, toRefs, computed, getCurrentInstance } from "vue";
|
import { onShow, onLoad, onReachBottom } from "@dcloudio/uni-app";
|
import { productWorkOrderPage, addProductMain, startProduction, getProductWorkOrderById,getProductionProductMain } from "@/api/productionManagement/productionReporting.js";
|
import { getDeviceLedger } from "@/api/equipmentManagement/ledger";
|
import { userListNoPageByTenantId } from "@/api/system/user.js";
|
import PageHeader from "@/components/PageHeader.vue";
|
import FilesDia from "./components/filesDia.vue";
|
import useUserStore from "@/store/modules/user";
|
|
const userStore = useUserStore();
|
|
const loading = ref(false);
|
const tableData = ref([]);
|
const loadStatus = ref('loadmore');
|
const transferCardVisible = ref(false);
|
const transferCardRowData = ref(null);
|
const transferCardLoading = ref(false);
|
const transferCardRecords = ref([]);
|
const auditStatusOptions = ref([
|
{ label: "未审核", value: 0 },
|
{ label: "通过", value: 1 },
|
{ label: "不通过", value: 2 },
|
]);
|
const transferRecordFields = [
|
{ label: "报工人员", prop: "teamNames", wide: true },
|
{ label: "审核人", prop: "auditUserName" },
|
{ label: "最终审核人", prop: "sureAuditUserName" },
|
{ label: "工单编号", prop: "workOrderNo" },
|
{ label: "订单编号", prop: "salesContractNo" },
|
{ label: "产品名称", prop: "productName" },
|
{ label: "产品规格型号", prop: "productModelName" },
|
{ label: "产出数量", prop: "quantity" },
|
{ label: "报废数量", prop: "scrapQty" },
|
{ label: "单位", prop: "unit" },
|
{ label: "审核状态", prop: "auditStatus" },
|
{ label: "备注信息", prop: "auditOpinion", wide: true },
|
{ label: "创建时间", prop: "createTime", wide: true },
|
];
|
const workOrderFilesRef = ref(null);
|
const startSubmittingId = ref(null);
|
|
const endReportVisible = ref(false);
|
const endReportRow = ref(null);
|
const endReportForm = reactive({
|
planQuantity: "",
|
quantity: "",
|
replenishQty: "0",
|
scrapQty: "0",
|
deviceLedgerId: "",
|
deviceName: "",
|
teamList: [],
|
startTime: "",
|
endTime: "",
|
auditUserId: "",
|
auditUserName: "",
|
userId: "",
|
userName: "",
|
workOrderId: "",
|
reportWork: "",
|
productProcessRouteItemId: "",
|
productMainId: null,
|
});
|
|
const userOptions = ref([]);
|
const auditPickerVisible = ref(false);
|
const auditActions = computed(() => userOptions.value.map(u => ({ name: u.name, value: u.value })));
|
|
const deviceOptions = ref([]);
|
const devicePickerVisible = ref(false);
|
const deviceActions = computed(() => deviceOptions.value.map(d => ({ name: d?.deviceName || "", value: d?.id })));
|
|
const teamPickerVisible = ref(false);
|
const teamCheckedIds = ref([]);
|
const teamDisplayText = computed(() => {
|
const list = Array.isArray(endReportForm.teamList) ? endReportForm.teamList : [];
|
const names = list.map(i => String(i?.userName ?? "")).filter(Boolean);
|
if (names.length === 0) return "";
|
if (names.length <= 2) return names.join("、");
|
return `${names.slice(0, 2).join("、")}等${names.length}人`;
|
});
|
|
const startTimePickerVisible = ref(false);
|
const endTimePickerVisible = ref(false);
|
const startTimeValue = ref(Date.now());
|
const endTimeValue = ref(Date.now());
|
|
const routeOrderRow = ref(null);
|
|
const page = reactive({
|
current: 1,
|
size: 10,
|
total: 0,
|
});
|
|
const data = reactive({
|
searchForm: {
|
workOrderId: "",
|
},
|
});
|
const { searchForm } = toRefs(data);
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const handleQuery = () => {
|
page.current = 1;
|
tableData.value = [];
|
loadStatus.value = "loadmore";
|
getList();
|
};
|
|
const showToast = (message) => {
|
uni.showToast({ title: message, icon: "none" });
|
};
|
|
const ensureUserInfo = async () => {
|
if (userStore.id) return;
|
try {
|
await userStore.getInfo();
|
} catch {
|
}
|
};
|
|
const ensureUserOptions = async () => {
|
if (userOptions.value.length > 0) return;
|
try {
|
const res = await userListNoPageByTenantId();
|
const users = res?.data || [];
|
users.unshift({
|
nickName:"任意用户",
|
userId:"-1",
|
})
|
userOptions.value = users.map(u => ({
|
name: u?.nickName || "",
|
value: String(u?.userId ?? ""),
|
})).filter(u => u.value);
|
} catch {
|
userOptions.value = [];
|
}
|
};
|
|
const ensureDeviceOptions = async () => {
|
if (deviceOptions.value.length > 0) return;
|
try {
|
const res = await getDeviceLedger();
|
deviceOptions.value = res?.data || [];
|
} catch {
|
deviceOptions.value = [];
|
}
|
};
|
|
const getList = () => {
|
if (loading.value) return;
|
loading.value = true;
|
|
const params = { ...searchForm.value, ...page };
|
|
productWorkOrderPage(params).then((res) => {
|
loading.value = false;
|
const records = res.data.records || [];
|
tableData.value = page.current === 1 ? records : [...tableData.value, ...records];
|
page.total = res.data.total;
|
|
if (tableData.value.length >= page.total) {
|
loadStatus.value = 'nomore';
|
} else {
|
loadStatus.value = 'loadmore';
|
}
|
}).catch(() => {
|
loading.value = false;
|
loadStatus.value = "loadmore";
|
uni.showToast({ title: '加载失败', icon: 'error' });
|
});
|
};
|
|
const loadSingleWorkOrder = async (row) => {
|
if (!row?.id) {
|
handleQuery();
|
return;
|
}
|
loading.value = true;
|
try {
|
const res = await getProductWorkOrderById({ id: row.id });
|
const data = res?.data;
|
tableData.value = data ? [data] : [];
|
page.total = tableData.value.length;
|
loadStatus.value = 'nomore';
|
} catch {
|
tableData.value = [];
|
showToast("加载工单失败");
|
} finally {
|
loading.value = false;
|
}
|
};
|
|
const loadMore = () => {
|
console.log(loadStatus.value);
|
if (loadStatus.value === 'nomore' || loading.value) return;
|
loadStatus.value = "loading";
|
page.current++;
|
getList();
|
};
|
|
onReachBottom(() => {
|
loadMore();
|
});
|
|
const toProgressPercentage = (val) => {
|
const n = Number(val);
|
if (!Number.isFinite(n)) return 0;
|
if (n <= 0) return 0;
|
if (n >= 100) return 100;
|
return Math.round(n);
|
};
|
|
const getAuditStatusLabel = (val) => {
|
const target = auditStatusOptions.value.find(item => Number(item.value) === Number(val));
|
return target?.label || "未知";
|
};
|
|
const getAuditStatusType = (val) => {
|
const typeMap = { 0: "info", 1: "success", 2: "danger" };
|
return typeMap[Number(val)] || "default";
|
};
|
|
const getTeamNameList = (val) => {
|
if (!val) return [];
|
return String(val)
|
.split(",")
|
.map(item => item.trim())
|
.filter(Boolean);
|
};
|
|
const formatTransferRecordValue = (record, prop) => {
|
if (prop === "auditStatus") {
|
return getAuditStatusLabel(record?.[prop]);
|
}
|
|
const value = record?.[prop];
|
if (value === null || value === undefined || value === "") {
|
return "-";
|
}
|
|
return String(value);
|
};
|
|
const getTransferCardParams = (row) => {
|
const params = {
|
current: 1,
|
size: 100,
|
};
|
|
if (row?.id != null) {
|
params.workOrderId = row.id;
|
}
|
if (row?.workOrderNo) {
|
params.workOrderNo = row.workOrderNo;
|
}
|
if (row?.productMainId != null) {
|
params.productMainId = row.productMainId;
|
}
|
|
return params;
|
};
|
|
const showTransferCard = async (row) => {
|
transferCardRowData.value = row;
|
transferCardVisible.value = true;
|
transferCardRecords.value = [];
|
transferCardLoading.value = true;
|
|
try {
|
const res = await getProductionProductMain(getTransferCardParams(row));
|
transferCardRecords.value = res?.data?.records || res?.records || [];
|
} catch {
|
transferCardRecords.value = [];
|
showToast("加载报工审核记录失败");
|
} finally {
|
transferCardLoading.value = false;
|
}
|
};
|
|
const getPendingQty = (row) => {
|
const plan = Number(row?.planQuantity) || 0;
|
const complete = Number(row?.completeQuantity) || 0;
|
return Math.max(plan - complete, 0);
|
};
|
|
const isStarted = (row) => {
|
if (!row?.id) return false;
|
if (Number(row?.completeQuantity) > 0) return true;
|
if (row?.startProductTime) return true;
|
return String(row?.reportWork) === "1";
|
};
|
|
const isEnded = (row) => {
|
return getPendingQty(row) <= 0;
|
};
|
|
const canEndProduction = (row) => {
|
if (!row?.id) return false;
|
if (isEnded(row)) return false;
|
return true;
|
};
|
|
// 判断是否可以开始报工
|
const canStartProduction = (row) => {
|
if (!row?.id) return false;
|
if (getPendingQty(row) <= 0) return false;
|
if (isEnded(row)) return false;
|
if (isStarted(row)) return false;
|
return canStartProductionByUserIds(userStore.id, row);
|
|
};
|
|
// 根据userIds判断是否有用户可以报工
|
const canStartProductionByUserIds = (userId, row) => {
|
const team = row?.userIds || "";
|
if (!userId) return true;
|
if (!team) return true;
|
return String(team).includes(String(userId));
|
};
|
|
const handleStartProduction = (row) => {
|
console.log(userStore.id)
|
if (!canStartProduction(row)) return;
|
if (startSubmittingId.value) return;
|
|
uni.showModal({
|
title: "提示",
|
content: `确定开始报工?\n工单:${row.workOrderNo || "-"}`,
|
success: async (res) => {
|
if (!res.confirm) return;
|
startSubmittingId.value = row.id;
|
await ensureUserInfo();
|
uni.showLoading({ title: "提交中...", mask: true });
|
try {
|
const payload = { id: row.id, userId: userStore.id, userName: userStore.nickName };
|
const apiRes = await startProduction(payload);
|
if (apiRes?.code === 200) {
|
showToast("开始报工成功");
|
handleQuery();
|
} else {
|
showToast(apiRes?.msg || "开始报工失败");
|
}
|
} catch {
|
showToast("开始报工失败");
|
} finally {
|
uni.hideLoading();
|
startSubmittingId.value = null;
|
}
|
}
|
});
|
};
|
|
const formatDateTime = (timestamp) => {
|
const date = new Date(timestamp);
|
const y = date.getFullYear();
|
const m = String(date.getMonth() + 1).padStart(2, "0");
|
const d = String(date.getDate()).padStart(2, "0");
|
const h = String(date.getHours()).padStart(2, "0");
|
const min = String(date.getMinutes()).padStart(2, "0");
|
const s = String(date.getSeconds()).padStart(2, "0");
|
return `${y}-${m}-${d} ${h}:${min}:${s}`;
|
};
|
|
const openEndReport = async (row) => {
|
if (!canEndProduction(row)) return;
|
endReportRow.value = row;
|
await ensureUserInfo();
|
await ensureUserOptions();
|
await ensureDeviceOptions();
|
|
endReportForm.planQuantity = String(getPendingQty(row));
|
endReportForm.quantity = String(getPendingQty(row));
|
endReportForm.replenishQty = "0";
|
endReportForm.scrapQty = "0";
|
endReportForm.deviceLedgerId = "";
|
endReportForm.deviceName = "";
|
endReportForm.teamList = [];
|
teamCheckedIds.value = [];
|
|
endReportForm.userId = userStore.id || "";
|
endReportForm.userName = userStore.nickName || "";
|
endReportForm.workOrderId = row.id;
|
endReportForm.reportWork = row.reportWork;
|
endReportForm.productProcessRouteItemId = row.productProcessRouteItemId || "";
|
endReportForm.productMainId = row.productMainId ?? null;
|
|
endReportForm.auditUserId = "";
|
endReportForm.auditUserName = "";
|
|
endReportForm.startTime = row.startProductTime || "";
|
endReportForm.endTime = "";
|
startTimeValue.value = endReportForm.startTime ? new Date(endReportForm.startTime).getTime() : Date.now();
|
if (!endReportForm.startTime) {
|
endReportForm.startTime = formatDateTime(startTimeValue.value);
|
}
|
endTimeValue.value = Date.now();
|
endReportForm.endTime = formatDateTime(endTimeValue.value);
|
|
if (row?.deviceName) {
|
const matched = deviceOptions.value.find(d => String(d?.deviceName || "") === String(row.deviceName));
|
if (matched) {
|
endReportForm.deviceLedgerId = String(matched.id ?? "");
|
endReportForm.deviceName = String(matched.deviceName ?? "");
|
}
|
}
|
|
endReportVisible.value = true;
|
};
|
|
const closeEndReport = () => {
|
endReportVisible.value = false;
|
endReportRow.value = null;
|
};
|
|
const openAuditPicker = async () => {
|
await ensureUserOptions();
|
auditPickerVisible.value = true;
|
};
|
|
const onAuditSelect = (e) => {
|
endReportForm.auditUserId = String(e?.value ?? "");
|
endReportForm.auditUserName = String(e?.name ?? "");
|
auditPickerVisible.value = false;
|
};
|
|
const openDevicePicker = async () => {
|
await ensureDeviceOptions();
|
devicePickerVisible.value = true;
|
};
|
|
const onDeviceSelect = (e) => {
|
endReportForm.deviceLedgerId = String(e?.value ?? "");
|
endReportForm.deviceName = String(e?.name ?? "");
|
devicePickerVisible.value = false;
|
};
|
|
const openTeamPicker = async () => {
|
await ensureUserOptions();
|
teamCheckedIds.value = (endReportForm.teamList || []).map(i => String(i.userId));
|
teamPickerVisible.value = true;
|
};
|
|
const confirmTeamPicker = () => {
|
const ids = teamCheckedIds.value || [];
|
endReportForm.teamList = ids
|
.map(id => {
|
const u = userOptions.value.find(x => String(x.value) === String(id));
|
return { userId: String(id), userName: u?.name || "" };
|
})
|
.filter(i => i.userId);
|
teamPickerVisible.value = false;
|
};
|
|
const onStartTimeConfirm = (e) => {
|
const start = e.value;
|
endReportForm.startTime = formatDateTime(start);
|
startTimePickerVisible.value = false;
|
|
// 👉 自动给结束时间 +1小时
|
const end = start + 60 * 60 * 1000;
|
endTimeValue.value = end;
|
endReportForm.endTime = formatDateTime(end);
|
};
|
|
const onEndTimeConfirm = (e) => {
|
const end = e.value;
|
|
if (end <= startTimeValue.value) {
|
showToast("结束时间必须大于开始时间");
|
return;
|
}
|
|
endReportForm.endTime = formatDateTime(end);
|
endTimePickerVisible.value = false;
|
};
|
|
const submitEndReport = async () => {
|
if (!endReportRow.value) return;
|
|
const pendingQty = Number(endReportForm.planQuantity) || 0;
|
if (pendingQty <= 0) {
|
showToast("待生产数量为0,无法报工");
|
return;
|
}
|
|
const quantity = Number(endReportForm.quantity);
|
if (!Number.isFinite(quantity) || !Number.isInteger(quantity) || quantity < 1) {
|
showToast("本次生产数量必须为大于等于1的整数");
|
return;
|
}
|
if (quantity > pendingQty) {
|
showToast("本次生产数量不能超过待生产数量");
|
return;
|
}
|
|
const replenishQty = endReportForm.replenishQty === "" ? 0 : Number(endReportForm.replenishQty);
|
if (!Number.isFinite(replenishQty) || !Number.isInteger(replenishQty) || replenishQty < 0) {
|
showToast("补产数量必须为大于等于0的整数");
|
return;
|
}
|
|
const scrapQty = endReportForm.scrapQty === "" ? 0 : Number(endReportForm.scrapQty);
|
if (!Number.isFinite(scrapQty) || !Number.isInteger(scrapQty) || scrapQty < 0) {
|
showToast("报废数量必须为大于等于0的整数");
|
return;
|
}
|
if (!endReportForm.startTime) {
|
showToast("请选择开始时间");
|
return;
|
}
|
|
if (!endReportForm.endTime) {
|
showToast("请选择结束时间");
|
return;
|
}
|
|
const start = new Date(endReportForm.startTime).getTime();
|
const end = new Date(endReportForm.endTime).getTime();
|
|
if (end <= start) {
|
showToast("结束时间必须大于开始时间");
|
return;
|
}
|
|
if (!endReportForm.auditUserId) {
|
showToast("请选择审核人");
|
return;
|
}
|
|
if (!endReportForm.deviceLedgerId) {
|
showToast("请选择机台");
|
return;
|
}
|
|
await ensureUserInfo();
|
uni.showLoading({ title: "提交中...", mask: true });
|
try {
|
const submitData = {
|
...endReportForm,
|
planQuantity: pendingQty,
|
quantity,
|
replenishQty,
|
scrapQty,
|
userId: endReportForm.userId || userStore.id,
|
userName: endReportForm.userName || userStore.nickName,
|
auditUserId: endReportForm.auditUserId,
|
auditUserName: endReportForm.auditUserName,
|
deviceLedgerId: endReportForm.deviceLedgerId,
|
deviceName: endReportForm.deviceName,
|
};
|
const res = await addProductMain(submitData);
|
if (res?.code === 200) {
|
showToast("报工成功");
|
closeEndReport();
|
handleQuery();
|
} else {
|
showToast(res?.msg || "报工失败");
|
}
|
} catch {
|
showToast("报工失败");
|
} finally {
|
uni.hideLoading();
|
}
|
};
|
|
onLoad((options) => {
|
if (!options?.orderRow) return;
|
try {
|
const raw = decodeURIComponent(options.orderRow);
|
routeOrderRow.value = JSON.parse(raw);
|
} catch {
|
try {
|
routeOrderRow.value = JSON.parse(options.orderRow);
|
} catch {
|
routeOrderRow.value = null;
|
}
|
}
|
});
|
|
onShow(() => {
|
if (routeOrderRow.value?.id) {
|
loadSingleWorkOrder(routeOrderRow.value);
|
} else {
|
handleQuery();
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import '@/styles/sales-common.scss';
|
|
.work-order {
|
min-height: 100vh;
|
background: #f8f9fa;
|
}
|
|
.tag-type {
|
background-color: #e3f2fd;
|
color: #2196f3;
|
padding: 2px 8px;
|
border-radius: 4px;
|
font-size: 12px;
|
}
|
|
.progress-section {
|
margin: 15px 0;
|
.detail-label {
|
display: block;
|
margin-bottom: 8px;
|
font-size: 13px;
|
color: #666;
|
}
|
}
|
|
.item-actions {
|
display: flex;
|
justify-content: flex-end;
|
gap: 10px;
|
padding: 12px 0;
|
border-top: 1px solid #f5f5f5;
|
|
:deep(.up-button) {
|
margin: 0;
|
width: auto;
|
}
|
}
|
|
.qr-popup {
|
width: 90vw;
|
max-width: 900rpx;
|
max-height: 85vh; // 原来 80 → 加大
|
padding: 32rpx 28rpx;
|
background: #fff;
|
border-radius: 20rpx;
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
box-sizing: border-box;
|
}
|
.qr-title {
|
font-size: 30rpx;
|
font-weight: 600;
|
color: #222;
|
}
|
.qr-box {
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
width: 100%;
|
margin-top: 24rpx;
|
}
|
.qr-info {
|
margin-top: 16rpx;
|
font-size: 26rpx;
|
color: #666;
|
}
|
.transfer-records {
|
width: 100%;
|
margin-top: 28rpx;
|
}
|
.transfer-records-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
gap: 16rpx;
|
margin-bottom: 16rpx;
|
}
|
.transfer-records-title {
|
font-size: 26rpx;
|
font-weight: 600;
|
color: #222;
|
}
|
.transfer-records-count {
|
font-size: 22rpx;
|
color: #8a8a8a;
|
}
|
.transfer-records-loading,
|
.transfer-records-empty {
|
padding: 28rpx 0;
|
font-size: 24rpx;
|
color: #8a8a8a;
|
text-align: center;
|
}
|
.transfer-records-list {
|
max-height: 500rpx;
|
overflow: auto;
|
}
|
.transfer-record-item {
|
padding: 20rpx 22rpx;
|
border-radius: 16rpx;
|
background: #f7f8fa;
|
}
|
|
.transfer-record-item + .transfer-record-item {
|
margin-top: 16rpx;
|
}
|
.transfer-record-top {
|
display: flex;
|
justify-content: space-between;
|
align-items: flex-start;
|
gap: 24rpx;
|
}
|
.transfer-record-top-main {
|
display: flex;
|
flex-direction: column;
|
gap: 8rpx;
|
min-width: 0;
|
}
|
.transfer-record-no {
|
font-size: 28rpx;
|
font-weight: 600;
|
color: #222;
|
word-break: break-all;
|
}
|
.transfer-record-sub {
|
font-size: 22rpx;
|
color: #8a8a8a;
|
word-break: break-all;
|
}
|
.transfer-record-grid {
|
display: flex;
|
flex-wrap: wrap;
|
gap: 16rpx;
|
margin-top: 18rpx;
|
}
|
.transfer-record-cell {
|
width: 100%; // 原来一行两个 → 改成一行一个
|
}
|
.transfer-record-cell.is-wide {
|
width: 100%;
|
}
|
.transfer-record-label {
|
display: block;
|
margin-bottom: 8rpx;
|
font-size: 22rpx;
|
color: #8a8a8a;
|
}
|
.transfer-record-content {
|
min-height: 36rpx;
|
}
|
.transfer-record-value {
|
display: block;
|
font-size: 24rpx;
|
color: #222;
|
word-break: break-all;
|
}
|
.transfer-tag-list {
|
display: flex;
|
flex-wrap: wrap;
|
gap: 10rpx;
|
}
|
.transfer-name-tag {
|
padding: 6rpx 14rpx;
|
border-radius: 999rpx;
|
background: #e9f2ff;
|
color: #2f6bff;
|
font-size: 22rpx;
|
}
|
.audit-status-tag {
|
display: inline-flex;
|
align-items: center;
|
justify-content: center;
|
min-height: 40rpx;
|
padding: 0 16rpx;
|
border-radius: 999rpx;
|
font-size: 22rpx;
|
box-sizing: border-box;
|
}
|
.audit-status-info {
|
background: #edf1f5;
|
color: #6b7280;
|
}
|
.audit-status-success {
|
background: #e9f9ef;
|
color: #16a34a;
|
}
|
.audit-status-danger {
|
background: #feeeee;
|
color: #dc2626;
|
}
|
.audit-status-default {
|
background: #f4f4f5;
|
color: #606266;
|
}
|
|
.report-modal {
|
background: #fff;
|
max-height: 85vh;
|
display: flex;
|
flex-direction: column;
|
overflow: hidden;
|
}
|
.modal-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 14px 16px;
|
border-bottom: 1px solid #f0f0f0;
|
}
|
.modal-header-left {
|
display: flex;
|
flex-direction: column;
|
gap: 4px;
|
min-width: 0;
|
}
|
.modal-title {
|
font-size: 16px;
|
font-weight: 600;
|
}
|
.modal-subtitle {
|
font-size: 12px;
|
color: #8a8a8a;
|
max-width: 260px;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
.close-btn {
|
padding: 6px;
|
}
|
.modal-content {
|
flex: 1;
|
height: 0;
|
padding: 12px 12px 0;
|
background: #f7f8fa;
|
}
|
.modal-footer {
|
display: flex;
|
gap: 12px;
|
padding: 12px 16px;
|
border-top: 1px solid #f0f0f0;
|
background: #fff;
|
}
|
.report-summary {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 12px 14px;
|
background: #fff;
|
border-radius: 12px;
|
margin-bottom: 12px;
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
|
}
|
.summary-left {
|
display: flex;
|
flex-direction: column;
|
gap: 4px;
|
min-width: 0;
|
}
|
.summary-title {
|
font-size: 14px;
|
font-weight: 600;
|
color: #222;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
.summary-sub {
|
font-size: 12px;
|
color: #8a8a8a;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
.summary-right {
|
display: flex;
|
flex-direction: column;
|
align-items: flex-end;
|
gap: 2px;
|
padding-left: 12px;
|
}
|
.summary-num {
|
font-size: 18px;
|
font-weight: 700;
|
color: #2979ff;
|
}
|
.summary-label {
|
font-size: 11px;
|
color: #8a8a8a;
|
}
|
.form-section {
|
background: #fff;
|
border-radius: 12px;
|
padding: 10px 12px;
|
margin-bottom: 12px;
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
|
}
|
.section-title {
|
display: block;
|
font-size: 13px;
|
font-weight: 600;
|
color: #333;
|
margin: 2px 0 10px;
|
}
|
.team-modal {
|
background: #fff;
|
max-height: 80vh;
|
display: flex;
|
flex-direction: column;
|
overflow: hidden;
|
}
|
.team-content {
|
flex: 1;
|
height: 0;
|
padding: 12px 16px;
|
}
|
|
.qr-popup {
|
padding: 30px;
|
background-color: #fff;
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
|
.qr-title {
|
font-size: 18px;
|
font-weight: bold;
|
margin-bottom: 20px;
|
}
|
|
.qr-box {
|
padding: 20px;
|
background-color: #fff;
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
|
border-radius: 8px;
|
margin-bottom: 15px;
|
}
|
|
.qr-info {
|
font-size: 14px;
|
color: #666;
|
}
|
}
|
|
.no-data {
|
padding-top: 100px;
|
}
|
</style>
|