From a8cc9d60a80afd7362e1d0fd31fb4307a6e04e2e Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期五, 31 七月 2026 10:22:14 +0800
Subject: [PATCH] fix: 芯线分层领用
---
src/pages/production/twist/receive/steelCore/index.vue | 489 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 341 insertions(+), 148 deletions(-)
diff --git a/src/pages/production/twist/receive/steelCore/index.vue b/src/pages/production/twist/receive/steelCore/index.vue
index 1e6b91c..77e607a 100644
--- a/src/pages/production/twist/receive/steelCore/index.vue
+++ b/src/pages/production/twist/receive/steelCore/index.vue
@@ -1,53 +1,55 @@
<template>
- <view class="list">
+ <view class="list_box">
<z-paging
ref="pagingRef"
- v-model="cardList"
:fixed="false"
:auto-show-back-to-top="true"
+ :loading-more-enabled="false"
@query="getList"
>
<template #top>
- <CardTitle title="鑺嚎棰嗙敤" :hideAction="false" :full="false">
+ <CardTitle title="鑺嚎棰嗙敤" :hideAction="false">
<template #action>
<wd-button type="icon" icon="scan" color="#0D867F" @click="openScan"></wd-button>
- <wd-button type="icon" icon="add-circle" color="#0D867F" @click="addReport"></wd-button>
+ <wd-button type="icon" icon="add-circle" color="#0D867F" @click="openAddForm"></wd-button>
</template>
</CardTitle>
</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.model }}</text>
- </view>
- <view class="text-[#A8A8A8]" @click="toEdit(item.id)">缂栬緫</view>
- </view>
- </template>
- <ProductionCard :data="cardAttr" :value="item" color="#0D867F" />
- </wd-card>
+
+ <!-- 灞傜骇 tabs -->
+ <wd-tabs v-model="tab" slidable="always" class="tabs-container">
+ <block v-for="item in nodeList" :key="item.twistedLayer">
+ <wd-tab :title="item.twistedLayer" :name="item.twistedLayer">
+ <scroll-view class="content" scroll-y>
+ <SteelCoreCard
+ v-for="(m, i) in item.strandedWireDish"
+ :key="i"
+ :data="m"
+ @delete="handleDeleteCard(item, m)"
+ />
+ </scroll-view>
+ </wd-tab>
+ </block>
+ </wd-tabs>
+
+ <template #bottom>
+ <view class="flex justify-center items-center">
+ <wd-button block @click="save">
+ <text class="text-[#fff]">淇濆瓨</text>
+ </wd-button>
+ </view>
+ </template>
</z-paging>
- <wd-popup v-model="addDialog.visible" position="bottom" custom-class="yl-popup">
+
+ <!-- 鏂板閽㈣姱寮圭獥 -->
+ <wd-popup v-model="showAddForm" 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>
</view>
- <SteelCore ref="addFormRef" mode="add" :wireId="paramsId" @refresh="reloadList" />
+ <SteelCoreForm ref="addFormRef" mode="add" :wireId="paramsId" />
</wd-popup>
- <wd-popup v-model="editDialog.visible" position="bottom" custom-class="yl-popup">
- <view class="action px-3">
- <wd-button type="text" @click="cancelEdit">鍙栨秷</wd-button>
- <wd-button type="text" @click="submitEdit">纭畾</wd-button>
- </view>
- <SteelCore
- ref="editFormRef"
- mode="edit"
- :wireId="paramsId"
- :editData="editDialog.currentItem"
- @refresh="reloadList"
- />
- </wd-popup>
+
<Scan ref="scanRef" emitName="scanSteelCore" />
<wd-toast />
</view>
@@ -55,11 +57,10 @@
<script setup lang="ts">
import CardTitle from "@/components/card-title/index.vue";
-import ProductionCard from "../../../components/ProductionCard.vue";
+import SteelCoreCard from "../../components/SteelCoreCard.vue";
+import SteelCoreForm from "./form.vue";
import { useToast } from "wot-design-uni";
-import SteelCore from "./form.vue";
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";
@@ -67,174 +68,306 @@
const paramsId = ref();
const pagingRef = ref();
const addFormRef = ref();
-const editFormRef = ref();
const scanRef = ref();
const toast = useToast();
-const isPageVisible = ref(false); // 鏍囪椤甸潰鏄惁鍙
-const addDialog = reactive({
- visible: false,
-});
-const editDialog = reactive({
- visible: false,
- currentItem: null as any,
- editId: undefined as number | undefined,
-});
-const cardList = ref<any[]>([]);
+const tab = ref("");
+const nodeList = ref<any[]>([]);
+const showAddForm = ref(false);
+const isPageVisible = ref(false);
-const cardAttr = ref<any[]>([
- {
- label: "鏍峰搧缂栧彿",
- prop: "monofilamentNumber",
- },
- {
- label: "鏁伴噺",
- prop: "amount",
- unitProp: "unit",
- },
- {
- label: "閲嶉噺",
- prop: "weight",
- unitProp: "weightUnit",
- },
- {
- label: "鍘傚",
- prop: "supplier",
- span: 16,
- },
-]);
+// 鐩戝惉鏍囩鍒囨崲
+watch(tab, () => {
+ if (tab.value) {
+ getList();
+ }
+});
-const toEdit = (id: number) => {
- const itemToEdit = cardList.value.find((item) => item.id === id);
- if (itemToEdit) {
- editDialog.currentItem = itemToEdit;
- editDialog.editId = id;
- editDialog.visible = true;
+// 鑾峰彇閽㈣姱灞傜骇鏁版嵁锛堝弬鐓C绔� getSteelCoreDishTypeByWire锛�
+const fetchSteelCoreData = async (wireId: number) => {
+ const { code, data, msg } = await TwistApi.getSteelCoreDishTypeByWire(wireId);
+ if (code === 200 && data) {
+ nodeList.value = data.nodeList || [];
+
+ // 杩藉姞"鍏朵粬"灞�
+ if (data.otherStrandedWireDish && data.otherStrandedWireDish.length > 0) {
+ nodeList.value.push({
+ strandedWireDish: data.otherStrandedWireDish,
+ twistedLayer: "鍏朵粬",
+ twistId: null,
+ });
+ }
+
+ // 璁剧疆榛樿绗竴灞�
+ if (nodeList.value.length > 0 && !tab.value) {
+ tab.value = nodeList.value[0].twistedLayer;
+ getList();
+ }
+ } else {
+ toast.error(msg || "鑾峰彇閽㈣姱灞傜骇鏁版嵁澶辫触");
}
};
-const addReport = () => {
+// 浠庡綋鍓嶉�変腑灞傝幏鍙栧垪琛ㄦ暟鎹�
+const getList = async () => {
+ const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
+ if (currentLayer && currentLayer.strandedWireDish) {
+ pagingRef.value.complete(currentLayer.strandedWireDish);
+ } else {
+ pagingRef.value.complete([]);
+ }
+};
+
+// 鎵撳紑鏂板琛ㄥ崟
+const openAddForm = () => {
+ if (!tab.value) {
+ toast.error("璇峰厛閫夋嫨涓�涓眰");
+ return;
+ }
if (addFormRef.value) {
addFormRef.value.resetFormData();
}
- addDialog.visible = true;
+ showAddForm.value = true;
};
+// 鎻愪氦鏂板
const submitAdd = async () => {
- const success = await addFormRef.value.submit();
- if (success) {
- addDialog.visible = false;
+ const formData = await addFormRef.value.submit();
+ if (!formData) return;
+
+ // 鏌ユ壘褰撳墠灞�
+ const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
+ if (!currentLayer) {
+ toast.error("鏈壘鍒板綋鍓嶉�変腑鐨勫眰");
+ return;
}
+
+ // 鍚屽眰閲嶅妫�鏌�
+ if (formData.monofilamentNumber) {
+ const exists = currentLayer.strandedWireDish?.some(
+ (item: any) => item.monofilamentNumber === formData.monofilamentNumber
+ );
+ if (exists) {
+ toast.error("璇ラ挗鑺凡棰嗙敤锛岃鍕块噸澶嶆坊鍔�");
+ return;
+ }
+ }
+
+ // 娣诲姞鍒板綋鍓嶅眰
+ if (!currentLayer.strandedWireDish) {
+ currentLayer.strandedWireDish = [];
+ }
+ currentLayer.strandedWireDish.push({
+ ...formData,
+ wireId: paramsId.value,
+ });
+
+ getList();
+ showAddForm.value = false;
+ toast.success("娣诲姞鎴愬姛");
};
const cancelAdd = () => {
- toast.show("鍙栨秷");
- addDialog.visible = false;
+ showAddForm.value = false;
};
-const submitEdit = async () => {
- const success = await editFormRef.value.submitEdit(cardList.value, editDialog.editId);
- if (success) {
- editDialog.visible = false;
- reloadList();
- }
-};
-
-const cancelEdit = () => {
- toast.show("鍙栨秷");
- editDialog.visible = false;
-};
-
-const getList = async () => {
- const { code, data } = await ManageApi.getStrandedWireDish({
- wireId: paramsId.value,
- type: "閽㈣姱",
- });
- if (code == 200) {
- pagingRef.value.complete(data);
- }
-};
-
-const reloadList = () => {
- pagingRef.value.refresh();
-};
-
-// 鎵爜鐩稿叧鏂规硶
-const openScan = () => {
- scanRef.value.triggerScan();
-};
-
+// 鑾峰彇鎵爜鏁版嵁
const getScanCode = async (code: any) => {
- // 妫�鏌ラ〉闈㈡槸鍚﹀彲瑙侊紝濡傛灉涓嶅彲瑙佸垯涓嶅鐞嗘壂鐮佹暟鎹�
if (!isPageVisible.value) {
return;
}
try {
- const parseData = JSON.parse(code.code);
-
- // 妫�鏌ュ繀闇�瀛楁锛歮odel銆乻upplier銆乨iskMaterial
- const requiredFields = ["model", "supplier", "diskMaterial"];
- const missingFields = requiredFields.filter((field) => !parseData[field]);
-
- if (missingFields.length > 0) {
- toast.error(`浜岀淮鐮侀敊璇紝璇锋洿鎹簩缁寸爜锛乣);
+ if (!tab.value) {
+ toast.error("璇峰厛閫夋嫨涓�涓眰");
return;
}
- // 鎵撳紑鏂板寮规骞跺~鍏呮壂鐮佽幏鍙栫殑淇℃伅
- addDialog.visible = true;
+ const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
+ if (!currentLayer) {
+ toast.error("鏈壘鍒板綋鍓嶉�変腑鐨勫眰");
+ return;
+ }
- // 绛夊緟寮规鎵撳紑鍚庡~鍏呰〃鍗曟暟鎹�
- // 浣跨敤鍙岄噸绛夊緟锛歯extTick + setTimeout 纭繚缁勪欢宸插畬鍏ㄦ寕杞�
- nextTick(() => {
- setTimeout(() => {
- if (addFormRef.value) {
- addFormRef.value.fillFormData(parseData);
- toast.success("鎵爜鎴愬姛锛岃纭淇℃伅");
- } else {
- toast.error("琛ㄥ崟鍔犺浇澶辫触锛岃閲嶈瘯");
- }
- }, 200); // 寤惰繜200ms纭繚寮规鍜岀粍浠跺凡瀹屽叏娓叉煋
- });
+ const parseData = JSON.parse(code.code);
+
+ // 妫�鏌ュ繀闇�瀛楁
+ const requiredFields = ["model", "supplier", "diskMaterial"];
+ const missingFields = requiredFields.filter((field) => !parseData[field]);
+ if (missingFields.length > 0) {
+ toast.error("浜岀淮鐮侀敊璇紝璇锋洿鎹簩缁寸爜锛�");
+ return;
+ }
+
+ // 鍚屽眰閲嶅妫�鏌�
+ if (parseData.monofilamentNumber) {
+ const exists = currentLayer.strandedWireDish?.some(
+ (item: any) => item.monofilamentNumber === parseData.monofilamentNumber
+ );
+ if (exists) {
+ toast.error("璇ラ挗鑺凡棰嗙敤锛岃鍕块噸澶嶆壂鐮�");
+ return;
+ }
+ }
+
+ // 鏋勫缓鏂伴挗鑺暟鎹�
+ const newItem = {
+ wireId: paramsId.value,
+ diskMaterial: parseData.diskMaterial || "",
+ model: parseData.model || "",
+ monofilamentNumber: parseData.monofilamentNumber || "",
+ amount: parseData.oneLength || parseData.amount || "",
+ weight: parseData.weight || "",
+ supplier: parseData.supplier || "",
+ type: "閽㈣姱",
+ };
+
+ if (!currentLayer.strandedWireDish) {
+ currentLayer.strandedWireDish = [];
+ }
+ currentLayer.strandedWireDish.push(newItem);
+ getList();
+ toast.success("鎵爜鎴愬姛");
} catch (error) {
toast.error("浜岀淮鐮佸紓甯革紝璇锋洿鎹簩缁寸爜锛�");
}
};
-onLoad((options: any) => {
- // 寮�鍚箍鎾洃鍚簨浠�
+// 鎵撳紑鎵弿
+const openScan = () => {
+ scanRef.value.triggerScan();
+};
+
+// 淇濆瓨锛堟壒閲忔彁浜わ級
+const save = () => {
+ // 妫�鏌ユ槸鍚︽湁鏂版暟鎹渶瑕佷繚瀛�
+ let hasNewData = false;
+ let newCount = 0;
+
+ nodeList.value.forEach((node) => {
+ if (node.strandedWireDish && Array.isArray(node.strandedWireDish)) {
+ const hasNewInLayer = node.strandedWireDish.some(
+ (item: { id?: number }) => item.id === undefined || item.id === null
+ );
+ if (hasNewInLayer) {
+ hasNewData = true;
+ newCount += node.strandedWireDish.filter(
+ (item: { id?: number }) => item.id === undefined || item.id === null
+ ).length;
+ }
+ }
+ });
+
+ if (!hasNewData) {
+ toast.error("娌℃湁鏂扮殑閽㈣姱鏁版嵁闇�瑕佷繚瀛�");
+ return;
+ }
+
+ // 纭淇濆瓨
+ uni.showModal({
+ title: "鎻愮ず",
+ content: `纭淇濆瓨 ${newCount} 鏉¢挗鑺鐢ㄦ暟鎹悧锛焋,
+ success: async (res) => {
+ if (res.confirm) {
+ await handleConfirmSave();
+ }
+ },
+ });
+};
+
+// 鎵ц鎵归噺淇濆瓨
+const handleConfirmSave = async () => {
+ const newData: any[] = [];
+
+ nodeList.value.forEach((node) => {
+ // 闄勫姞涓婁笅绾� twistId
+ if (node.strandedWireDish && Array.isArray(node.strandedWireDish)) {
+ node.strandedWireDish.forEach((item: any) => {
+ item.saleTwistId = node.twistId;
+ });
+ const layerNewData = node.strandedWireDish.filter(
+ (item: { id?: number }) => item.id === undefined || item.id === null
+ );
+ newData.push(...layerNewData);
+ }
+ });
+
+ if (newData.length === 0) {
+ toast.error("娌℃湁鏂扮殑閽㈣姱鏁版嵁闇�瑕佷繚瀛�");
+ return;
+ }
+
+ const { code, msg } = await TwistApi.addStrandedWireDish(newData);
+ if (code == 200) {
+ toast.success(msg || "淇濆瓨鎴愬姛");
+ // 鍒锋柊鏁版嵁鑾峰彇鏈�鏂扮殑 id
+ fetchSteelCoreData(paramsId.value);
+ } else {
+ toast.error(msg || "淇濆瓨澶辫触");
+ }
+};
+
+// 鍒犻櫎鍗$墖
+const handleDeleteCard = async (layer: any, cardData: any) => {
+ uni.showModal({
+ title: "鎻愮ず",
+ content: "纭畾瑕佸垹闄よ閽㈣姱鍚楋紵",
+ success: async (res) => {
+ if (res.confirm) {
+ try {
+ // 宸蹭繚瀛樼殑鏁版嵁璋冪敤鎺ュ彛鍒犻櫎
+ if (cardData.id !== undefined && cardData.id !== null) {
+ const { code, msg } = await TwistApi.deleteStrandedWireDish(cardData.id);
+ if (code !== 200) {
+ toast.error(msg || "鍒犻櫎澶辫触");
+ return;
+ }
+ }
+
+ // 鍓嶇绉婚櫎
+ if (layer.strandedWireDish && Array.isArray(layer.strandedWireDish)) {
+ const index = layer.strandedWireDish.findIndex(
+ (item: any) => item.monofilamentNumber === cardData.monofilamentNumber
+ );
+ if (index !== -1) {
+ layer.strandedWireDish.splice(index, 1);
+ toast.success("鍒犻櫎鎴愬姛");
+ getList();
+ }
+ }
+ } catch (error: any) {
+ toast.error(error.msg || "鍒犻櫎澶辫触");
+ }
+ }
+ },
+ });
+};
+
+onLoad(async (options: any) => {
uni.$on("scanSteelCore", getScanCode);
paramsId.value = options.id;
+ fetchSteelCoreData(options.id);
});
onShow(() => {
- // 椤甸潰鏄剧ず鏃舵爣璁颁负鍙
isPageVisible.value = true;
});
onHide(() => {
- // 椤甸潰闅愯棌鏃舵爣璁颁负涓嶅彲瑙�
isPageVisible.value = false;
});
onUnload(() => {
- // 鍙栨秷骞挎挱鐩戝惉浜嬩欢
uni.$off("scanSteelCore", getScanCode);
isPageVisible.value = false;
});
</script>
<style lang="scss" scoped>
-.list {
- height: calc(100vh - 120px);
- padding: 12px;
+.list_box {
+ height: calc(100vh - 50px);
background: #f3f9f8;
-
- :deep() {
- .round {
- border-radius: 4px;
- }
- }
+ display: flex;
+ flex-direction: column;
}
.action {
@@ -245,4 +378,64 @@
:deep(.wd-button__content) {
color: #0d867f;
}
+
+.tabs-container {
+ height: calc(100vh - 200px);
+ display: flex;
+ flex-direction: column;
+}
+
+.content {
+ height: calc(100vh - 200px);
+ width: 100%;
+}
+
+:deep(.zp-paging-container) {
+ background: transparent !important;
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+}
+
+:deep(.zp-paging-container-content) {
+ background: transparent !important;
+ flex: 1;
+ display: flex;
+ flex-direction: column;
+}
+
+:deep(.wd-tabs) {
+ background: transparent !important;
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+}
+
+:deep(.wd-tabs__nav) {
+ margin-bottom: 10px;
+ flex-shrink: 0;
+ position: sticky;
+ top: 0;
+ z-index: 10;
+ background: #f3f9f8;
+}
+
+:deep(.wd-tabs__content) {
+ flex: 1;
+ overflow: visible;
+}
+
+:deep(.wd-tab__pane) {
+ height: 100%;
+}
+
+:deep(.zp-paging-container-top) {
+ flex-shrink: 0;
+}
+
+:deep(.zp-paging-container-bottom) {
+ flex-shrink: 0;
+ padding: 8px 12px;
+}
</style>
--
Gitblit v1.9.3