From 506cb425d38489e47e05bd05c0c5ad1e37e7153f Mon Sep 17 00:00:00 2001
From: songshankun <songshankun@foxmail.com>
Date: 星期三, 27 九月 2023 16:41:06 +0800
Subject: [PATCH] fix: 采购订单状态是为已完成时隐藏提交按钮;添加缺少的 catch;添加产品参数删除更新时间

---
 src/views/purchaseManage/purchase/components/AddPurchase.vue |  216 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 169 insertions(+), 47 deletions(-)

diff --git a/src/views/purchaseManage/purchase/components/AddPurchase.vue b/src/views/purchaseManage/purchase/components/AddPurchase.vue
index 8211eb2..260540a 100644
--- a/src/views/purchaseManage/purchase/components/AddPurchase.vue
+++ b/src/views/purchaseManage/purchase/components/AddPurchase.vue
@@ -27,7 +27,8 @@
                 <el-form-item
                   label="閲囪喘绫诲瀷"
                   prop="purchaseTypeId"
-                  class="form-item float_left"
+                  class="float_left"
+                  style="width:100%;"
                 >
                   <el-select
                     placeholder="璇烽�夋嫨閲囪喘绫诲瀷"
@@ -37,9 +38,9 @@
                   >
                     <el-option
                       v-for="ele in plcBrandList"
-                      :key="ele.id"
+                      :key="ele.name"
                       :label="ele.name"
-                      :value="ele.name"
+                      :value="ele.ID"
                     ></el-option>
                   </el-select>
                   <i
@@ -85,9 +86,9 @@
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="鍗曟嵁鏉ユ簮" prop="number">
+                <el-form-item label="鍗曟嵁鏉ユ簮" prop="orderSource">
                   <el-input
-                    v-model="editConfig.infomation.number"
+                    v-model="editConfig.infomation.orderSource"
                     disabled
                     placeholder="璇峰~鍐�"
                   ></el-input>
@@ -166,7 +167,9 @@
               :show-summary="showSummary"
               :recalculateShow="false"
               :product-table-list="productTableList"
+              sign="purchase"
               @inputContent="inputContent"
+              @getSummaries="getSummaries"
               @addProductClick="addProductClick"
               @emptyProductClick="emptyProductClick"
               @clearupProduct="clearupProduct"
@@ -177,9 +180,10 @@
               <div class="table-bottom-l">
                 <el-form-item label="鏁村崟鎶樻墸" prop="member_id">
                   <el-select
-                    v-model="editConfig.infomation.fieldName"
+                    v-model="editConfig.infomation.wholeDiscountType"
                     placeholder="璇烽�夋嫨"
                     filterable
+                    @change="getTotal"
                   >
                     <el-option label="鐧惧垎姣旈檷浠�" :value="1"></el-option>
                     <el-option label="鐩存帴闄嶄环" :value="2"></el-option>
@@ -189,8 +193,10 @@
               <div class="table-bottom-r">
                 <el-form-item label="" prop="member_id">
                   <el-input
-                    v-model="editConfig.infomation.number"
+                    v-model="editConfig.infomation.wholeDiscount"
                     size="mini"
+                    :disabled="editConfig.infomation.wholeDiscountType?false:true"
+                    @change="getTotal"
                     placeholder="璇峰~鍐�"
                   ></el-input>
                 </el-form-item>
@@ -200,9 +206,10 @@
               <div class="table-bottom-l">
                 <el-form-item label="璋冩暣" prop="member_id">
                   <el-select
-                    v-model="editConfig.infomation.fieldName"
+                    v-model="editConfig.infomation.priceAdjustmentType"
                     placeholder="璇烽�夋嫨"
                     filterable
+                    @change="getTotal"
                   >
                     <el-option label="澧炲姞" :value="1"></el-option>
                     <el-option label="鍑忓皯" :value="2"></el-option>
@@ -212,8 +219,10 @@
               <div class="table-bottom-r">
                 <el-form-item label="" prop="member_id">
                   <el-input
-                    v-model="editConfig.infomation.number"
+                    v-model="editConfig.infomation.priceAdjustment"
                     size="mini"
+                    :disabled="editConfig.infomation.priceAdjustmentType?false:true"
+                    @change="getTotal"
                     placeholder="璇峰~鍐�"
                   ></el-input>
                 </el-form-item>
@@ -221,7 +230,7 @@
             </div>
             <div class="table-bottom-item">
               <div class="table-bottom-l">鍚堣</div>
-              <div class="table-bottom-r">26000.00</div>
+              <div class="table-bottom-r">{{ total }}</div>
             </div>
           </div>
         </div>
@@ -246,6 +255,7 @@
       ref="editDialog"
       @sucessSet="handleGetBomKindDictList"
       @handleConfirmSave="handleConfirmSave"
+      :editRow="editRow"
       :workList="plcBrandList"
       title="閲囪喘绫诲瀷"
     ></BomDialog>
@@ -259,11 +269,10 @@
 import {
   addPurchase,
   updatePurchase,
+  savePurchaseType,
+  getPurchaseType,
 } from "@/api/purchaseManage/purchase";
-// import {
-//   postGetUnitDictList,
-//   postGetSaveSUnitDict,
-// } from "@/api/purchaseManage/purchase";
+
 import SelectSupplierDialog from "@/views/purchaseManage/purchase/components/SelectSupplierDialog";
 export default {
   name: "QuotationDialog",
@@ -284,6 +293,7 @@
     return {
       editConfig: this.editCommonConfig,
       rules: {
+        purchaseTypeId:[{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
         supplierName: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
         phone: [
           {
@@ -293,12 +303,29 @@
           },
           { validator: this.validatorPhone, trigger: "change" },
         ],
+        wholeDiscount: [
+          {
+            required: false,
+            message: "璇峰~鍐�0-100鐨勬暟瀛�",
+            trigger: "change",
+          },
+          { validator: this.validatorNum, trigger: "change" },
+        ],
+        priceAdjustment: [
+          {
+            required: false,
+            message: "璇峰~鍐�",
+            trigger: "change",
+          },
+          { validator: this.validatorNumThree, trigger: "change" },
+        ],
       },
       productTableList: {},
       showSummary: {
         show: true,
         total: false,
         sumProp: ["price", "total"],
+        multiply:['amount','price'],
         titleProp: [
           "缂栧彿",
           "浜у搧鍚嶇О",
@@ -309,6 +336,7 @@
           "鎻忚堪",
         ],
         mergeNumber: 4,
+        totalName:'灏忚'
       },
       editSelectSupplierConfig: {
         editVisible: false,
@@ -321,10 +349,15 @@
       isNoProduct: true,
       clientList: [],
       plcBrandList:[],
+      editRow:{
+        isDefault:'pin'
+      },
+      total:0,
+      totalTwo:0,
     };
   },
   created() {
-    this.setTableForm();
+    this.handleGetBomKindDictList();
   },
   computed: {
   },
@@ -332,46 +365,94 @@
     'editCommonConfig.visible':{
       immediate:true,
       handler:function(){
-        this.setTableForm();
+        
+        this.handleGetBomKindDictList(true);
       }
     }
   },
   methods: {
+    validatorNum(rule, value, callback) {
+      if(this.editConfig.infomation.wholeDiscountType==1){
+        if(value==undefined||value==null||(!value&&value!=0)){
+          callback(new Error("璇疯緭鍏ユ湁鏁堟暟瀛�"));
+        }else{
+          var reg=/^\+?[0-9]\d*$/
+          if(!reg.test(value)){
+            callback(new Error('璇峰~鍐�0-100鐨勬暟瀛�'))
+          }else{
+            if(Number(value)>100){
+              callback(new Error('璇峰~鍐�0-100鐨勬暟瀛�'))
+            }else{
+              callback()
+            }
+          }
+        }  
+      }else{
+        this.validatorNumThree(rule, value, callback)
+      }   
+    },
+    validatorNumThree(rule, value, callback){
+      if(value){
+        if(value==undefined||value==null){
+          callback(new Error("璇疯緭鍏ユ湁鏁堟暟瀛�"));
+        }else{
+          let reg2=/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
+          if(!reg2.test(value)){
+            callback(new Error('璇峰~鍐�2浣嶅皬鏁扮殑鏁板瓧'))
+          }else{
+            callback()
+          }
+        }
+      }else{
+        callback()
+      } 
+    },
     // PLC閰嶇疆璁剧疆
     handleShow() {
-      // this.handleGetBomKindDictList();
+      this.handleGetBomKindDictList();
       this.$refs.editDialog.editDialogVisible = true;
     },
     //  PLC閰嶇疆
     handleGetBomKindDictList(val) {
-      console.log(val,'val')
-      // postGetUnitDictList().then((res) => {
-      //   this.plcBrandList = res.data;
-      //   if (val) {
-      //     for (let i in this.plcBrandList) {
-      //       if (this.plcBrandList[i].isDefault) {
-      //         this.form.unit = this.form.unit
-      //           ? this.form.unit
-      //           : this.plcBrandList[i].name;
-      //         this.$set(this.form, "unit", this.form.unit);
-      //         break;
-      //       }
-      //     }
-      //   }
-      // });
+      getPurchaseType().then((res) => {
+        this.plcBrandList = res.data;
+        this.setTableForm()
+        if (val) {
+          for (let i in this.plcBrandList) {
+            if (this.plcBrandList[i][this.editRow.isDefault]) {
+              this.editConfig.infomation.purchaseTypeId = this.editConfig.infomation.purchaseTypeId
+                ? this.editConfig.infomation.purchaseTypeId
+                : this.plcBrandList[i].ID;
+              this.$set(this.editConfig.infomation, "purchaseTypeId", this.editConfig.infomation.purchaseTypeId);
+             
+              break;
+            }
+          }
+        }
+      });
     },
     handleConfirmSave(data) {
       console.log(data,'data')
-      // postGetSaveSUnitDict({ data: data }).then((res) => {
-      //   if (res.code == 200) {
-      //     this.$message({
-      //       message: "鎿嶄綔鎴愬姛锛�",
-      //       type: "success",
-      //     });
-      //     this.$refs.editDialog.editDialogVisible = false;
-      //     this.handleGetBomKindDictList();
-      //   }
-      // });
+      data.forEach(ele=>{
+        delete ele.created_at
+      })
+
+      savePurchaseType(data).then((res) => {
+        if (res.code === 200) {
+          this.$message({
+            message: "鎿嶄綔鎴愬姛锛�",
+            type: "success",
+          });
+          this.$refs.editDialog.editDialogVisible = false;
+          this.handleGetBomKindDictList(true);
+        }
+      },(err)=>{
+        console.error(err)
+        this.$message({
+          message: "鎿嶄綔澶辫触锛�",
+          type: "warning",
+        });
+      });
     },
     validatorPhone(rule, value, callback) {
       if (value) {
@@ -437,19 +518,32 @@
       });
     },
     saveParams() {
-      debugger
       let data =JSON.parse(JSON.stringify(this.editConfig.infomation));
+      
+      if(this.editConfig.infomation.wholeDiscountType==2&&this.editConfig.infomation.wholeDiscount){
+        if(Number(this.editConfig.infomation.wholeDiscount)>Number(this.totalTwo)){
+            this.$message.error('鐩存帴闄嶄环涓嶈兘瓒呰繃浠风◣鍚堣鐨勬�诲拰锛�')
+            return true;
+        }
+      }
       let params = {
         productList:this.tableData,
         purchase:{
           supplierId:this.supplierId||0,
           signingDate:data.signingDate||'',
           remark:data.remark,
-          purchaseTypeId:this.purchaseTypeId||0,
+          orderSource:data.orderSource||'',
+          purchaseTypeId:data.purchaseTypeId||0,
           phone:data.phone||'',
           name:data.name||'',
           deliveryDate:data.deliveryDate||'',
-          contact:data.contact
+          contact:data.contact,
+          wholeDiscountType:data.wholeDiscountType?data.wholeDiscountType:0,
+          wholeDiscount:data.wholeDiscount?Number(data.wholeDiscount):0,
+          priceAdjustmentType:data.priceAdjustmentType?data.priceAdjustmentType:0,
+          priceAdjustment:data.priceAdjustment?Number(data.priceAdjustment):0,
+          realTotalPrice:this.total?Number(this.total):0,
+          totalPrice:this.totalTwo?Number(this.totalTwo):0,
         }
       };
       if(data.ID){
@@ -530,10 +624,11 @@
           {
             label: "浜у搧鍚嶇О",
             prop: "name",
+            min: 180,
             productName: true,
             isRequird: true,
           },
-          { label: "浜у搧缂栧彿", prop: "number" },
+          { label: "浜у搧缂栧彿", prop: "number", min: 150,},
           { label: "璁¢噺鍗曚綅", prop: "unit" },
           { label: "瑙勬牸鍨嬪彿", prop: "specifications" },
           { label: "鏁伴噺", prop: "amount", inputNumber: true, isRequird: true },
@@ -543,10 +638,12 @@
             inputFloat: true,
             isRequird: true,
           },
-          { label: "浠风◣鍚堣", prop: "total", inputFloat: true },
+          { label: "浠风◣鍚堣", prop: "total", inputFloat: true,disabled:true,multiply:true, },
           { label: "鎻忚堪", prop: "remark", input: true },
         ],
       };
+      this.toal=this.editConfig.infomation.realTotalPrice
+     
     },
     // 浜у搧鍒楄〃杈撳叆
     inputContent(val, prop, row) {
@@ -556,6 +653,31 @@
           item[prop] = val;
         }
       });
+     
+    },
+    getSummaries(total){
+      this.totalTwo= JSON.parse(JSON.stringify(total));
+      this.total=total;
+      this.getTotal()
+    },
+    getTotal(){
+      let prie=0
+      if(this.editConfig.infomation.priceAdjustmentType==1){
+        prie=Number(this.editConfig.infomation.priceAdjustment)
+      }else if(this.editConfig.infomation.priceAdjustmentType==2){
+        prie=(-1)*Number(this.editConfig.infomation.priceAdjustment)
+      }else{
+        prie=0
+      }
+      let t=0
+      if(this.editConfig.infomation.wholeDiscountType==1){
+        t=this.totalTwo*Number(this.editConfig.infomation.wholeDiscount)/100
+      }else if(this.editConfig.infomation.wholeDiscountType==2){
+        t=Number(this.editConfig.infomation.wholeDiscount)
+      }else{
+        t=0
+      }
+      this.total=this.totalTwo-t+Number(prie)
     },
     // 浜у搧鏂板
     addProductClick() {

--
Gitblit v1.8.0