From 375554f68494f303617ad06aba2f8997d4b9e423 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期一, 13 四月 2026 13:16:23 +0800
Subject: [PATCH] 重新设计车间选择逻辑,使其能够根据产品类型自动设定;优化车间展示界面

---
 pages/wareHouse/nuclearScale/createwriteoffform.vue |  222 ++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 153 insertions(+), 69 deletions(-)

diff --git a/pages/wareHouse/nuclearScale/createwriteoffform.vue b/pages/wareHouse/nuclearScale/createwriteoffform.vue
index 9de5390..9bdfdfd 100644
--- a/pages/wareHouse/nuclearScale/createwriteoffform.vue
+++ b/pages/wareHouse/nuclearScale/createwriteoffform.vue
@@ -188,34 +188,20 @@
         label="鐢熶骇杞﹂棿锛�"
         :border-bottom="false"
         prop="workshop"
-        style="font-size: 16px; height: 40px"
+        class="workshop-form-item"
+        style="font-size: 16px"
       >
-        <picker
-          class="item-one item-two"
-          style="width: 100%; text-align: right; font-size: 16px"
-          @change="workshopChange($event, workshopList)"
-          :value="workshopIndex"
-          :range="workshopList"
-          range-key="label"
-          :disabled="!form.productType"
-        >
-          <view>
-            <text
-              :style="{ color: workshopIndex == null ? '#a5abb4' : '#0c0c0c' }"
-              >{{
-                workshopIndex == null
-                  ? "璇烽�夋嫨"
-                  : workshopList[workshopIndex].label
-              }}</text
-            >
-          </view>
-        </picker>
-        <u-icon
-          v-if="workshopIndex == null"
-          name="arrow-right"
-          color="#687792"
-          size="28"
-        ></u-icon>
+        <view class="workshop-field-body">
+          <text v-if="!form.productType" class="workshop-field-text is-placeholder"
+            >璇峰厛閫夋嫨浜у搧绫诲瀷</text
+          >
+          <text
+            v-else
+            class="workshop-field-text"
+            :class="{ 'is-placeholder': !workshopDisplayText }"
+            >{{ workshopDisplayText || "姝e湪鍖归厤杞﹂棿..." }}</text
+          >
+        </view>
       </u-form-item>
       <u-form-item
         label="鍙哥鍛橈細"
@@ -398,9 +384,8 @@
       selClientList: [],
       selClientIndex1: null,
       selClientIndex2: null,
-      // 鐢熶骇杞﹂棿
+      // 鐢熶骇杞﹂棿锛堢敱浜у搧绫诲瀷鑷姩甯﹀嚭锛屼笉鍙敼锛�
       workshopList: [],
-      workshopIndex: null,
       // 鍙哥鍛�
       weighmanList: [],
       weighmanIndex: null,
@@ -410,6 +395,33 @@
       id2: "",
       isSubmitting: false,
     };
+  },
+  computed: {
+    workshopDisplayText() {
+      const raw = this.form.workshop;
+      if (!raw) return "";
+      const values = String(raw)
+        .split(",")
+        .map((s) => s.trim())
+        .filter(Boolean);
+      const labels = values.map((v) => {
+        const w = this.workshopList.find(
+          (x) => String(x.value) === String(v)
+        );
+        return w ? w.label : v;
+      });
+      return labels.join("銆�");
+    },
+  },
+  watch: {
+    workshopList: {
+      handler(list) {
+        if (list && list.length && this.form.productType) {
+          this.$nextTick(() => this.syncWorkshopFromProductType());
+        }
+      },
+      deep: true,
+    },
   },
   onReady() {
     this.$refs.uForm.setRules(this.rules);
@@ -443,7 +455,6 @@
     };
     this.selClientIndex1 = null;
     this.selClientIndex2 = null;
-    this.workshopIndex = null;
     this.weighmanIndex = null;
     this.checkboxList = this.checkboxList.map((item) => ({
       ...item,
@@ -505,6 +516,7 @@
               });
               this.workshopList.push(obj);
             });
+            this.$nextTick(() => this.syncWorkshopFromProductType());
           } else {
             uni.showToast({
               title: res.msg || "鑾峰彇杞﹂棿鍒楄〃澶辫触",
@@ -700,48 +712,69 @@
         this.id1 = selectedCustomer.id;
       }
     },
-    // 鐢熶骇杞﹂棿
-    workshopChange(e, storage) {
-      if (storage.length <= 0) {
-        this.workshopIndex = null;
+    /**
+     * 鎸変骇鍝佺被鍨嬭嚜鍔ㄨ缃敓浜ц溅闂达紙鍗曢��/澶氶�夊潎鐢辩被鍨嬪喅瀹氾紝鐢ㄦ埛涓嶅彲鏀癸級
+     */
+    syncWorkshopFromProductType() {
+      const pt = this.form.productType;
+      const list = this.workshopList;
+      if (!pt) {
+        this.form.workshop = "";
         return;
       }
-
-      const productType = this.form.productType;
-      const selectedWorkshop = storage[e.target.value];
-      console.log("閫夋嫨鐨勮溅闂�:", selectedWorkshop);
-      // 妫�鏌ヤ骇鍝佺被鍨嬫槸鍚︿负閾滄潌(鍊间负TG01)
-      if (productType === "TG01") {
-        // 閾滄潌鍙兘閫夋嫨閾滄潌鐩稿叧杞﹂棿
-        if (!selectedWorkshop.label.includes("閾滄潌")) {
-          uni.showModal({
-            title: "鎻愮ず",
-            content: "閾滄潌浜у搧鍙兘閫夋嫨閾滄潌鐩稿叧杞﹂棿",
-            showCancel: false,
-          });
-          return;
-        }
-      } else {
-        // 瀵间綋浜у搧涓嶈兘閫夋嫨閾滄潌杞﹂棿
-        if (selectedWorkshop.label.includes("閾滄潌")) {
-          uni.showModal({
-            title: "鎻愮ず",
-            content: "瀵间綋浜у搧涓嶈兘閫夋嫨閾滄潌杞﹂棿",
-            showCancel: false,
-          });
-          return;
-        }
+      if (!list.length) {
+        this.form.workshop = "";
+        return;
       }
-      if (selectedWorkshop.label.includes("鐩村彂") && productType !== "DT02") {
-        uni.showModal({
-          title: "鎻愮ず",
-          content: "鐩村彂浜у搧鍙兘閫夋嫨瀵间綋2.6杞﹂棿",
-          showCancel: false,
+      if (pt === "TG01") {
+        const w =
+          list.find((x) => x.label === "閾滄潌") ||
+          list.find((x) => x.label.includes("閾滄潌"));
+        if (w) {
+          this.form.workshop = w.value;
+        } else {
+          this.form.workshop = "";
+          uni.showToast({ title: "瀛楀吀涓湭鎵惧埌閾滄潌杞﹂棿", icon: "none" });
+        }
+        return;
+      }
+      if (pt === "DT01") {
+        this.setWorkshopByLabels(["瀵间綋杞﹂棿", "瀵间綋杞﹂棿2"]);
+        return;
+      }
+      if (pt === "DT02") {
+        this.setWorkshopByLabels(["瀵间綋杞﹂棿", "瀵间綋杞﹂棿2", "鐩村彂"]);
+      }
+    },
+    setWorkshopByLabels(requiredLabels) {
+      const list = this.workshopList;
+      const picked = [];
+      const missing = [];
+      requiredLabels.forEach((lbl) => {
+        let w = list.find((x) => x.label === lbl);
+        if (!w && lbl === "鐩村彂") {
+          w = list.find((x) => x.label.includes("鐩村彂"));
+        }
+        if (w) picked.push(w);
+        else missing.push(lbl);
+      });
+      if (missing.length) {
+        this.form.workshop = "";
+        uni.showToast({
+          title: `杞﹂棿瀛楀吀缂哄皯锛�${missing.join("銆�")}`,
+          icon: "none",
         });
         return;
       }
-      this.workshopIndex = e.target.value;
-      this.form.workshop = selectedWorkshop.value;
+      const uniq = [];
+      const seen = new Set();
+      picked.forEach((w) => {
+        if (!seen.has(w.value)) {
+          seen.add(w.value);
+          uniq.push(w);
+        }
+      });
+      this.form.workshop = uniq.map((x) => x.value).join(",");
     },
     // 鍙哥鍛�
     weighmanChange(e, storage) {
@@ -759,11 +792,10 @@
     confirm() {},
 
     /**
-     * 浜у搧绫诲瀷鍙樺寲鏃舵竻绌鸿溅闂撮�夋嫨
+     * 浜у搧绫诲瀷鍙樺寲鏃舵寜瑙勫垯鑷姩甯﹀嚭鐢熶骇杞﹂棿
      */
     handleProductTypeChange() {
-      this.workshopIndex = null;
-      this.form.workshop = "";
+      this.syncWorkshopFromProductType();
     },
     // 鎻愪氦鎸夐挳
     async submit() {
@@ -945,4 +977,56 @@
   // margin-right: 5px;
   transform: scale(1.2);
 }
+
+/* 鐢熶骇杞﹂棿澶氳灞曠ず锛岄伩鍏嶅浐瀹氶珮搴︽尋鍘嬭鐩栦笅涓�琛� */
+::v-deep .workshop-form-item.u-form-item {
+  height: auto !important;
+  min-height: 40px;
+  line-height: 1.45 !important;
+  align-items: stretch;
+}
+
+::v-deep .workshop-form-item .u-form-item__body {
+  align-items: flex-start;
+}
+
+::v-deep .workshop-form-item .u-form-item--left {
+  align-items: flex-start;
+  padding-top: 4px;
+}
+
+::v-deep .workshop-form-item .u-form-item--left__content,
+::v-deep .workshop-form-item .u-form-item--left__content__label {
+  align-items: flex-start;
+}
+
+::v-deep .workshop-form-item .u-form-item--right__content {
+  align-items: flex-start;
+}
+
+::v-deep .workshop-form-item .u-form-item--right__content__slot {
+  align-items: flex-start !important;
+}
+
+.workshop-field-body {
+  width: 100%;
+  box-sizing: border-box;
+  padding: 4px 0 6px;
+  text-align: right;
+}
+
+.workshop-field-text {
+  display: block;
+  width: 100%;
+  font-size: 16px;
+  line-height: 1.45;
+  color: #0c0c0c;
+  text-align: right;
+  word-break: break-word;
+  white-space: normal;
+}
+
+.workshop-field-text.is-placeholder {
+  color: #a5abb4;
+}
 </style>
\ No newline at end of file

--
Gitblit v1.9.3