From bf8467516b08a9c1345b591d5a12174cb006b023 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期六, 17 一月 2026 11:23:12 +0800
Subject: [PATCH] fix: 报工功能调整
---
src/pages/index.vue | 84 +++++++++++++++++++++-------
src/pages/productionManagement/productionReport/index.vue | 83 ++++++++++++++++++++-------
src/api/productionManagement/productionReporting.js | 8 ++
3 files changed, 132 insertions(+), 43 deletions(-)
diff --git a/src/api/productionManagement/productionReporting.js b/src/api/productionManagement/productionReporting.js
index 710a02f..12c483d 100644
--- a/src/api/productionManagement/productionReporting.js
+++ b/src/api/productionManagement/productionReporting.js
@@ -17,6 +17,14 @@
params: query,
});
}
+// 鏍规嵁ID鑾峰彇宸ュ崟璇︽儏
+export function getProductWorkOrderById(query) {
+ return request({
+ url: "/productWorkOrder/getProductWorkOrderById",
+ method: "get",
+ params: query,
+ });
+}
// 鐢熶骇鎶ュ伐
export function productionReport(query) {
return request({
diff --git a/src/pages/index.vue b/src/pages/index.vue
index e1b0061..44595f9 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -192,6 +192,7 @@
<script setup>
import { ref, onMounted, nextTick, reactive } from "vue";
import { userLoginFacotryList } from "@/api/login";
+ import { getProductWorkOrderById } from "@/api/productionManagement/productionReporting";
import modal from "@/plugins/modal";
import useUserStore from "@/store/modules/user";
@@ -527,30 +528,74 @@
}
const getcode = () => {
uni.scanCode({
- success: res => {
+ success: async res => {
// 瑙f瀽浜岀淮鐮佸唴瀹�
const scanResult = res.result;
let orderRow = "";
- // 灏濊瘯浠庢壂鐮佺粨鏋滀腑鎻愬彇orderRow鍙傛暟
- try {
- // 澶勭悊娣峰悎鏍煎紡: http://...?orderRow={...}
- const orderRowStart = scanResult.indexOf("orderRow={");
- // 鎻愬彇浠巓rderRow={寮�濮嬬殑JSON鍐呭
- const jsonPart = scanResult.substring(orderRowStart + 9); // 9鏄�"orderRow=".length
- // 灏濊瘯鐩存帴浣跨敤杩欎釜JSON閮ㄥ垎
- orderRow = jsonPart;
- } catch (e) {
- console.error(e, "瑙f瀽澶辫触====????=====");
- orderRow = "";
+ // 鍒ゆ柇鎵弿缁撴灉鏄惁涓虹函鏁板瓧锛坕d锛�
+ const isNumericId = /^\d+$/.test(scanResult.trim());
+
+ if (isNumericId) {
+ // 濡傛灉鏄函鏁板瓧锛屾牴鎹� id 鑾峰彇宸ュ崟鏁版嵁
+ const workOrderId = scanResult.trim();
+ modal.loading("姝e湪鑾峰彇宸ュ崟淇℃伅...");
+ try {
+ const workRes = await getProductWorkOrderById({ id: workOrderId });
+ modal.closeLoading();
+
+ console.log("宸ュ崟鏌ヨ缁撴灉:", workRes);
+
+ if (workRes.code === 200 && workRes.data) {
+ // 鏂版帴鍙h繑鍥炵殑鏄崟涓璞★紝涓嶆槸鏁扮粍
+ const workData = workRes.data;
+ console.log("宸ュ崟鏁版嵁:", workData);
+
+ orderRow = JSON.stringify({
+ id: workData.id || workOrderId,
+ planQuantity: workData.planQuantity || workData.寰呯敓浜ф暟閲� || 0,
+ productProcessRouteItemId: workData.productProcessRouteItemId || workData.浜у搧宸ヨ壓璺嚎椤笽D || "",
+ });
+
+ console.log("鏋勯�犵殑orderRow:", orderRow);
+ } else {
+ modal.msgError("鏈壘鍒板搴旂殑宸ュ崟淇℃伅");
+ return;
+ }
+ } catch (error) {
+ modal.closeLoading();
+ console.error("鑾峰彇宸ュ崟淇℃伅澶辫触:", error);
+ modal.msgError("鑾峰彇宸ュ崟淇℃伅澶辫触: " + (error.message || "鏈煡閿欒"));
+ return;
+ }
+ } else {
+ // 濡傛灉涓嶆槸绾暟瀛楋紝灏濊瘯浠庢壂鐮佺粨鏋滀腑鎻愬彇orderRow鍙傛暟
+ try {
+ // 澶勭悊娣峰悎鏍煎紡: http://...?orderRow={...}
+ const orderRowStart = scanResult.indexOf("orderRow={");
+ if (orderRowStart !== -1) {
+ // 鎻愬彇浠巓rderRow={寮�濮嬬殑JSON鍐呭
+ const jsonPart = scanResult.substring(orderRowStart + 9); // 9鏄�"orderRow=".length
+ orderRow = jsonPart;
+ } else {
+ // 濡傛灉鐩存帴鏄疛SON瀛楃涓诧紝灏濊瘯瑙f瀽
+ orderRow = scanResult;
+ }
+ } catch (e) {
+ console.error(e, "瑙f瀽澶辫触====????=====");
+ orderRow = "";
+ }
+
+ // 楠岃瘉鏄惁涓烘湁鏁堢殑JSON
+ try {
+ JSON.parse(orderRow);
+ } catch (error) {
+ modal.msgError("璁㈠崟瑙f瀽澶辫触锛岃妫�鏌ヤ簩缁寸爜鏍煎紡");
+ return;
+ }
}
+
console.log(orderRow, "orderRow======@@@@@@@@");
- try {
- JSON.parse(orderRow);
- } catch (error) {
- modal.msgError("璁㈠崟瑙f瀽澶辫触");
- return;
- }
// 鎵爜鎴愬姛鍚庤烦杞埌鐢熶骇鎶ュ伐椤甸潰锛屽苟浼犻�抩rderRow鍙傛暟
uni.navigateTo({
url: `/pages/productionManagement/productionReport/index?orderRow=${orderRow}`,
@@ -561,9 +606,6 @@
title: "鎵爜澶辫触",
icon: "none",
});
- // uni.navigateTo({
- // url: `/pages/productionManagement/productionReport/index`,
- // });
},
});
};
diff --git a/src/pages/productionManagement/productionReport/index.vue b/src/pages/productionManagement/productionReport/index.vue
index f60eba5..c528611 100644
--- a/src/pages/productionManagement/productionReport/index.vue
+++ b/src/pages/productionManagement/productionReport/index.vue
@@ -35,7 +35,9 @@
required>
<u-input v-model="form.userName"
placeholder="璇烽�夋嫨鐢熶骇浜�"
- readonly />
+ readonly
+ @click="openProducerPicker"
+ suffix-icon="arrow-down" />
</u-form-item>
</view>
<!-- 浣跨敤FooterButtons缁勪欢 -->
@@ -55,7 +57,7 @@
</template>
<script setup>
- import { ref, onMounted } from "vue";
+ import { ref, nextTick } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import FooterButtons from "@/components/FooterButtons.vue";
@@ -67,35 +69,52 @@
};
import { addProductMain } from "@/api/productionManagement/productionReporting";
import { getInfo } from "@/api/login";
+ import { userListNoPageByTenantId } from "@/api/system/user";
// 琛ㄥ崟寮曠敤
const formRef = ref();
// 琛ㄥ崟鏁版嵁
let form = ref({
- planQuantity: 0,
- quantity: 0,
+ planQuantity: "",
+ quantity: "",
userName: "",
workOrderId: "",
- reportWork: "",
productProcessRouteItemId: "",
userId: "",
- productMainId: null,
+ schedulingUserId: "",
});
- let schedulingUserName = ref("");
-
- // 鏃ユ湡閫夋嫨鍣ㄧ姸鎬�
- const showEnterDatePicker = ref(false);
- const enterDateValue = ref(Date.now());
// 鐢熶骇浜洪�夋嫨鍣ㄧ姸鎬�
const showProducerPicker = ref(false);
const producerList = ref([]);
+ // 鎵撳紑鐢熶骇浜洪�夋嫨鍣�
+ const openProducerPicker = async () => {
+ if (producerList.value.length === 0) {
+ // 濡傛灉鍒楄〃涓虹┖锛屽厛鍔犺浇鐢ㄦ埛鍒楄〃
+ try {
+ const res = await userListNoPageByTenantId();
+ const users = res.data || [];
+ // 杞崲涓� action-sheet 闇�瑕佺殑鏍煎紡
+ producerList.value = users.map(user => ({
+ name: user.nickName || user.userName,
+ value: user.userId,
+ }));
+ } catch (error) {
+ console.error("鍔犺浇鐢ㄦ埛鍒楄〃澶辫触:", error);
+ showToast("鍔犺浇鐢ㄦ埛鍒楄〃澶辫触");
+ return;
+ }
+ }
+ showProducerPicker.value = true;
+ };
+
// 鐢熶骇浜洪�夋嫨纭
const onProducerConfirm = e => {
form.value.schedulingUserId = e.value;
- schedulingUserName.value = e.name;
+ form.value.userName = e.name;
+ form.value.userId = e.value; // 鍚屾椂鏇存柊 userId
showProducerPicker.value = false;
};
@@ -115,14 +134,28 @@
showToast("璇疯緭鍏ユ湰娆$敓浜ф暟閲�");
return;
}
- if (form.value.quantity > form.value.planQuantity) {
+ if (!form.value.schedulingUserId) {
+ submitting.value = false;
+ showToast("璇烽�夋嫨鐢熶骇浜�");
+ return;
+ }
+ // 杞崲涓烘暟瀛楄繘琛屾瘮杈�
+ const quantity = Number(form.value.quantity);
+ const planQuantity = Number(form.value.planQuantity);
+ if (quantity > planQuantity) {
submitting.value = false;
showToast("鏈鐢熶骇鏁伴噺涓嶈兘澶т簬寰呯敓浜ф暟閲�");
return;
}
- console.log(form.value, "form.value");
+ // 鍑嗗鎻愪氦鏁版嵁锛岀‘淇濇暟閲忓瓧娈典负鏁板瓧绫诲瀷
+ const submitData = {
+ ...form.value,
+ quantity: Number(form.value.quantity),
+ planQuantity: Number(form.value.planQuantity) || 0,
+ };
+ console.log(submitData, "submitData");
- addProductMain(form.value).then(res => {
+ addProductMain(submitData).then(res => {
if (res.code === 200) {
showToast("鎶ュ伐鎴愬姛");
submitting.value = false;
@@ -141,19 +174,25 @@
console.log(options, "options");
try {
const orderRow = JSON.parse(options.orderRow);
+ console.log("鏋勯�犵殑orderRow:", orderRow);
console.log(orderRow, "orderRow======########");
- form.value.planQuantity = orderRow.planQuantity;
- form.value.quantity = orderRow.quantity;
- form.value.productProcessRouteItemId = orderRow.productProcessRouteItemId;
- form.value.workOrderId = orderRow.id;
- form.value.reportWork = orderRow.reportWork;
- form.value.productMainId = orderRow.productMainId;
+ // 纭繚 planQuantity 杞崲涓哄瓧绗︿覆锛屼互渚垮湪 u-input 涓纭樉绀�
+ form.value.planQuantity = orderRow.planQuantity != null ? String(orderRow.planQuantity) : "";
+ form.value.productProcessRouteItemId = orderRow.productProcessRouteItemId || "";
+ form.value.workOrderId = orderRow.id || "";
getInfo().then(res => {
+ // 榛樿浣跨敤褰撳墠鐧诲綍鐢ㄦ埛锛屼絾鍏佽鐢ㄦ埛淇敼
form.value.userId = res.user.userId;
form.value.userName = res.user.userName;
+ form.value.schedulingUserId = res.user.userId;
+ });
+ // 浣跨敤 nextTick 纭繚 DOM 鏇存柊
+ nextTick(() => {
+ console.log("form.value after assignment:", form.value);
});
} catch (error) {
- modal.msgError("璁㈠崟瑙f瀽澶辫触");
+ console.error("璁㈠崟瑙f瀽澶辫触:", error);
+ showToast("璁㈠崟瑙f瀽澶辫触");
goBack();
return;
}
--
Gitblit v1.9.3