From e132d7d87ff834eb231bd39c82c3be22bae2d80b Mon Sep 17 00:00:00 2001
From: XiaoRuby <3114200645@qq.com>
Date: 星期一, 28 八月 2023 09:10:59 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/views/standardLibrary/index.vue |  142 ++++++++++++++++++++++++++++-------------------
 1 files changed, 84 insertions(+), 58 deletions(-)

diff --git a/src/views/standardLibrary/index.vue b/src/views/standardLibrary/index.vue
index f6eeba1..5c69021 100644
--- a/src/views/standardLibrary/index.vue
+++ b/src/views/standardLibrary/index.vue
@@ -2,7 +2,10 @@
   <div class="standard-library-main">
     <div class="content-main">
       <div class="library-bom" style="width: 300px">
-        <el-input v-model="filterText" placeholder="杈撳叆鍏抽敭瀛楄繘琛岃繃婊�" />
+        <el-input
+          v-model="filterText"
+          placeholder="杈撳叆鍏抽敭瀛楄繘琛岃繃婊�"
+        ></el-input>
         <el-button type="text">鍏ㄩ儴</el-button>
         <el-tree
           ref="tree"
@@ -22,6 +25,16 @@
         <div class="table-header">
           <div class="serve-btn">
             <span class="tipMsg">{{ msg !== "" ? msg : "" }}</span>
+            <el-select v-model="versionValue" @change="changeSelect" placeholder="璇烽�夋嫨鐗堟湰鍙�">
+              <el-option
+                v-for="item in options"
+                :key="item.value"
+                :label="item.label"
+                :value="item.value"
+                >
+              </el-option>
+            </el-select>
+            <el-button type="primary" @click="addVersionFun">鏂板鐗堟湰鍙�</el-button>
             <el-button
               type="primary"
               icon="el-icon-plus"
@@ -41,13 +54,14 @@
           <el-table
             :data="tableData"
             style="width: 100%; margin-bottom: 20px"
-            row-key="name"
+            row-key="id"
             border
             height="calc(100vh - 250px)"
             default-expand-all
             ref="multipleTable"
             @select="selectTr"
             @select-all="selectAll"
+            @selection-change="handleSelectionChange"
             :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
           >
             <el-table-column type="selection" label="搴忓彿"> </el-table-column>
@@ -157,12 +171,16 @@
   addSpecifications,
   deleteListApi,
   blurUpdateApi,
+  getVersion,
+  addVersion
 } from "@/api/standardLibrary";
 
 import { selectproductModelApi } from "@/api/basicData/index";
 export default {
   data() {
     return {
+      options:[],
+      versionValue: '',
       deleteList: [],
       msg: "",
       isAllSelect: false,
@@ -195,10 +213,51 @@
   created() {
     this.getStandardTree();
   },
+  mounted(){
+    
+  },
   methods: {
+    async initSelect(){
+        this.options = [];
+        this.versionValue = "";
+        const response = await getVersion({"specificationsId":this.selectData.id});
+        if(response.code===200 && response.data.length>0){
+          this.getTableByClick(this.selectData,response.data[0])
+          for(let i=0;i<response.data.length;i++){
+            this.options.push({
+              value: response.data[i],
+              label: "V" + response.data[i]
+            })
+            this.versionValue = response.data[0];
+          }
+        }
+    },
+    changeSelect(){
+      this.tableData = [];
+      this.getTableByClick(this.selectData,this.versionValue);
+    },
+    async insertVersion(){
+      const resp = await addVersion({"specificationsId":this.selectData.id});
+      if(resp.code===200){
+        this.initSelect();
+        this.$message({
+            type: 'success',
+            message: resp.message
+          });
+      }
+    },
+     addVersionFun() {
+        this.$confirm('纭娣诲姞鏂扮殑鐗堟湰鍙峰悧?', '鎻愮ず', {
+          confirmButtonText: '纭畾',
+          cancelButtonText: '鍙栨秷',
+          type: 'warning'
+        }).then(() => {
+          this.insertVersion();
+        }).catch(() => {});
+    },
     filterNode(value, data) {
       if (!value) return true;
-      return data.label.indexOf(value) !== -1;
+      return data.name.indexOf(value) !== -1;
     },
     // 鑾峰彇bom鏍戠殑鏍囧噯鏁版嵁
     async getStandardTree() {
@@ -229,7 +288,6 @@
           ".el-tree-node .el-tree-node__children .el-tree-node .el-tree-node__children .el-tree-node .el-tree-node__children .el-tree-node"
         );
         firstNode.click();
-        // console.log(firstNode);
       });
     },
     getDefault(arr, index) {
@@ -250,8 +308,8 @@
         this.getParentData(node.parent, node.data.name);
         // 瀛樹笅閫変腑鑺傜偣
         this.selectData = data;
-        // eslint-disable-next-line prefer-const
-        this.getTableByClick(data);
+        this.getTableByClick(data,this.versionValue);
+        this.initSelect();
       }
       if (!("children" in data)) {
         return;
@@ -266,9 +324,10 @@
         this.getParentData(node.parent, this.msg);
       }
     },
-    async getTableByClick(data) {
+    async getTableByClick(data,versionVal) {
       await getProductList({
         specificationsId: data.id,
+        version: versionVal
       }).then((res) => {
         res.data.forEach((i) => {
           if (i.name === undefined) {
@@ -282,7 +341,6 @@
           }
         });
         this.tableData = res.data;
-        console.log(`output->this.tableData`, this.tableData);
         this.selectDataList();
       });
     },
@@ -316,7 +374,6 @@
     },
     async subAddTreeForm() {
       this.addTreeFormVisible = false;
-      console.log(this.addTreeForm.addTypeArr.length);
       let res = null;
       try {
         switch (this.addTreeForm.addTypeArr.length) {
@@ -346,14 +403,14 @@
         this.$message.error("娣诲姞澶辫触");
       }
 
-      console.log(res);
       this.$message.success("娣诲姞鎴愬姛");
-      this.addTreeForm = {};
+      this.addTreeForm = {
+        addTypeArr: [],
+      };
       this.getStandardTree();
-      this.getTableByClick(this.selectData);
+      this.getTableByClick(this.selectData,this.versionValue);
     },
     changeCascader(data) {
-      console.log(data);
       this.addTreeForm.addTypeArr = data;
     },
     closeAddTreeForm() {
@@ -400,21 +457,6 @@
       this.isAllSelect = !this.isAllSelect;
       let data = this.tableData;
       this.toggleSelect(data, this.isAllSelect, "all");
-      // 鑷畾涔�
-      if (this.isAllSelect) {
-        val.forEach((i) => {
-          if (i.id !== undefined) {
-            this.deleteList.push(i.id);
-          } else {
-            i.children.forEach((c) => {
-              this.deleteList.push(c.id);
-            });
-          }
-        });
-      } else {
-        this.deleteList.splice(0, this.deleteList.length);
-      }
-      console.log(`output->this.`, this.deleteList);
     },
     //閫夋嫨鏌愯
     selectTr(selection, row) {
@@ -423,34 +465,6 @@
         this.isAllSelect = row.isChecked;
         this.toggleSelect(row, row.isChecked, "tr");
       });
-
-      if (row.isChecked === true) {
-        if (row.children !== undefined) {
-          row.children.forEach((i) => {
-            this.deleteList.push(i.id);
-          });
-        } else {
-          this.deleteList.push(row.id);
-        }
-      } else if (row.isChecked === false) {
-        if (row.children !== undefined) {
-          row.children.forEach((i) => {
-            this.deleteList.findIndex((c, index) => {
-              if (c === i.id) {
-                this.deleteList.splice(index, 1);
-                return;
-              }
-            });
-          });
-        }
-        this.deleteList.findIndex((c, index) => {
-          if (c === row.id) {
-            this.deleteList.splice(index, 1);
-            return;
-          }
-        });
-      }
-      console.log(`output->this.deleteList`, this.deleteList);
     },
     //閫掑綊瀛愮骇
     toggleSelect(data, flag, type) {
@@ -484,6 +498,15 @@
         }
       });
     },
+    handleSelectionChange(val) {
+      this.deleteList = []
+      val.forEach((v) => {
+        if(v.id !== undefined){
+          this.deleteList.push(v.id)
+        }
+      })
+      console.log(`output->this.deleteList`,this.deleteList)
+    },
     // 琛ㄦ牸鏍戝叏閮ㄩ�変腑閰嶇疆  缁撴潫
     deleteListClick() {
       deleteListApi(this.deleteList).then((res) => {
@@ -491,7 +514,7 @@
           message: res.message,
           type: "success",
         });
-        this.getTableByClick(this.selectData);
+        this.getTableByClick(this.selectData,this.versionValue);
       });
     },
     async requiredOnfocus(scope) {
@@ -506,7 +529,7 @@
           message: res.message,
           type: "success",
         });
-        this.getTableByClick(this.selectData);
+        this.getTableByClick(this.selectData,this.versionValue);
       });
     },
   },
@@ -642,6 +665,9 @@
   width: 100%;
   padding-bottom: 6px;
   text-align: right;
+  .el-select{
+    margin-right:10px;
+  }
 }
 .tipMsg {
   float: left;

--
Gitblit v1.9.3