From 84d9de8968ea6675ecb57fa7c59a7bf2fede8f4d Mon Sep 17 00:00:00 2001
From: zuozhengqing <a13193816592@163.com>
Date: 星期三, 06 十二月 2023 16:45:44 +0800
Subject: [PATCH] 采购管理新增和编辑时供应商是否可以提供当前产品提示优化

---
 src/views/purchaseManage/purchase/components/AddPurchase.vue |  234 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 192 insertions(+), 42 deletions(-)

diff --git a/src/views/purchaseManage/purchase/components/AddPurchase.vue b/src/views/purchaseManage/purchase/components/AddPurchase.vue
index 260540a..a69d2d1 100644
--- a/src/views/purchaseManage/purchase/components/AddPurchase.vue
+++ b/src/views/purchaseManage/purchase/components/AddPurchase.vue
@@ -31,6 +31,7 @@
                   style="width:100%;"
                 >
                   <el-select
+                    :disabled="editConfig.isDisabled"
                     placeholder="璇烽�夋嫨閲囪喘绫诲瀷"
                     v-model="editConfig.infomation.purchaseTypeId"
                     clearable
@@ -44,6 +45,7 @@
                     ></el-option>
                   </el-select>
                   <i
+                    v-if="!editConfig.isDisabled"
                     class="el-icon-setting margin_left_10px cursor_pointer"
                     style="font-size: 20px; color: #333"
                     @click="handleShow"
@@ -55,11 +57,12 @@
                 <el-form-item label="渚涘簲鍟嗗悕绉�" prop="supplierName">
                   <div class="custom-name">
                     <el-autocomplete
+                      :disabled="editConfig.isDisabled"
                       style="width: calc(100% - 40px)"
                       v-model="editConfig.infomation.supplierName"
                       :fetch-suggestions="
                         (queryString, callback) => {
-                          querySearchAsync(queryString, callback, 'client');
+                          querySearchAsync(queryString, callback, 'supplier');
                         }
                       "
                       value-key="name"
@@ -67,6 +70,7 @@
                       @select="handleSelectClient('client', $event)"
                     ></el-autocomplete>
                     <div
+                      v-if="!editConfig.isDisabled"
                       class="common-select-btn"
                       @click="selClientClick('client')"
                     >
@@ -80,7 +84,8 @@
                       class="common-select-btn"
                       @click="clearupClient('client')"
                     >
-                      <i class="el-icon-remove-outline" title="娓呴櫎"></i>
+                      <i class="el-icon-remove-outline" 
+                      v-if="!editConfig.isDisabled" title="娓呴櫎"></i>
                     </div>
                   </div>
                 </el-form-item>
@@ -97,6 +102,7 @@
               <el-col :span="12">
                 <el-form-item label="閲囪喘鍗曞悕绉�" prop="name">
                   <el-input
+                    :disabled="editConfig.isDisabled"
                     v-model="editConfig.infomation.name"
                     placeholder="璇峰~鍐�"
                     clearable
@@ -106,6 +112,7 @@
               <el-col :span="12">
                 <el-form-item label="渚涘簲鍟嗚仈绯讳汉" prop="contact">
                   <el-input
+                    :disabled="editConfig.isDisabled"
                     v-model="editConfig.infomation.contact"
                     placeholder="璇峰~鍐�"
                     clearable
@@ -115,8 +122,11 @@
               <el-col :span="12">
                 <el-form-item label="鑱旂郴鐢佃瘽" prop="phone">
                   <el-input
+                    :disabled="editConfig.isDisabled"
                     v-model="editConfig.infomation.phone"
                     placeholder="璇峰~鍐�"
+                    maxlength="11"
+                    show-word-limit
                     clearable
                   ></el-input>
                 </el-form-item>
@@ -124,6 +134,7 @@
               <el-col :span="12">
                 <el-form-item label="绛剧害鏃ユ湡" prop="signingDate">
                   <el-date-picker
+                    :disabled="editConfig.isDisabled"
                     v-model="editConfig.infomation.signingDate"
                     style="width: 100%"
                     type="date"
@@ -137,6 +148,7 @@
               <el-col :span="12">
                 <el-form-item label="浜や粯鏃ユ湡" prop="deliveryDate">
                   <el-date-picker
+                    :disabled="editConfig.isDisabled"
                     v-model="editConfig.infomation.deliveryDate"
                     style="width: 100%"
                     type="date"
@@ -150,6 +162,7 @@
               <el-col :span="24">
                 <el-form-item label="澶囨敞淇℃伅" prop="remark">
                   <el-input
+                    :disabled="editConfig.isDisabled"
                     type="textarea"
                     :autosize="{ minRows: 3, maxRows: 4 }"
                     maxlength="500"
@@ -164,6 +177,7 @@
           <div class="basic-info-title" style="display: flex">浜у搧淇℃伅</div>
           <div class="product-view">
             <CommonFormTableView
+              :detailEnter=editCommonConfig.detailEnter
               :show-summary="showSummary"
               :recalculateShow="false"
               :product-table-list="productTableList"
@@ -173,6 +187,8 @@
               @addProductClick="addProductClick"
               @emptyProductClick="emptyProductClick"
               @clearupProduct="clearupProduct"
+              @rowClick="rowClick"
+              @handleProduct="handleProduct"
             />
           </div>
           <div class="table-bottom">
@@ -182,6 +198,7 @@
                   <el-select
                     v-model="editConfig.infomation.wholeDiscountType"
                     placeholder="璇烽�夋嫨"
+                    :disabled="editConfig.isDisabled"
                     filterable
                     @change="getTotal"
                   >
@@ -195,7 +212,7 @@
                   <el-input
                     v-model="editConfig.infomation.wholeDiscount"
                     size="mini"
-                    :disabled="editConfig.infomation.wholeDiscountType?false:true"
+                    :disabled="editConfig.isDisabled"
                     @change="getTotal"
                     placeholder="璇峰~鍐�"
                   ></el-input>
@@ -206,6 +223,7 @@
               <div class="table-bottom-l">
                 <el-form-item label="璋冩暣" prop="member_id">
                   <el-select
+                    :disabled="editConfig.isDisabled"
                     v-model="editConfig.infomation.priceAdjustmentType"
                     placeholder="璇烽�夋嫨"
                     filterable
@@ -219,9 +237,9 @@
               <div class="table-bottom-r">
                 <el-form-item label="" prop="member_id">
                   <el-input
+                    :disabled="editConfig.isDisabled"
                     v-model="editConfig.infomation.priceAdjustment"
                     size="mini"
-                    :disabled="editConfig.infomation.priceAdjustmentType?false:true"
                     @change="getTotal"
                     placeholder="璇峰~鍐�"
                   ></el-input>
@@ -237,10 +255,10 @@
       </el-form>
       <div slot="footer" class="dialog-footer">
         <!-- <el-button type="primary" size="small" @click="editConfig.visible = false">淇濆苟鎻愪氦瀹℃壒</el-button> -->
-        <el-button type="primary" size="small" @click="saveClick('form')"
+        <el-button type="primary" v-if="this.editConfig.title != '鏌ョ湅'" size="small" @click="saveClick('form')"
           >淇濆瓨</el-button
         >
-        <el-button size="small" @click="editConfig.visible = false"
+        <el-button size="small" v-if="this.editConfig.title != '鏌ョ湅'" @click="editConfig.visible = false"
           >鍙栨秷</el-button
         >
       </div>
@@ -265,6 +283,7 @@
 <script>
 import CommonFormTableView from "@/components/makepager/CommonFormTableView";
 import BomDialog from "@/components/makepager/BomDialog";
+import { getProductList } from "@/api/productManage/product"
 
 import {
   addPurchase,
@@ -274,6 +293,7 @@
 } from "@/api/purchaseManage/purchase";
 
 import SelectSupplierDialog from "@/views/purchaseManage/purchase/components/SelectSupplierDialog";
+// import { formToJSON } from "axios";
 export default {
   name: "QuotationDialog",
   components: { SelectSupplierDialog, CommonFormTableView,BomDialog },
@@ -282,6 +302,7 @@
       type: Object,
       default: () => {
         return {
+          detailEnter:true,
           visible: false,
           title: "鍒涘缓",
           infomation: {},
@@ -345,7 +366,8 @@
       },
       supplierId: this.editCommonConfig.infomation.supplierId,
       tableData: [],
-      productId: 1,
+      productIndex: 0,
+      productId:'',
       isNoProduct: true,
       clientList: [],
       plcBrandList:[],
@@ -354,12 +376,18 @@
       },
       total:0,
       totalTwo:0,
+      productListIdx:0,
+      lacks:[],
     };
   },
   created() {
     this.handleGetBomKindDictList();
+    this.$store.dispatch("getSupplier")
   },
   computed: {
+    supplierList() {
+      return this.$store.state.getSupplierName.supplierList
+    }
   },
   watch:{
     'editCommonConfig.visible':{
@@ -491,24 +519,93 @@
             this.$message.error("浜у搧鍚嶇О涓嶈兘涓虹┖");
           } else {
             const params = this.saveParams();
-            console.log(params);
+            //鏂板缓
             if (this.editConfig.title === "鍒涘缓") {
-              addPurchase(params).then((res) => {
-                console.log(res);
-                this.editConfig.visible = false;
-                if (res.code === 200) {
-                  this.$message.success("娣诲姞鎴愬姛");
-                  this.$parent.getData();
+              this.lacks=[]
+              this.tableData.forEach((item)=>{
+                if(this.productTableList.tableProductList.map(obj => obj.number).includes(item.number)) {  
+                    console.log(`${item.name} 鍦ㄦ暟缁勪腑瀛樺湪`);  
+                } else {
+                  this.lacks.push(item.name)
                 }
-              });
+              })
+              if(this.lacks.length>0){
+                this.$confirm(`褰撳墠渚涘簲鍟嗕笉鑳芥彁渚涙偍閫夋嫨鐨勪骇鍝�:${this.lacks},    鏄惁缁х画鍒涘缓閲囪喘鍗�?`, '鎻愮ず', {
+                  confirmButtonText: '纭畾',
+                  cancelButtonText: '鍙栨秷',
+                  type: 'warning'
+                }).then(() => {
+                  console.log("纭畾鍒涘缓")
+                  //鍒涘缓閲囪喘鍗�
+                  addPurchase(params).then((res) => {
+                    this.editConfig.visible = false;
+                    if (res.code === 200) {
+                      this.$message.success("鍒涘缓鎴愬姛");
+                      this.$parent.getData();
+                    }
+                  });
+                }).catch(() => {
+                  console.log("鍙栨秷鍒涘缓")
+                });
+              }else{
+                addPurchase(params).then((res) => {
+                  this.editConfig.visible = false;
+                  if (res.code === 200) {
+                    this.$message.success("鍒涘缓鎴愬姛");
+                    this.$parent.getData();
+                  }
+                });
+              }
             } else {
-              updatePurchase(params).then((res) => {
-                this.editConfig.visible = false;
-                if (res.code === 200) {
-                  this.$message.success("缂栬緫鎴愬姛");
-                  this.$parent.getData();
+              // 缂栬緫
+              getProductList({
+                supplierId:this.editConfig.infomation.supplierId,
+                page:1,
+                pageSize:100
+              }).then((res)=>{
+                if(res.code===200){
+                  this.lacks=[]
+                  // 缂栬緫鍓嶅厛鐪嬬湅褰撳墠渚涘簲鍟嗗搴旂殑浜у搧鍒楄〃
+                  this.productTableList.tableProductList = res.data.list
+                  //褰撳墠浜у搧鏄惁鍦ㄥ綋鍓嶄緵搴斿晢涓嬪瓨鍦�
+                  this.tableData.forEach((item)=>{
+                    if(this.productTableList.tableProductList.map(obj => obj.number).includes(item.number)) {  
+                      console.log(`${item.name} 鍦ㄦ暟缁勪腑瀛樺湪`);  
+                    } else {
+                      this.lacks.push(item.name)
+                    }
+                  })
+                  // 涓嶅瓨鍦ㄧ殑浜у搧淇℃伅
+                  if(this.lacks.length>0){
+                    this.$confirm(`褰撳墠渚涘簲鍟嗕笉鑳芥彁渚涙偍閫夋嫨鐨勪骇鍝�:${this.lacks},    鏄惁缁х画鏇存柊閲囪喘鍗�?`, '鎻愮ず', {
+                      confirmButtonText: '纭畾',
+                      cancelButtonText: '鍙栨秷',
+                      type: 'warning'
+                    }).then(() => {
+                      console.log("纭畾鏇存柊")
+                      //鏇存柊閲囪喘鍗�
+                      updatePurchase(params).then((res) => {
+                        this.editConfig.visible = false;
+                        if (res.code === 200) {
+                          this.$message.success("鏇存柊鎴愬姛");
+                          this.$parent.getData();
+                        }
+                      });
+                    }).catch(() => {
+                      console.log("鍙栨秷鏇存柊")
+                    });
+                  }else {
+                    updatePurchase(params).then((res) => {
+                      this.editConfig.visible = false;
+                      if (res.code === 200) {
+                        this.$message.success("鏇存柊鎴愬姛");
+                        this.$parent.getData();
+                      }
+                    });
+                  }
                 }
-              });
+              })
+              
             }
           }
         } else {
@@ -529,7 +626,7 @@
       let params = {
         productList:this.tableData,
         purchase:{
-          supplierId:this.supplierId||0,
+          supplierId:data.supplierId,
           signingDate:data.signingDate||'',
           remark:data.remark,
           orderSource:data.orderSource||'',
@@ -544,6 +641,8 @@
           priceAdjustment:data.priceAdjustment?Number(data.priceAdjustment):0,
           realTotalPrice:this.total?Number(this.total):0,
           totalPrice:this.totalTwo?Number(this.totalTwo):0,
+          status:data.status,
+          quantity:data.quantity, // 閲囪喘鏁伴噺
         }
       };
       if(data.ID){
@@ -556,9 +655,10 @@
     },
     // 閫夋嫨瀹㈡埛鐩稿叧鏂规硶
     querySearchAsync(queryString, cb, value) {
+      this.productTableList.tableProductList=[]
       var restaurants = [];
-      if (value === "client") {
-        restaurants = this.clientList;
+      if (value === "supplier") {
+        restaurants = this.supplierList;
       } 
       var results = queryString
         ? restaurants.filter(this.createStateFilter(queryString))
@@ -572,20 +672,41 @@
         );
       };
     },
-    handleSelectClient(value, item) {
-      console.log(value);
+    // 閫夋嫨渚涘簲鍟�
+    async handleSelectClient(value, item) {
+      this.productTableList.supplierId=item.ID
       if (value === "client") {
         this.supplierId = item.id;
+        this.editConfig.infomation.supplierId=item.ID
       }
+      await getProductList({
+        supplierId:item.ID,
+        page:1,
+        pageSize:100
+      }).then((res)=>{
+        if(res.code===200){
+          this.productTableList.tableProductList = res.data.list
+          console.log(this.productTableList.tableProductList,"pop")
+        }
+      })
     },
     selClientClick() {
       this.editSelectSupplierConfig.editVisible = true;
     },
-    selClient(row) {
+    async selClient(row) {
+      await getProductList({
+        supplierId:row.ID,
+        page:1,
+        pageSize:100
+      }).then((res)=>{
+        if(res.code===200){
+          this.productTableList.tableProductList = res.data.list
+        }
+      })
       this.$set(this.editConfig.infomation,'supplierName',row.name)
       this.editConfig.infomation.contact = row.contact;
       this.editConfig.infomation.phone = row.phone;
-      this.supplierId = row.ID;
+      this.editConfig.infomation.supplierId = row.ID;
     },
     // 娓呴櫎宸查�夋嫨鐢ㄦ埛
     clearupClient(value) {
@@ -602,14 +723,21 @@
       ) {
         this.tableData = [
           {
+            purchaseId:0,
             productId: this.productId,
-            id: 0,
+            productIndex:this.productIndex,
             amount: 0,
-            desc: "",
             name: "",
             number: "",
             price: 0,
             total: 0,
+            remark:'',
+            unit:'',
+            purchasePrice:'',
+            deliveryTime:"",
+            shippingDuration:"",
+            specifications:"",
+            modelNumber:"",
           },
         ];
       } else {
@@ -619,7 +747,10 @@
         // });
       }
       this.productTableList = {
+        tableProductList:[],
+        supplierId:undefined,
         tableData: this.tableData,
+        disabled:this.editConfig.isDisabled,
         tableColumn: [
           {
             label: "浜у搧鍚嶇О",
@@ -627,19 +758,21 @@
             min: 180,
             productName: true,
             isRequird: true,
+            disabled:this.editConfig.isDisabled,
           },
           { label: "浜у搧缂栧彿", prop: "number", min: 150,},
           { label: "璁¢噺鍗曚綅", prop: "unit" },
-          { label: "瑙勬牸鍨嬪彿", prop: "specifications" },
-          { label: "鏁伴噺", prop: "amount", inputNumber: true, isRequird: true },
+          { label: "瑙勬牸鍨嬪彿", prop: "specifications",},
+          { label: "鏁伴噺", prop: "amount", inputNumber: true,disabled:this.editConfig.isDisabled, },
           {
             label: "閲囪喘鍗曚环",
             prop: "price",
             inputFloat: true,
             isRequird: true,
+            disabled:this.editConfig.isDisabled,
           },
-          { label: "浠风◣鍚堣", prop: "total", inputFloat: true,disabled:true,multiply:true, },
-          { label: "鎻忚堪", prop: "remark", input: true },
+          { label: "浠风◣鍚堣", prop: "total", inputFloat: true,disabled:this.editConfig.isDisabled,multiply:true, },
+          { label: "鎻忚堪", prop: "remark", input: true,disabled:this.editConfig.isDisabled},
         ],
       };
       this.toal=this.editConfig.infomation.realTotalPrice
@@ -647,13 +780,18 @@
     },
     // 浜у搧鍒楄〃杈撳叆
     inputContent(val, prop, row) {
-      this.productId = row.productId;
+      // this.productId = row.productId;
+      this.productIndex=row.productIndex;
+      let num=0
       this.tableData.map((item) => {
-        if (item.productId === row.productId) {
+        num+=item.amount
+        if (item.productIndex === row.productIndex) {
           item[prop] = val;
         }
       });
-     
+      if(prop==="amount"){
+        this.editConfig.infomation.quantity=num
+      }
     },
     getSummaries(total){
       this.totalTwo= JSON.parse(JSON.stringify(total));
@@ -681,9 +819,10 @@
     },
     // 浜у搧鏂板
     addProductClick() {
-      this.productId++;
+      this.productIndex++;
       this.tableData.push({
-        productId: this.productId,
+        productIndex: this.productIndex,
+        productId:'',
         id: 0,
         amount: 0,
         desc: "",
@@ -696,12 +835,13 @@
     },
     //  浜у搧娓呯┖
     emptyProductClick() {
-      this.productId = 1;
+      this.productIndex = 1;
       this.tableData = [
         {
-          productId: this.productId,
+          productId: '',
+          productIndex:this.productIndex,
           id: 0,
-          amount: 0,
+          amount: "0",
           desc: "",
           name: "",
           number: "",
@@ -715,6 +855,16 @@
       this.tableData = data;
       this.productTableList.tableData = this.tableData;
     },
+    //閫夋嫨琛�
+    rowClick(row){
+      console.log(row,"xuanze")
+      this.productListIdx=row.productIndex
+    },
+    //閫変腑浜у搧
+    handleProduct(item){
+      this.tableData[this.productListIdx].productId=item.ID
+      console.log(item,"閫変腑浜у搧",this.tableData)
+    }
   },
 };
 </script>

--
Gitblit v1.8.0