From fcadf16afa65a8a5ca53a33c4b8f4bf2efe2ea03 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 16 九月 2026 09:21:44 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_新疆_新聚' into dev_新疆_新聚

---
 src/views/business/productOrder/components/addOrder.vue |  517 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 323 insertions(+), 194 deletions(-)

diff --git a/src/views/business/productOrder/components/addOrder.vue b/src/views/business/productOrder/components/addOrder.vue
index 5b9c516..000296d 100644
--- a/src/views/business/productOrder/components/addOrder.vue
+++ b/src/views/business/productOrder/components/addOrder.vue
@@ -14,9 +14,13 @@
           <el-select v-show="active==1" v-model="template" placeholder="涓嬪崟妯℃澘" size="small"
                      @change="selectInsOrderTemplateById">
             <el-option v-for="(a, ai) in templates" :key="ai" :label="a.name" :value="a.id">
-              <span style="float: left">{{ a.name }}</span>
-              <i class="el-icon-delete" style="float: right; color: #66b1ff; font-size: 16px"
-                 @click.stop="handleDelete(a)"></i>
+              <div style="display: flex; align-items: center; justify-content: space-between;">
+                <span>{{ a.name }}</span>
+                <i class="el-icon-delete"
+                   style="color: #66b1ff; font-size: 16px; cursor: pointer;"
+                   @click.stop="handleDelete(a)">
+                </i>
+              </div>
             </el-option>
           </el-select>
           <el-button v-show="active==1" size="small" @click="templateDia=true">
@@ -38,7 +42,28 @@
     </div>
     <div v-show="!cableConfigShow&&!auxiliaryShow" style="margin-top: 10px">
       <div class="search">
-        <el-form ref="addObj" :inline="true" :model="addObj" :rules="addObjRules" label-width="108px" label-position="right">
+        <el-form ref="newJuOrder" :inline="true" :model="addObj" label-width="108px" label-position="right">
+          <el-row>
+            <el-col :span="6"><el-form-item label="浜у搧鍚嶇О"><el-input v-model="addObj.sample" disabled size="small"><template slot="append"><el-button :disabled="active>1" icon="el-icon-search" @click="selectStandardTree = true" /></template></el-input></el-form-item></el-col>
+            <el-col :span="6"><el-form-item label="鐢熶骇鍗曚綅"><el-input v-model="addObj.production" :disabled="active>1" size="small" /></el-form-item></el-col>
+            <el-col :span="6"><el-form-item label="濮旀墭鍗曚綅"><el-input v-model="addObj.company" disabled size="small"><template slot="append"><el-button :disabled="active>1" icon="el-icon-search" @click="openCompanyList" /></template></el-input></el-form-item></el-col>
+            <el-col :span="6"><el-form-item label="妫�楠岀被鍒�"><el-select v-model="addObj.orderType" :disabled="active>1" size="small"><el-option v-for="item in dict.type.check_type1" :key="item.value" :label="item.label" :value="item.value" /></el-select></el-form-item></el-col>
+          </el-row>
+          <el-row>
+            <el-col :span="6"><el-form-item label="鏍峰搧鏁伴噺"><el-input v-model="addObj.testQuantity" :disabled="active>1" placeholder="濡傦細2妗躲��500mL" size="small" /></el-form-item></el-col>
+            <el-col :span="6"><el-form-item label="鏍峰搧缂栧彿"><el-input v-model="sampleCode" :disabled="active>1" size="small" /></el-form-item></el-col>
+            <el-col :span="6"><el-form-item label="鏍峰搧澶栬"><el-input v-model="addObj.sampleStatus" :disabled="active>1" size="small" /></el-form-item></el-col>
+            <el-col :span="6"><el-form-item label="閫佹牱浜�"><el-input v-model="addObj.prepareUser" :disabled="active>1" size="small" /></el-form-item></el-col>
+          </el-row>
+          <el-row>
+            <el-col :span="6"><el-form-item label="鐢熶骇鏃ユ湡"><el-date-picker v-model="addObj.productionDate" type="date" value-format="yyyy-MM-dd" :disabled="active>1" size="small" /></el-form-item></el-col>
+            <el-col :span="6"><el-form-item label="鐢熶骇鎵瑰彿"><el-input v-model="addObj.productionBatch" :disabled="active>1" size="small" /></el-form-item></el-col>
+            <el-col :span="6"><el-form-item label="閫佹牱鏃ユ湡"><el-date-picker v-model="addObj.sampleDate" type="date" value-format="yyyy-MM-dd" :disabled="active>1" size="small" /></el-form-item></el-col>
+            <el-col :span="6"><el-form-item label="鑱旂郴鏂瑰紡"><el-input v-model="addObj.phone" :disabled="active>1" size="small" /></el-form-item></el-col>
+          </el-row>
+          <el-row><el-col :span="6"><el-form-item label="鐜鏉′欢"><el-input v-model="addObj.temperature" :disabled="active>1" placeholder="娓╁害" size="small" /></el-form-item></el-col><el-col :span="6"><el-form-item label="婀垮害"><el-input v-model="addObj.humidity" :disabled="active>1" size="small" /></el-form-item></el-col><el-col :span="6"><el-form-item label="澶囨敞"><el-input v-model="addObj.remark" :disabled="active>1" size="small" /></el-form-item></el-col></el-row>
+        </el-form>
+        <el-form v-if="false" ref="addObj" :inline="true" :model="addObj" :rules="addObjRules" label-width="108px" label-position="right">
           <el-row>
             <el-col :span="6">
               <el-form-item label="濮旀墭缂栧彿:" prop="entrustCode">
@@ -201,7 +226,7 @@
           </el-row>
         </el-form>
       </div>
-      <div>
+      <div v-if="false">
         <div style="display: flex;justify-content: space-between;background-color: #F5F7FB;margin-bottom: 6px">
           <div v-if="active==1">
             <el-form :inline="true" :model="addObj1" label-width="90px">
@@ -296,19 +321,27 @@
             </template>
           </el-table-column>
         </el-table>
+        <div v-if="canSelectProduct" style="display: flex; align-items: center; gap: 12px; padding: 10px 0;">
+          <span>妫�娴嬭寖鍥达細</span>
+          <el-radio-group v-model="inspectionScope" size="small" @change="changeInspectionScope">
+            <el-radio-button label="all">鍏ㄩ儴妫�楠�</el-radio-button>
+            <el-radio-button label="specified">鎸囧畾妫�楠岄」</el-radio-button>
+          </el-radio-group>
+          <span>宸查�� {{ selectedProductCount }} / 鍏� {{ productList.length }} 椤�</span>
+        </div>
         <el-table ref="productTable" v-loading="getProductLoad" :data="productList"
                   :row-class-name="tableRowClassName" border class="el-table"
                   :header-cell-style="{ background: '#f8f8f9', color: '#515a6e' }"
           max-height="400px" style="margin-bottom: 10px;" tooltip-effect="dark"
           @select="selectOne" @selection-change="selectProduct" @select-all="handleAll">
-          <el-table-column v-if="active==1" :selectable="selectable0" type="selection" width="65"></el-table-column>
+          <el-table-column v-if="canSelectProduct" :selectable="selectable0" type="selection" width="65"></el-table-column>
           <el-table-column label="妫�楠岄」鍒嗙被" min-width="140" prop="inspectionItemClass" show-overflow-tooltip></el-table-column>
           <el-table-column label="妫�楠岄」" min-width="140" prop="inspectionItem" show-overflow-tooltip>
             <template slot="header" slot-scope="scope">
               <div style="display: flex;align-items: center;flex-direction: column;font-size: 14px">
                 <span>妫�楠岄」</span>
                 <el-input
-                  v-if="active==1"
+                  v-if="canSelectProduct"
                 v-model="inspectionItem"
                 placeholder="璇疯緭鍏�"
                 size="mini"
@@ -322,7 +355,7 @@
               <div style="display: flex;align-items: center;flex-direction: column;font-size: 14px">
                 <span>妫�楠岄」瀛愰」</span>
                 <el-input
-                  v-if="active==1"
+                  v-if="canSelectProduct"
                   v-model="inspectionItemSubclass"
                   placeholder="璇疯緭鍏�"
                   size="mini"
@@ -364,7 +397,7 @@
               <div style="display: flex;align-items: center;flex-direction: column;font-size: 14px">
                 <span>璇曢獙鏂规硶</span>
                 <el-input
-                  v-if="active==1"
+                  v-if="canSelectProduct"
                   v-model="methodS"
                   placeholder="璇疯緭鍏�"
                   size="mini"
@@ -415,7 +448,7 @@
               <el-col :span="24">
                 <span><i
                     :class="`node_i ${data.children != undefined ? (data.code==='[1]'?'el-icon-folder-opened':'el-icon-folder') : 'el-icon-tickets'}`"></i>
-                  {{ data.code }} {{ data.label }}</span>
+                  {{ data.label }}</span>
               </el-col>
             </el-row>
           </div>
@@ -459,10 +492,10 @@
             </div>
           </el-col>
           <el-col v-if="distributeData.userId" :span="22" class="search_thing">
-            <div class="search_label"><span class="required-span">* </span>璇曢獙瀹わ細</div>
+            <div class="search_label">璇曢獙瀹わ細</div>
             <div class="search_input">
               <el-select v-model="distributeData.sonLaboratory" filterable placeholder="璇烽�夋嫨" size="small" style="width: 100%;">
-                <el-option v-for="item in sonLaboratoryList" :key="item.value" :label="item.label" :value="item.value">
+                <el-option v-for="item in newJuLaboratoryList" :key="item.value" :label="item.label" :value="item.value">
                 </el-option>
               </el-select>
             </div>
@@ -587,7 +620,7 @@
 } from "@/api/business/rawMaterialOrder";
 import {
   addInsOrder, addInsOrderTemplate, delInsOrderTemplate,
-  getQuarterOnOrder, selectInsOrderTemplateById,
+  getQuarterOnOrder, judgeNotSpotCheckOrder, selectInsOrderTemplateById,
   selectOrderManDay,
   updateInsOrder,
   upInsOrder,
@@ -598,6 +631,13 @@
 import limsTable from "@/components/Table/lims-table.vue";
 import {selectCustomPageList} from "@/api/system/customer";
 import {mapGetters} from "vuex";
+import { bigEval } from "@/utils/bigEval";
+import {addQuarter, updateQuarterOnOrder} from "@/api/business/finishedProductSampling";
+import {
+  isLeafPath,
+  buildSelectTree,
+  dropLastLabel,
+} from "@/utils/standardTree";
 
 export default {
   name: 'AddOrder',
@@ -607,14 +647,24 @@
     AuxiliaryWireCore
   },
   computed:{
-  ...mapGetters(["nickName"]),
+    ...mapGetters(["nickName", 'nameEn', 'userName']),
+    canSelectProduct() {
+      return this.active == 1 || (this.tabIndex == 4 && this.active == 2)
+    },
+    selectedProductCount() {
+      return this.productList.filter(item => item.state == 1).length
+    },
+    newJuLaboratoryList() {
+      return (this.dict.type.sys_sub_lab || []).filter(item => item.label === '鏂拌仛')
+    },
   },
-  dicts: ['check_type1', 'urgency_level', 'form_type', 'sample_status_list'],
+  dicts: ['check_type1', 'urgency_level', 'form_type', 'sample_status_list', 'sys_sub_lab'],
   data() {
     return {
       active: '',
       tabIndex: '',
       currentId: '',
+      sampleCode: '',
       sampleSelectionList: [],//鏍峰搧琛ㄦ牸閫変腑鏁版嵁
       editTable:[],
       template: null,
@@ -683,12 +733,6 @@
         testQuantity: [
           { required: true, message: '璇峰~鍐欐娊妫�鏁伴噺', trigger: 'blur' }
         ],
-        production: [
-          { required: true, message: '璇峰~鍐欑敓浜у崟浣�', trigger: 'blur' }
-        ],
-        productionEn: [
-          { required: true, message: '璇峰~鍐欑敓浜у崟浣岴N', trigger: 'blur' }
-        ],
       },
       sample: {
         sampleCode: null,
@@ -727,6 +771,8 @@
       list: [],
       selectStandardTreeLoading: false,
       selectTree: null,
+      // 褰撳墠閫変腑鐨勬爲鑺傜偣锛堢敤浜庢寜灞傜骇鎺ㄥ瀛楁锛�
+      selectTreeNode: null,
       sampleViewEn: null,
       expandedKeys: [],
       sampleList: [],
@@ -790,13 +836,14 @@
       quarterItemOptions: [], // 鏌ヨ瀛e害淇℃伅
       specialStandardMethod: '',
       isSpecial: false,
+      inspectionScope: 'all',
     }
   },
   watch: {
-    sampleList() {
-      this.addObj.method = null
-      this.productList = []
-    },
+    // sampleList() {
+    //   this.addObj.method = null
+    //   this.productList = []
+    // },
     productList: {
       deep: true,
       handler(val) {
@@ -842,6 +889,11 @@
     this.currentId = this.$route.query.currentId
     this.getUserNowData()
     this.getInfo()
+    if(this.tabIndex==4&&this.active==2){
+      this.isSpecial = true
+    }else{
+      this.isSpecial = false
+    }
   },
   activated() {
     this.active = this.$route.query.active
@@ -850,11 +902,41 @@
     this.getInfo();
   },
   methods: {
+    /**
+     * 鑾峰彇灏忔暟鐨勬渶澶т綅鏁�
+     * @param number  鍨嬪彿鍙傛暟
+     * @param ask     瑕佹眰鍊�
+     * @param calcNum 璁$畻鍊�
+     */
+    getDecimalPlaces(number, ask, calcNum) {
+      console.log("璁$畻灏忔暟鐐�-->", number, ask, calcNum);
+      let count1 = 0;
+      let count2 = 0;
+      const reg = /(\d+\.)(\d+)/g;
+      let matches = [];
+      if (ask) {
+        matches = ask.match(reg);
+      }
+      if (
+        matches &&
+        matches.length > 0 &&
+        matches[0].toString().indexOf(".") > -1
+      ) {
+        count1 = matches[0].toString().split(".")[1].length;
+      }
+      if (number.toString().indexOf(".") > -1) {
+        count2 = number.toString().split(".")[1].length;
+      }
+      if (calcNum.toString().indexOf(".") > -1) {
+        const pointLength2 = calcNum.toString().split(".")[1].length;
+        count2 = count2 > pointLength2 ? count2 : pointLength2;
+      }
+      return count1 > count2 ? count1 : count2;
+    },
     getInfo() {
       this.selectStandardTreeList()
       this.getAuthorizedPerson();
       this.selectStandardMethods()
-      this.getPrepareUser() // 澶嶅埗褰撳墠璐﹀彿浜轰负濮旀墭浜�
       if (this.active != 1) {
         // 鏌ョ湅/瀹℃牳娴佺▼
         // 璇锋眰鎺ュ彛锛屽洖鏄炬暟鎹�
@@ -865,29 +947,26 @@
             ...res.data.insOrder
           };
           this.addObj.type = String(this.addObj.type)
-          this.sampleList = this.HaveJson(res.data.sampleProduct);
-          this.specialStandardMethod = this.sampleList[0].specialStandardMethod
-          this.getProNum()
-          this.addObj.sampleNum = this.sampleList.length
-          this.$nextTick(() => {
-            this.$refs.sampleTable.doLayout()
-            if (this.addObj.sampleNum > 0) {
-              this.$refs.sampleTable.setCurrentRow(this.sampleList[0], true)
-              this.rowClick(this.sampleList[0])
-            }
+          const samples = this.HaveJson(res.data.sampleProduct)
+          const loadSamples = this.canSelectProduct
+            ? Promise.all(samples.map(sample => this.loadSelectableProducts(sample)))
+            : Promise.resolve(samples)
+          loadSamples.then(sampleList => {
+            this.sampleList = sampleList
+            this.specialStandardMethod = this.sampleList[0].specialStandardMethod
+            this.getProNum()
+            this.addObj.sampleNum = this.sampleList.length
+            this.$nextTick(() => {
+              this.$refs.sampleTable.doLayout()
+              if (this.addObj.sampleNum > 0) {
+                this.$refs.sampleTable.setCurrentRow(this.sampleList[0], true)
+                this.rowClick(this.sampleList[0])
+              }
+            })
           })
         })
       }
-      if(this.tabIndex==4&&this.active==2){
-        this.isSpecial = true
-      }else{
-        this.isSpecial = false
-      }
-    },
-    getPrepareUser () {
-        // this.addObj.prepareUser = JSON.parse(localStorage.getItem("user")).name;
-        // this.addObj.prepareUserEn = JSON.parse(localStorage.getItem("user")).nameEn
-        // this.addObj.prepareCode = JSON.parse(localStorage.getItem("user")).account
+
     },
       // 缂栬緫瑕佹眰鍊艰〃鏍�
       editSpecial () {
@@ -1045,7 +1124,13 @@
               let index = code.findIndex(b => m.includes(b))
               if (index > -1) {
                 let arr = m.split(code[index]).filter(b => !!b)
-                let num = eval(this.replaceAll(arr[0], symbolItem, value))
+                let calcNum = this.$Big(
+                  bigEval(this.replaceAll(arr[0], symbolItem, value))
+                );
+                let num = calcNum.toFixed(
+                  this.getDecimalPlaces(value, ask, calcNum)
+                );
+                // let num = eval(this.replaceAll(arr[0], symbolItem, value))
                 m = code[index] + '' + num
                 arr1.push(m)
               }
@@ -1074,7 +1159,13 @@
             let index = code.findIndex(b => ask.includes(b))
             if (index > -1) {
               let arr = ask.split(code[index]).filter(b => !!b)
-              let num = eval(this.replaceAll(arr[0], symbolItem, value))
+              let calcNum = this.$Big(
+                bigEval(this.replaceAll(arr[0], symbolItem, value))
+              );
+              let num = calcNum.toFixed(
+                this.getDecimalPlaces(value, ask, calcNum)
+              );
+              // let num = eval(this.replaceAll(arr[0], symbolItem, value))
               return code[index] + '' + num
             }
           }
@@ -1087,6 +1178,14 @@
         return str.replaceAll(find, value);
       },
       save() {
+        if (this.addObj.standardTreeId) {
+          if (!this.addObj.sample || !this.addObj.company || !this.addObj.orderType || !this.addObj.testQuantity) {
+            this.$message.error('璇峰~鍐欎骇鍝佸悕绉般�佸鎵樺崟浣嶃�佹楠岀被鍒拰鏍峰搧鏁伴噺');
+            return;
+          }
+          this.saveData([]);
+          return;
+        }
         this.$refs['addObj'].validate((valid) => {
           if (valid) {
             this.sampleList.forEach(item => {
@@ -1122,22 +1221,23 @@
                   if (this.tabIndex != 4) {
                     delete c.id
                   }
+                  if (c.isNew) {
+                    c.id = null
+                    delete c.isNew
+                  }
                 })
               }
               if (a.endModels) {
                 a.model = a.endModels
               }
-              a.insProduct = a.insProduct.filter(b=>b.state === 1)
+              if (!this.canSelectProduct || this.active == 1) {
+                a.insProduct = a.insProduct.filter(b=>b.state === 1)
+              }
             })
             let projectNum = this.totalArr.filter(a => a.state == 1).length
             if(projectNum==0){
-              this.$confirm('妫�楠岄」鐩负绌猴紝鏄惁纭鎻愪氦?', "鎻愮ず", {
-                confirmButtonText: "纭畾",
-                cancelButtonText: "鍙栨秷",
-                type: "warning"
-              }).then(() => {
-                this.saveMethod(sampleList)
-              }).catch(() => {})
+              this.$message.warning('璇疯嚦灏戦�夋嫨涓�涓楠岄」')
+              return
             }else{
               let isRTS = this.totalArr.find(a => a.ask != null && this.symbolList.find(b=>a.ask.includes(b)) && a.state == 1)
               if (isRTS) {
@@ -1162,12 +1262,18 @@
                 if (this.tabIndex != 4) {
                   delete c.id
                 }
+                if (c.isNew) {
+                  c.id = null
+                  delete c.isNew
+                }
               })
             }
             if (a.endModels) {
               a.model = a.endModels
             }
-            a.insProduct = a.insProduct.filter(b=>b.state === 1)
+            if (!this.canSelectProduct || this.active == 1) {
+              a.insProduct = a.insProduct.filter(b=>b.state === 1)
+            }
           })
           this.saveMethod(sampleList)
         }else{
@@ -1260,36 +1366,69 @@
         }
       },
       saveMethod(sampleList){
-        this.saveLoad = true
+        if (this.addObj.standardTreeId) {
+          this.saveData([]);
+          return;
+        }
         if (this.addObj.quarterItemId) {
           this.addObj.quarterItemId = this.addObj.quarterItemId[1]
         }
-        if(this.tabIndex==4&&this.active==2){
-          if (this.addObj.createTime) {
-            delete this.addObj.createTime
-          }
-          // 閫�鍥炲悗鎻愪氦
-          updateInsOrder({insOrder: this.addObj, sampleProduct: sampleList}).then(res => {
-            this.saveLoad = false
-            this.$message.success('宸叉彁浜�')
-            this.bsm3Dia = false;
-            this.closeOpenPage()
-          }).catch(e=>{
-            this.saveLoad = false
-          })
-        }else{
-          // 甯歌鎻愪氦
-          addInsOrder({insOrder: this.addObj, sampleList: sampleList}).then(res => {
-            this.saveLoad = false
-            this.$message.success('宸叉彁浜�')
-            this.bsm3Dia = false;
-            this.closeOpenPage()
-          }).catch(e=>{
-            this.saveLoad = false
-          })
+        if (this.addObj.createTime) {
+          delete this.addObj.createTime
         }
-
+        if (this.addObj.orderType === '鎶芥') {
+          judgeNotSpotCheckOrder({ insOrder: this.addObj, sampleList: sampleList }).then(res => {
+            if (res.data === true) {
+              this.saveData(sampleList);
+            } else {
+              // const message = res.message.replace(/\n/g, '<br>');
+              this.$confirm(res.message, '鎻愮ず', {
+                confirmButtonText: '纭畾',
+                cancelButtonText: '鍙栨秷',
+                type: 'warning',
+                dangerouslyUseHTMLString: true, // 馃憟 鍏抽敭鐐癸細鍏佽 HTML
+                message: res.message // 杩欓噷涔熷彲浠ョ渷鐣ワ紝鍥犱负绗簩涓弬鏁版槸 title锛岀涓変釜鏄� options
+              }).then(() => {
+                this.saveData(sampleList);
+              }).catch(() => {
+                this.$message({
+                  type: 'info',
+                  message: '宸插彇娑�'
+                });
+              });
+            }
+          });
+        } else {
+          this.saveData(sampleList)
+        }
       },
+    saveData(sampleList) {
+      this.saveLoad = true
+      if(this.tabIndex==4&&this.active==2){
+        // 閫�鍥炲悗鎻愪氦
+        updateInsOrder({insOrder: this.addObj, sampleProduct: sampleList}).then(res => {
+          this.saveLoad = false
+          this.$message.success('宸叉彁浜�')
+          this.bsm3Dia = false;
+          this.closeOpenPage()
+        }).catch(e=>{
+          this.saveLoad = false
+        })
+      }else{
+        // 甯歌鎻愪氦
+        const payload = this.addObj.standardTreeId
+          ? { insOrder: {...this.addObj,typeSource:-1}, standardTreeId: this.addObj.standardTreeId, sampleCode: this.sampleCode }
+          : { insOrder: {...this.addObj,typeSource:-1}, sampleList: sampleList }
+        addInsOrder(payload).then(res => {
+          this.saveLoad = false
+          this.$message.success('宸叉彁浜�')
+          this.bsm3Dia = false;
+          this.closeOpenPage()
+        }).catch(e=>{
+          this.saveLoad = false
+        })
+      }
+    },
       upInsOrderOfState(state) {
         if (state == 1) {
           this.saveLoad = true
@@ -1309,6 +1448,7 @@
               this.distributeData.appointed = ress.data
             })
             setTimeout(() => {
+              this.distributeData.sonLaboratory = this.newJuLaboratoryList.length > 0 ? this.newJuLaboratoryList[0].value : ''
               this.issuedDialogVisible = true;
             }, 1000)
           })
@@ -1325,10 +1465,6 @@
         }
         if (this.distributeData.userId == null || this.distributeData.userId == '') {
           this.$message.error('鎸囨淳浜哄憳鏈~鍐�')
-          return
-        }
-        if (this.distributeData.userId&&(this.distributeData.sonLaboratory== null ||this.distributeData.sonLaboratory== '')) {
-          this.$message.error('璇曢獙瀹ゆ湭濉啓')
           return
         }
         this.upLoad = true;
@@ -1348,6 +1484,9 @@
         })
       },
       getUserNowData() {
+      this.addObj.prepareUser = this.nickName
+      this.addObj.prepareUserEn = this.nameEn
+      this.addObj.prepareCode = this.userName
         getUserNow().then(res => {
           let selects = res.data
           if (selects == null) return
@@ -1357,8 +1496,8 @@
           this.addObj.code = selects.code
           this.addObj.phone = selects.phone
           this.addObj.companyId = selects.departId
-          this.addObj.production = '涓ぉ绉戞妧瑁呭鐢电紗鏈夐檺鍏徃'
-          this.addObj.productionEn = 'Zhongtian Technology Industrial Wire&Cable System CO.,LTD'
+          this.addObj.production = ''
+          this.addObj.productionEn = ''
           if(this.active==1){
             this.selectInsOrderTemplate()
           }
@@ -1375,9 +1514,9 @@
       },
       nodeOpen(data, node, el) {
         $($(el.$el).find('.node_i')[0]).attr('class', 'node_i el-icon-folder-opened')
-        if (node.data.code === '[3]') {
+        if (data.sampleTypeEn !== undefined && data.sampleTypeEn !== null) {
           this.sampleViewEn = data.sampleTypeEn
-        } else if (node.data.code === '[4]') {
+        } else if (data.sampleEn !== undefined && data.sampleEn !== null) {
           this.sampleViewEn = data.sampleEn
         }
       },
@@ -1385,47 +1524,13 @@
         $($(el.$el).find('.node_i')[0]).attr('class', 'node_i el-icon-folder')
       },
       handleNodeClick(val, node, el) {
-        this.selectTree = ''
-        this.models = val.children
-        this.getNodeParent(node)
-        let flag = false
-        if (node.level == 3) {
-          if(node.data.children.length>0){
-            node.data.children.forEach(a => {
-              let key = Object.keys(a)
-              if(!key.includes('level')) {
-                flag = true
-              }
-            })
-
-          }
-        }
-        if (node.data.code === '[3]') {
+        this.selectTreeNode = node
+        this.models = val.children || []
+        this.selectTree = buildSelectTree(node, '')
+        if (val.sampleTypeEn !== undefined && val.sampleTypeEn !== null) {
           this.sampleViewEn = val.sampleTypeEn
-        } else if (node.data.code === '[4]') {
-          if (node.data.children!==null && node.data.children.length>0) {
-            this.sampleViewEn = val.sampleEn
-          }
-        }
-        this.selectTree = this.selectTree.replace(' - ', '')
-        if(flag) {
-          this.selectTree =  ' -  - ' + this.selectTree
-        }
-        let data = this.selectTree.split(' - ')
-        let data2 = ''
-        for (let index = data.length - 1; index >= 0; index--) {
-          data2 += " - " + data[index]
-        }
-        this.selectTree = data2.replace(' - ', '')
-      },
-      getNodeParent(val) {
-        if (val.parent != null) {
-          if (val.data.children === null) {
-            this.selectTree += ' - ' + val.label + ' - ' + ''
-          } else {
-            this.selectTree += ' - ' + val.label
-          }
-          this.getNodeParent(val.parent)
+        } else if (val.sampleEn !== undefined && val.sampleEn !== null) {
+          this.sampleViewEn = val.sampleEn
         }
       },
       selectStandardTreeList() {
@@ -1443,42 +1548,23 @@
         return data.label.indexOf(value) !== -1;
       },
       activeStandardTree() {
-        let trees = this.selectTree.split(" - ")
-        if (trees.length < 3) {
-          this.$message.error('鏈�夋嫨瀵硅薄')
+        if (!this.selectTreeNode || this.selectTreeNode.data.code !== '[2]') {
+          this.$message.error('璇烽�夋嫨浜岀骇浜у搧')
           return
         }
-        this.addObj.factory = trees[0]
-        this.addObj.laboratory = trees[1]
-        this.addObj.sampleType = trees[2]
-        if (trees[3] === undefined || trees[3] === '' || trees[3] === '- ') {
-          this.addObj.sample = trees[2]
-        } else {
-          this.addObj.sample = trees[3]
-        }
-        this.addObj.sampleView = this.addObj.sample
-        this.addObj.sampleViewEn = this.sampleViewEn
-        this.addObj.model = (trees[4] == undefined ? null : trees[4])
+        const productName = this.selectTreeNode.data.label
+        this.addObj.sample = productName
+        this.addObj.standardTreeId = this.selectTreeNode.data.id
         this.selectStandardTree = false
         this.sampleList = []
-        for (var i = 0; i < this.addObj.sampleNum; i++) {
-          this.sample.joinName = null
-          this.sample.joinModel = null
-          this.sample.joinNum = 1
-          this.sample.sample = this.addObj.sample
-          this.sample.model = this.addObj.model
-          this.sample.unit = this.addObj.unit
-          this.sample.standardMethodListId = null
-          this.sample.insProduct = []
-          this.sample.id = this.count
-          this.sample.childSampleList = []
-          this.sample.insulating = null
-          this.sample.sheath = null
-          this.sampleList.push(this.HaveJson(this.sample))
-          this.count++
-        }
-        this.$refs.sampleTable.doLayout()
-        // this.selectsStandardMethodByFLSSM()
+      },
+      // 鐢ㄦ寚瀹氬瀷鍙锋浛鎹㈡爲璺緞鏈锛堟湯娈靛嵆鏍囧噯/鍨嬪彿锛�
+      buildFactoryPath(model) {
+        const tree = this.selectTree || ''
+        if (!tree || !model) return tree
+        const tokens = tree.split(' - ')
+        tokens[tokens.length - 1] = model
+        return tokens.join(' - ')
       },
       selectsStandardMethodByFLSSMList() {
         this.methodLoad = true
@@ -1486,20 +1572,21 @@
           tree: this.selectTree
         }).then(res => {
           this.methodLoad = false
-          try {
-            if (res.data.standardMethodList.length == 0 && this.selectTree.split('-').length == 5) {
-              let arr = this.selectTree.split('-')
-              let arr0 = arr.slice(0, arr.length - 1)
-              let selectTree = arr0.join('-').substring(0, arr0.join('-').length - 1)
+          const list = (res.data && res.data.standardMethodList) || []
+          // 褰撳墠鏄彾瀛�(鏍囧噯)鍗存煡涓嶅埌鏍囧噯鏃讹紝鍥為��鍒扮埗绾у啀鏌ヤ竴娆�
+          // 鐢ㄨ矾寰勫垽瀹氬彾瀛愶細妯℃澘鍥炲~鏃� selectTreeNode 涓虹┖锛岃妭鐐瑰璞″垽瀹氫細澶辨晥
+          if (list.length === 0 && isLeafPath(this.selectTree)) {
+            const parentTree = dropLastLabel(this.selectTree)
+            if (parentTree) {
               selectsStandardMethodByFLSSM({
-                tree: selectTree
+                tree: parentTree
               }).then(ress => {
-                this.methods = ress.data.standardMethodList
+                this.methods = (ress.data && ress.data.standardMethodList) || []
               })
-            } else {
-              this.methods = res.data.standardMethodList
+              return
             }
-          } catch (e) {}
+          }
+          this.methods = list
         })
       },
       addStandardTree() {
@@ -1555,6 +1642,9 @@
         }
         this.productList = row.insProduct
         this.productList0 = JSON.parse(JSON.stringify(this.productList))
+        this.inspectionScope = this.productList.length === 0
+          ? (this.active == 1 ? 'all' : 'specified')
+          : (this.productList.every(item => item.state == 1) ? 'all' : 'specified')
         setTimeout(() => {
           this.productList.forEach(a => {
             if (a.state == 1) {
@@ -1624,6 +1714,9 @@
         })
         this.changeProductList0()
         this.currentMethod.insProduct = this.productList0
+        this.inspectionScope = this.productList.length > 0 && this.productList.every(item => item.state == 1)
+          ? 'all'
+          : 'specified'
         this.getProNum()
       },
       permute(nums) {
@@ -1732,19 +1825,17 @@
           }
         }
         this.getProductLoad = true
-        let selectTreeList = this.selectTree.split(" - ")
-        this.addObj.model&&(selectTreeList[selectTreeList.length - 1] = this.addObj.model)
         selectStandardProductList({
           model: this.addObj.model?this.addObj.model:row.model,
           modelNum: row.modelNum,
           standardMethodListId: val,
-          factory: selectTreeList.join(" - "),
+          factory: this.buildFactoryPath(this.addObj.model),
           cores: row.cores,
           conductorMaterial: row.conductorMaterial,
           conductorType: row.conductorType,
         }).then(res => {
           res.data.forEach(a => {
-            a.state = 0
+            a.state = this.inspectionScope === 'all' ? 1 : 0
           })
           row.insProduct = this.HaveJson(res.data)
           this.getProductLoad = false
@@ -1759,6 +1850,9 @@
             this.productList.forEach(a => {
               if (a.state == 1) this.toggleSelection(a)
             })
+            if (this.inspectionScope === 'all') {
+              this.handleAll(this.productList.filter(item => this.selectable0(item)))
+            }
           }, 200)
         })
       },
@@ -1796,17 +1890,15 @@
           this.isAskOnlyRead = false
         }
         this.getProductLoad = true
-        let selectTreeList = this.selectTree.split(" - ")
-        this.addObj.model&&(selectTreeList[selectTreeList.length - 1] = this.addObj.model)
         selectStandardProductList({
           model: this.addObj.model?this.addObj.model:row.model,
           modelNum: row.modelNum,
           standardMethodListId: val,
           cores: row.cores,
-          factory: selectTreeList.join(" - "),
+          factory: this.buildFactoryPath(this.addObj.model),
         }).then(res => {
           res.data.forEach(a => {
-            a.state = 0
+            a.state = this.inspectionScope === 'all' ? 1 : 0
           })
           row.insProduct = this.HaveJson(res.data)
           this.getProductLoad = false
@@ -1817,6 +1909,9 @@
             this.productList.forEach(a => {
               if (a.state == 1) this.toggleSelection(a)
             })
+            if (this.inspectionScope === 'all') {
+              this.handleAll(this.productList.filter(item => this.selectable0(item)))
+            }
           }, 200)
         })
       },
@@ -1842,13 +1937,13 @@
       },
       handleChangeModel(e) {
         this.productList = []
-        let num = this.selectTree.split('-').length;
-        if (num != 5) {
-          this.selectTree = this.selectTree + ' - ' + e
+        const tree = this.selectTree || ''
+        // 璺緞鏈宸叉槸鏍囧噯(鍙跺瓙)锛氭浛鎹㈡湯娈碉紱鍚﹀垯杩藉姞
+        // 鐢ㄨ矾寰勫垽瀹氾細妯℃澘鍥炲~(obj.selectTree)鏃舵病鏈夊彲鐢ㄧ殑鏍戣妭鐐瑰璞�
+        if (isLeafPath(tree)) {
+          this.selectTree = this.buildFactoryPath(e)
         } else {
-          let arr = this.selectTree.split('-')
-          let arr0 = arr.slice(0, arr.length - 1)
-          this.selectTree = arr0.join('-') + '- ' + e
+          this.selectTree = tree ? tree + ' - ' + e : e
         }
       },
       // 瑕佹眰鍊煎彉鍖栨椂
@@ -1885,7 +1980,7 @@
         }
       },
       selectable0(row,index) {
-        if (this.active > 1||row.repetitionTag) {
+        if (!this.canSelectProduct||row.repetitionTag) {
           return false
         } else {
           return true
@@ -1956,17 +2051,51 @@
             return item
           })
         }
-        this.productList.forEach(item => {
-          if (item.id == row.id) {
-            item.state = row.state;
-          }
-        })
         this.changeProductList0()
         this.currentMethod.insProduct = this.productList0
+        this.inspectionScope = e.length > 0 ? 'all' : 'specified'
         this.getProNum()
         this.$nextTick(() => {
           this.$refs.productTable.doLayout()
         })
+      },
+      changeInspectionScope(scope) {
+        if (scope !== 'all' || this.productList.length === 0) return
+        this.$refs.productTable.clearSelection()
+        this.productList.forEach(item => {
+          if (this.selectable0(item)) this.$refs.productTable.toggleRowSelection(item, true)
+        })
+        this.handleAll(this.productList.filter(item => this.selectable0(item)))
+      },
+      inspectionProductKey(product) {
+        return [
+          product.structureItemParameterId,
+          product.inspectionItemClass,
+          product.inspectionItem,
+          product.inspectionItemSubclass
+        ].join('|')
+      },
+      loadSelectableProducts(sample) {
+        const selectedProducts = sample.insProduct || []
+        if (!sample.standardMethodListId) return Promise.resolve(sample)
+        const product = selectedProducts[0] || {}
+        const factory = this.buildFactoryPath(product.model || sample.model)
+        return selectStandardProductList({
+          model: sample.model,
+          modelNum: sample.modelNum,
+          standardMethodListId: sample.standardMethodListId,
+          factory,
+          cores: sample.cores,
+          conductorMaterial: sample.conductorMaterial,
+          conductorType: sample.conductorType
+        }).then(res => {
+          const selectedKeys = new Set(selectedProducts.map(item => this.inspectionProductKey(item)))
+          const availableProducts = (res.data || [])
+            .filter(item => !selectedKeys.has(this.inspectionProductKey(item)))
+            .map((item, index) => ({...item, id: `new-${sample.id}-${index}`, state: 0, isNew: true}))
+          sample.insProduct = selectedProducts.concat(availableProducts)
+          return sample
+        }).catch(() => sample)
       },
       submitTell() {
         if (!this.tell) {
@@ -2151,8 +2280,8 @@
         })
       },
       changeUser(){
-        if(this.sonLaboratoryList.length>0){
-          this.distributeData.sonLaboratory = this.sonLaboratoryList[0].value
+        if(this.newJuLaboratoryList.length>0){
+          this.distributeData.sonLaboratory = this.newJuLaboratoryList[0].value
         }
       },
       addProductList(productList,row,index){

--
Gitblit v1.9.3