From e0fc86fda41a8777a0cec5a9de7aa9f1474f5dc8 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期四, 08 十月 2026 17:09:52 +0800
Subject: [PATCH] fix: 库存操作原型绘制。单丝领用,添加字段
---
src/pages/production/twist/receive/plate/index.vue | 439 +++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 363 insertions(+), 76 deletions(-)
diff --git a/src/pages/production/twist/receive/plate/index.vue b/src/pages/production/twist/receive/plate/index.vue
index 63a768e..9460126 100644
--- a/src/pages/production/twist/receive/plate/index.vue
+++ b/src/pages/production/twist/receive/plate/index.vue
@@ -1,36 +1,61 @@
<template>
- <view class="list">
+ <view class="list_box">
<z-paging
ref="pagingRef"
- v-model="cardList"
+ v-model="plateData"
:fixed="false"
:auto-show-back-to-top="true"
+ :loading-more-enabled="false"
@query="getList"
>
<template #top>
- <CardTitle title="鐩樺叿棰嗙敤" :hideAction="true" :full="false" @action="addReport" />
- </template>
- <wd-card v-for="(item, index) in cardList" :key="index" type="rectangle" custom-class="round">
- <template #title>
- <view class="flex justify-between">
- <view>
- <wd-icon name="a-rootlist" color="#0D867F"></wd-icon>
- <text class="text-[#252525] ml-2 font-medium">{{ item.diskMaterial }}</text>
+ <CardTitle title="鐩樺叿棰嗙敤" :hideAction="false">
+ <template #action>
+ <view class="action-wrap">
+ <!-- 宸ュ崟瑕佹眰鐨勭洏鍏疯鏍煎瀷鍙� / 鏉愯川锛氬睍绀哄湪鎵爜锛堟柊澧烇級鎸夐挳鏃� -->
+ <view class="reel-defaults">
+ <text class="reel-default-item">瑙勬牸鍨嬪彿锛歿{ defaultDishModel || "-" }}</text>
+ <text class="reel-default-item">鏉愯川锛歿{ defaultDishMaterial || "-" }}</text>
+ </view>
+ <wd-button type="icon" icon="scan" color="#0D867F" @click="openScan"></wd-button>
</view>
- <view class="text-[#A8A8A8]" @click="toEdit(item.id)">缂栬緫</view>
- </view>
- </template>
- <ProductionCard :data="cardAttr" :value="item" color="#0D867F" />
- </wd-card>
- </z-paging>
- <wd-popup v-model="addDialog.visible" position="bottom" custom-class="yl-popup">
- <view class="action px-3">
- <wd-button type="text" @click="cancelAdd">鍙栨秷</wd-button>
- <wd-button type="text" @click="submitAdd">纭畾</wd-button>
+ </template>
+ </CardTitle>
+ <view class="scan-tip">璇锋壂鎻忕洏鍏锋爣绛句簩缁寸爜棰嗙敤鐩樺叿锛堢洏鍏烽渶鍏堝湪鐩樺叿绉伴噸鍙拌处涓О閲嶏級</view>
+ </template>
+
+ <view class="content">
+ <wd-card
+ v-for="(item, index) in plateData"
+ :key="item.id ?? item.dishCode ?? index"
+ type="rectangle"
+ custom-class="round"
+ >
+ <template #title>
+ <view class="flex justify-between">
+ <view>
+ <wd-icon name="a-rootlist" color="#0D867F"></wd-icon>
+ <text class="text-[#252525] ml-2 font-medium">{{ item.diskMaterial }}</text>
+ </view>
+ <view class="flex items-center">
+ <text v-if="!item.id" class="text-[#E6A23C] mr-3 text-[12px]">寰呬繚瀛�</text>
+ <view v-if="!item.id" class="text-[#A8A8A8]" @click="removeDish(item)">绉婚櫎</view>
+ <view v-else class="text-[#A8A8A8]" @click="toEdit(item)">缂栬緫</view>
+ </view>
+ </view>
+ </template>
+ <ProductionCard :data="cardAttr" :value="item" color="#0D867F" />
+ </wd-card>
</view>
- <PlateForm ref="addFormRef" mode="add" @refresh="reloadList" />
- </wd-popup>
- <wd-popup v-model="editDialog.visible" position="bottom" custom-class="yl-popup">
+ </z-paging>
+
+ <view class="save-footer">
+ <wd-button block @click="save">
+ <text class="text-[#fff]">淇濆瓨</text>
+ </wd-button>
+ </view>
+
+ <wd-popup v-model="editDialog.visible" position="bottom" custom-class="yl-popup" :z-index="30">
<view class="action px-3">
<wd-button type="text" @click="cancelEdit">鍙栨秷</wd-button>
<wd-button type="text" @click="submitEdit">纭畾</wd-button>
@@ -42,6 +67,8 @@
@refresh="reloadList"
/>
</wd-popup>
+
+ <Scan ref="scanRef" emitName="scanPlate" />
<wd-toast />
</view>
</template>
@@ -51,28 +78,37 @@
import ProductionCard from "../../../components/ProductionCard.vue";
import { useToast } from "wot-design-uni";
import PlateForm from "./form.vue";
-import { onLoad, onShow } from "@dcloudio/uni-app";
+import { onLoad, onUnload, onShow, onHide } from "@dcloudio/uni-app";
import ManageApi from "@/api/product/manage";
+import TwistApi from "@/api/product/twist";
import zPaging from "@/components/z-paging/z-paging.vue";
+import Scan from "@/components/scan/index.vue";
const paramsId = ref();
const pagingRef = ref();
-const addFormRef = ref();
const editFormRef = ref();
+const scanRef = ref();
const toast = useToast();
-const addDialog = reactive({
- visible: false,
-});
const editDialog = reactive({
visible: false,
currentItem: null as any,
editId: undefined as number | undefined,
});
-const cardList = ref<any[]>([]);
+const plateData = ref<any[]>([]);
+
+const isPageVisible = ref(true);
+
+/** 宸ュ崟瑕佹眰鐨勭洏鍏疯鏍煎瀷鍙� / 鏉愯川锛堝睍绀哄湪鏂板鎸夐挳鏃侊紝棰嗙敤鍚庝綔涓鸿鏍煎瀷鍙烽粯璁ゅ�硷級 */
+const defaultDishModel = ref("");
+const defaultDishMaterial = ref("");
const cardAttr = ref<any[]>([
{
- label: "灏哄",
+ label: "鐩樺叿缂栧彿",
+ prop: "dishCode",
+ },
+ {
+ label: "瑙勬牸鍨嬪彿",
prop: "model",
},
{
@@ -88,48 +124,39 @@
label: "鍗曚綅",
prop: "unit",
},
- {
- label: "鍘傚",
- prop: "supplier",
- span: 14,
- },
]);
-const toEdit = (id: number) => {
- // 鎵惧埌闇�瑕佺紪杈戠殑椤�
- const itemToEdit = cardList.value.find((item) => item.id === id);
- if (itemToEdit) {
- editDialog.currentItem = itemToEdit;
- editDialog.editId = id;
- editDialog.visible = true;
- }
+/** 缁熶竴鐩樺叿鏁版嵁锛氱洏鍏风紪鍙峰吋瀹� weighingCode锛屾暟閲�/鍗曚綅琛ラ粯璁ゅ�� */
+const normalizeDish = (item: any) => ({
+ ...item,
+ dishCode: item?.dishCode ?? item?.weighingCode ?? "",
+ weighingCode: item?.weighingCode ?? item?.dishCode ?? "",
+ amount: item?.amount ?? 1,
+ unit: item?.unit ?? "鍙�",
+});
+
+/** 鏄惁宸茶棰嗙敤锛氬吋瀹� 1/"1"/true/"鏄�" */
+const isReceived = (row: any) => {
+ const value = row?.received ?? row?.isReceived;
+ return [true, 1, "1", "true", "鏄�"].includes(value);
};
-const addReport = () => {
- // 閲嶇疆琛ㄥ崟鏁版嵁
- if (addFormRef.value) {
- addFormRef.value.resetFormData();
- }
- addDialog.visible = true;
+const toEdit = (item: any) => {
+ editDialog.currentItem = item;
+ editDialog.editId = item?.id;
+ editDialog.visible = true;
};
-const submitAdd = async () => {
- toast.show("鎻愪氦");
- const success = await addFormRef.value.submit();
- if (success) {
- addDialog.visible = false;
+/** 绉婚櫎灏氭湭淇濆瓨鐨勬壂鐮佽褰� */
+const removeDish = (item: any) => {
+ const index = plateData.value.findIndex((row) => row.dishCode === item.dishCode && !row.id);
+ if (index > -1) {
+ plateData.value.splice(index, 1);
}
-};
-
-const cancelAdd = () => {
- toast.show("鍙栨秷");
- addDialog.visible = false;
- // 娓呯┖琛ㄥ崟鏁版嵁
- addFormRef.value?.$refs?.form?.resetFields();
};
const submitEdit = async () => {
- const success = await editFormRef.value.submitEdit(cardList.value, editDialog.editId);
+ const success = await editFormRef.value.submitEdit(plateData.value, editDialog.editId);
if (success) {
editDialog.visible = false;
reloadList();
@@ -137,33 +164,268 @@
};
const cancelEdit = () => {
- toast.show("鍙栨秷");
editDialog.visible = false;
};
const reloadList = () => {
- pagingRef.value.refresh();
+ pagingRef.value?.refresh();
};
const getList = async () => {
- const { code, data } = await ManageApi.getStrandedWireDish({
- wireId: paramsId.value,
- type: "鐩樺叿",
- });
- if (code == 200) {
- pagingRef.value.complete(data);
+ try {
+ const { code, data } = await ManageApi.getStrandedWireDish({
+ wireId: paramsId.value,
+ type: "鐩樺叿",
+ });
+ if (code == 200) {
+ const list = (Array.isArray(data) ? data : []).map(normalizeDish);
+ pagingRef.value.complete(list);
+ } else {
+ pagingRef.value.complete([]);
+ }
+ } catch (error) {
+ pagingRef.value.complete([]);
}
};
+
+// ============ 鎵爜鏂板鐩樺叿 ============
+/** 瑙f瀽鎵爜鍐呭锛氬吋瀹� JSON 涓庣函鏂囨湰绉伴噸缂栧彿 */
+const parseScanCode = (payload: any) => {
+ const raw = payload?.code ?? payload;
+ if (raw === undefined || raw === null) return null;
+ if (typeof raw === "object") return raw;
+ const text = String(raw).trim();
+ if (!text) return null;
+ if (text.startsWith("{")) {
+ try {
+ return JSON.parse(text);
+ } catch {
+ // JSON 瑙f瀽澶辫触鏃舵寜绾枃鏈О閲嶇紪鍙峰鐞�
+ }
+ }
+ return { weighingCode: text };
+};
+
+/** 浠庢壂鐮佸唴瀹归噷鍙栫洏鍏凤紙绉伴噸锛夌紪鍙� */
+const pickWeighingCode = (data: any) => {
+ const keys = [
+ "weighingCode",
+ "weighingNo",
+ "dishCode",
+ "receiveDishNo",
+ "batchCode",
+ "code",
+ "绉伴噸缂栧彿",
+ "鐩樺叿缂栧彿",
+ "鐩樺彿",
+ ];
+ for (const key of keys) {
+ const value = data?.[key];
+ if (value !== undefined && value !== null && String(value).trim() !== "") {
+ return String(value).trim();
+ }
+ }
+ return "";
+};
+
+/** 鍙拌处琛� 鈫� 鐩樺叿棰嗙敤琛� */
+const buildDishFromLedger = (record: any) =>
+ normalizeDish({
+ wireId: paramsId.value,
+ diskMaterial: record?.diskMaterial ?? undefined,
+ // 瑙勬牸鍨嬪彿鍙栬鐩樺叿鍦ㄧО閲嶅彴璐﹂噷鐨勮鏍煎瀷鍙�
+ model: record?.specificationModel ?? undefined,
+ weight: record?.weight ?? undefined,
+ amount: 1,
+ unit: "鍙�",
+ dishCode: String(record?.weighingCode ?? "").trim(),
+ weighingCode: String(record?.weighingCode ?? "").trim(),
+ type: "鐩樺叿",
+ });
+
+const getScanCode = async (payload: any) => {
+ if (!isPageVisible.value) return;
+
+ const parsed = parseScanCode(payload);
+ if (!parsed) {
+ toast.error("鎵爜鍐呭涓虹┖锛岃閲嶆柊鎵爜");
+ return;
+ }
+
+ const code = pickWeighingCode(parsed);
+ if (!code) {
+ toast.error("浜岀淮鐮佹棤娉曡瘑鍒洏鍏风紪鍙凤紝璇锋洿鎹簩缁寸爜");
+ return;
+ }
+
+ if (plateData.value.some((item) => String(item.dishCode ?? item.weighingCode ?? "") === code)) {
+ toast.error("璇ョ洏鍏峰凡鍦ㄦ湰鍗曢鐢ㄥ垪琛ㄤ腑锛岃鍕块噸澶嶆壂鐮�");
+ return;
+ }
+
+ try {
+ const { data } = await TwistApi.queryBobbinWeighingPage({
+ current: 1,
+ size: 50,
+ weighingCode: code,
+ });
+ const pageData: any = data ?? {};
+ const records =
+ pageData?.records ??
+ pageData?.list ??
+ pageData?.rows ??
+ (Array.isArray(pageData) ? pageData : []);
+ const exact = (records || []).find((row: any) => String(row?.weighingCode ?? "") === code);
+ const record = exact ?? (records?.length === 1 ? records[0] : null);
+
+ if (!record) {
+ toast.error("鐩樺叿绉伴噸鍙拌处涓湭鎵惧埌璇ョ洏鍏凤紝璇峰厛鍦ㄧ洏鍏风О閲嶅彴璐︿腑绉伴噸");
+ return;
+ }
+ if (isReceived(record)) {
+ toast.error("璇ョ洏鍏峰凡琚鐢紝璇锋洿鎹㈢洏鍏�");
+ return;
+ }
+
+ plateData.value.push(buildDishFromLedger(record));
+ toast.success("鎵爜鎴愬姛锛岃鐐瑰嚮淇濆瓨鎻愪氦");
+ } catch (error) {
+ // 璇锋眰灞傚凡缁熶竴鎻愮ず澶辫触鍘熷洜
+ }
+};
+
+const openScan = () => {
+ scanRef.value?.triggerScan();
+};
+
+// ============ 淇濆瓨 ============
+const isNewDish = (item: any) => item?.id === undefined || item?.id === null;
+
+const save = () => {
+ const newCount = plateData.value.filter(isNewDish).length;
+ if (!newCount) {
+ toast.error("娌℃湁鏂版壂鐮佺殑鐩樺叿闇�瑕佷繚瀛�");
+ return;
+ }
+ uni.showModal({
+ title: "鎻愮ず",
+ content: `纭淇濆瓨 ${newCount} 鏉$洏鍏烽鐢ㄦ暟鎹悧锛焋,
+ success: async (res) => {
+ if (res.confirm) {
+ await handleConfirmSave();
+ }
+ },
+ });
+};
+
+const handleConfirmSave = async () => {
+ const newData = plateData.value.filter(isNewDish);
+ if (newData.length === 0) {
+ toast.error("娌℃湁鏂版壂鐮佺殑鐩樺叿闇�瑕佷繚瀛�");
+ return;
+ }
+ const invalid = newData.find((item) => !item.dishCode || !item.diskMaterial);
+ if (invalid) {
+ toast.error(`${invalid.dishCode || "鐩樺叿"}锛氱洏鍏锋暟鎹笉瀹屾暣锛岃閲嶆柊鎵爜`);
+ return;
+ }
+
+ const { code, msg } = await TwistApi.addStrandedWireDish(newData);
+ if (code == 200) {
+ toast.success(msg || "淇濆瓨鎴愬姛");
+ pagingRef.value?.refresh();
+ } else {
+ toast.error(msg || "淇濆瓨澶辫触");
+ }
+};
+
+/**
+ * 鍙栧伐鍗曡姹傜殑鐩樺叿鍨嬪彿 / 鐩樺叿鏉愯川锛堝睍绀哄湪鎵爜鎸夐挳鏃侊級
+ * 鍙彇鐩樺叿鐩稿叧瀛楁 diskModel / diskMaterial锛屼笉鎷夸骇鍝佽鏍� model 鍏滃簳
+ */
+const loadDishDefaults = async () => {
+ if (!paramsId.value) return;
+ try {
+ const { data } = await TwistApi.getTwistDetailById({ id: paramsId.value });
+ defaultDishModel.value = data?.diskModel || "";
+ defaultDishMaterial.value = data?.diskMaterial || "";
+ } catch (error) {
+ // 鍙栦笉鍒板氨灞曠ず "-"锛屼笉闃诲棰嗙敤
+ }
+};
+
onLoad((options: any) => {
- paramsId.value = options.id;
+ uni.$off("scanPlate", getScanCode);
+ uni.$on("scanPlate", getScanCode);
+ paramsId.value = options?.id;
+ loadDishDefaults();
+});
+
+// 鐩樺叿棰嗙敤鏄�岃姱绾�/鍗曚笣/鐩樺叿銆嶉〉绛句箣涓�锛岀粍浠跺彲鑳芥櫄浜庨〉闈� onShow 鎵嶆寕杞斤紝
+// 杩欓噷鍏滃簳缃负鍙锛岄伩鍏嶆壂鐮佽璇垽涓轰笉鍙鑰岄潤榛樹涪寮冦��
+onMounted(() => {
+ isPageVisible.value = true;
+});
+
+onShow(() => {
+ isPageVisible.value = true;
+});
+
+onHide(() => {
+ isPageVisible.value = false;
+});
+
+onUnload(() => {
+ uni.$off("scanPlate", getScanCode);
+ isPageVisible.value = false;
});
</script>
<style lang="scss" scoped>
-.list {
- height: calc(100vh - 120px);
- padding: 12px;
+.list_box {
+ height: calc(100vh - 160px);
background: #f3f9f8;
+ display: flex;
+ flex-direction: column;
+}
+
+.action {
+ display: flex;
+ justify-content: space-between;
+}
+
+:deep(.wd-button__content) {
+ color: #0d867f;
+}
+
+.scan-tip {
+ padding: 0 12px 8px;
+ font-size: 12px;
+ color: #8a8a8a;
+}
+
+.action-wrap {
+ display: flex;
+ align-items: center;
+}
+
+.reel-defaults {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-end;
+ margin-right: 8px;
+}
+
+.reel-default-item {
+ font-size: 11px;
+ line-height: 16px;
+ color: #646874;
+}
+
+.content {
+ width: 100%;
+ padding-bottom: 76px;
+ box-sizing: border-box;
:deep() {
.round {
@@ -172,8 +434,33 @@
}
}
-.action {
+.save-footer {
+ position: fixed;
+ right: 0;
+ bottom: 0;
+ left: 0;
+ z-index: 20;
+ padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
+ background: #ffffff;
+ border-top: 1px solid #eeeeee;
+ box-shadow: 0 -2px 10px rgb(0 0 0 / 6%);
+}
+
+:deep(.zp-paging-container) {
+ background: transparent !important;
+ flex: 1;
display: flex;
- justify-content: space-between;
+ flex-direction: column;
+}
+
+:deep(.zp-paging-container-content) {
+ background: transparent !important;
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+}
+
+:deep(.zp-paging-container-top) {
+ flex-shrink: 0;
}
</style>
--
Gitblit v1.9.3