| | |
| | | <template> |
| | | <view class="invoice-add"> |
| | | <!-- 使用通用页面头部组件 --> |
| | | <PageHeader title="生产报工" |
| | | <PageHeader :title="pageTitle" |
| | | @back="goBack" /> |
| | | <!-- 表单内容 --> |
| | | <u-form @submit="submitForm" |
| | |
| | | placeholder="自动填充" |
| | | disabled /> |
| | | </u-form-item> |
| | | <u-form-item label="本次生产数量" |
| | | <u-form-item v-if="!isStartReport" |
| | | label="本次生产数量" |
| | | prop="quantity" |
| | | required> |
| | | <u-input v-model="form.quantity" |
| | | placeholder="请输入" |
| | | type="number" /> |
| | | </u-form-item> |
| | | <u-form-item label="报废数量" |
| | | <u-form-item v-if="!isStartReport" |
| | | label="报废数量" |
| | | prop="scrapQty"> |
| | | <u-input v-model="form.scrapQty" |
| | | placeholder="请输入" |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, nextTick } from "vue"; |
| | | import { computed, ref, nextTick } from "vue"; |
| | | import { onLoad } from "@dcloudio/uni-app"; |
| | | import FooterButtons from "@/components/FooterButtons.vue"; |
| | | |
| | |
| | | icon: "none", |
| | | }); |
| | | }; |
| | | import { addProductMain } from "@/api/productionManagement/productionReporting"; |
| | | import { addProductMain ,getReportState} from "@/api/productionManagement/productionReporting"; |
| | | import { getInfo } from "@/api/login"; |
| | | import { userListNoPageByTenantId } from "@/api/system/user"; |
| | | |
| | |
| | | productProcessRouteItemId: "", |
| | | userId: "", |
| | | schedulingUserId: "", |
| | | }); |
| | | |
| | | // 报工状态(来自 reportState 接口) |
| | | const reportState = ref({}); |
| | | |
| | | // 开始报工:隐藏“本次生产数量/报废数量” |
| | | const isStartReport = computed(() => Number(reportState.value?.state) === 1); |
| | | |
| | | const pageTitle = computed(() => { |
| | | const state = Number(reportState.value?.state); |
| | | if (state === 1) return "开始报工"; |
| | | if (state === 2) return "结束报工"; |
| | | if (state === 3) return "报工完成"; |
| | | return "生产报工"; |
| | | }); |
| | | |
| | | // 生产人选择器状态 |
| | |
| | | // 提交表单 |
| | | const submitForm = async () => { |
| | | submitting.value = true; |
| | | const planQuantity = Number(form.value.planQuantity) || 0; |
| | | if (!form.value.schedulingUserId) { |
| | | submitting.value = false; |
| | | showToast("请选择生产人"); |
| | | return; |
| | | } |
| | | |
| | | // 开始报工:不需要填写数量/报废数量 |
| | | let quantity = 0; |
| | | let scrapQty = 0; |
| | | if (!isStartReport.value) { |
| | | // 校验表单 |
| | | if (!form.value.quantity) { |
| | | submitting.value = false; |
| | | showToast("请输入本次生产数量"); |
| | | return; |
| | | } |
| | | if (!form.value.schedulingUserId) { |
| | | submitting.value = false; |
| | | showToast("请选择生产人"); |
| | | return; |
| | | } |
| | | |
| | | // 转换为数字进行比较 |
| | | const quantity = Number(form.value.quantity) || 0; |
| | | const scrapQty = Number(form.value.scrapQty) || 0; |
| | | const planQuantity = Number(form.value.planQuantity); |
| | | quantity = Number(form.value.quantity) || 0; |
| | | scrapQty = Number(form.value.scrapQty) || 0; |
| | | |
| | | // 验证生产数量和报废数量的和不能超过待生产数量 |
| | | if (quantity + scrapQty > planQuantity) { |
| | | submitting.value = false; |
| | |
| | | showToast("本次生产数量不能大于待生产数量"); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 准备提交数据,确保数量字段为数字类型 |
| | | const submitData = { |
| | | ...form.value, |
| | | quantity: Number(form.value.quantity), |
| | | scrapQty: Number(form.value.scrapQty) || 0, |
| | | planQuantity: Number(form.value.planQuantity) || 0, |
| | | quantity, |
| | | scrapQty, |
| | | planQuantity, |
| | | }; |
| | | console.log(submitData, "submitData"); |
| | | |
| | |
| | | getInfo().then(res => { |
| | | // 默认使用当前登录用户 |
| | | form.value.userId = res.user.userId; |
| | | form.value.userName = res.user.userName; |
| | | // 回显展示名称优先使用 nickName;若后端不返回则兜底用 userName |
| | | // 避免使用可能为 id 的 userName 字段导致“回显的是 id” |
| | | form.value.userName = res.user.nickName || res.user.userName; |
| | | form.value.schedulingUserId = res.user.userId; |
| | | }); |
| | | return; |
| | | } |
| | | try { |
| | | const orderRow = JSON.parse(options.orderRow); |
| | | // options.orderRow 来自路由参数,可能是 encodeURIComponent 后的字符串 |
| | | const orderRowRaw = |
| | | typeof options.orderRow === "string" ? options.orderRow : String(options.orderRow); |
| | | let orderRowStr = orderRowRaw; |
| | | try { |
| | | orderRowStr = decodeURIComponent(orderRowRaw); |
| | | } catch (e) { |
| | | // 若已经是未编码的 JSON,则无需解码 |
| | | } |
| | | const orderRow = JSON.parse(orderRowStr); |
| | | console.log("构造的orderRow:", orderRow); |
| | | console.log(orderRow, "orderRow======########"); |
| | | // 确保 planQuantity 转换为字符串,以便在 u-input 中正确显示 |
| | | form.value.planQuantity = orderRow.planQuantity != null ? String(orderRow.planQuantity) : ""; |
| | | form.value.productProcessRouteItemId = orderRow.productProcessRouteItemId || ""; |
| | | form.value.workOrderId = orderRow.id || ""; |
| | | form.value.workOrderId = orderRow.workOrderId || ""; |
| | | |
| | | // 若扫码结果已携带 todayReportState,则先本地渲染标题/显隐 |
| | | if (orderRow.todayReportState != null) { |
| | | reportState.value = { state: Number(orderRow.todayReportState) }; |
| | | } |
| | | getInfo().then(res => { |
| | | // 默认使用当前登录用户,但允许用户修改 |
| | | form.value.userId = res.user.userId; |
| | | form.value.userName = res.user.userName; |
| | | // 回显展示名称优先使用 nickName;若后端不返回则兜底用 userName |
| | | form.value.userName = res.user.nickName || res.user.userName; |
| | | form.value.schedulingUserId = res.user.userId; |
| | | }); |
| | | |
| | | // 根据扫码传入的 orderRow 获取报工状态 |
| | | getReportState(orderRow) |
| | | .then(res => { |
| | | if (res.code === 200) { |
| | | reportState.value = res.data || {}; |
| | | } else { |
| | | // 状态获取失败时,不影响页面正常录入(兜底显示输入项) |
| | | console.warn("getReportState 返回非200:", res); |
| | | } |
| | | }) |
| | | .catch(err => { |
| | | console.error("获取报工状态失败:", err); |
| | | }); |
| | | |
| | | // 使用 nextTick 确保 DOM 更新 |
| | | nextTick(() => { |
| | | console.log("form.value after assignment:", form.value); |