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/supplierManage/supplier/AddSupplier.vue |  324 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 242 insertions(+), 82 deletions(-)

diff --git a/src/views/supplierManage/supplier/AddSupplier.vue b/src/views/supplierManage/supplier/AddSupplier.vue
index 42d0ac3..c8dbfa4 100644
--- a/src/views/supplierManage/supplier/AddSupplier.vue
+++ b/src/views/supplierManage/supplier/AddSupplier.vue
@@ -14,7 +14,7 @@
         :model="editConfig.infomation"
         :rules="rules"
         label-position="right"
-        label-width="308px"
+        label-width="150px"
         size="mini"
       >
         <!-- 淇℃伅 -->
@@ -29,20 +29,25 @@
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="渚涘簲鍟嗗悕绉�" prop="supplier_name">
+                <el-form-item label="渚涘簲鍟嗗悕绉�" prop="name">
                   <el-input v-model="editConfig.infomation.name"></el-input>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="渚涘簲鍟嗙被鍨�" prop="supplierType_id">
+                <el-form-item label="渚涘簲鍟嗙被鍨�" prop="supplierType">
                   <div class="custom-name">
                     <el-select
-                      v-model="editConfig.infomation.supplierType_id"
+                      v-model="editConfig.infomation.supplierType"
                       placeholder="璇烽�夋嫨渚涘簲鍟嗙被鍨�"
                       class="common-select-sel"
                       size="mini"
                     >
-                      <el-option v-for="item in supplierTypeOptions" :key="item.id" :label="item.name" :value="item.id">
+                      <el-option
+                        v-for="(item, index) in supplierTypeOptions"
+                        :key="index"
+                        :label="item.name"
+                        :value="item.name"
+                      >
                       </el-option>
                     </el-select>
                     <div class="common-select-btn" @click="setSupplierType"><i class="el-icon-setting"></i></div>
@@ -50,15 +55,20 @@
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="鎵�灞炶涓�" prop="industry_id">
+                <el-form-item label="鎵�灞炶涓�" prop="industry">
                   <div class="custom-name">
                     <el-select
-                      v-model="editConfig.infomation.industry_id"
+                      v-model="editConfig.infomation.industry"
                       placeholder="璇烽�夋嫨渚涘簲鍟嗚涓�"
                       class="common-select-sel"
                       size="mini"
                     >
-                      <el-option v-for="item in industryOptions" :key="item.id" :label="item.name" :value="item.id">
+                      <el-option
+                        v-for="(item, index) in industryOptions"
+                        :key="index"
+                        :label="item.name"
+                        :value="item.name"
+                      >
                       </el-option>
                     </el-select>
                     <div class="common-select-btn" @click="setIndustry"><i class="el-icon-setting"></i></div>
@@ -66,8 +76,8 @@
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="鑱旂郴浜�" prop="contact_name">
-                  <el-input v-model="editConfig.infomation.contact_name"></el-input>
+                <el-form-item label="鑱旂郴浜�" prop="contact">
+                  <el-input v-model="editConfig.infomation.contact"></el-input>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
@@ -81,8 +91,22 @@
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="閿�鍞礋璐d汉" prop="sale_member">
-                  <el-input v-model="editConfig.infomation.sale_member" disabled></el-input>
+                <el-form-item label="閿�鍞礋璐d汉" prop="responsiblePersonName">
+                  <!-- <el-input v-model="editConfig.infomation.responsiblePersonId"></el-input> -->
+                  <el-select
+                    v-model="editConfig.infomation.responsiblePersonName"
+                    placeholder="璇烽�夋嫨"
+                    size="mini"
+                    style="width: 63%"
+                  >
+                    <el-option
+                      v-for="item in memberOptions"
+                      :key="item.id"
+                      :label="item.username"
+                      :value="item.userName"
+                    >
+                    </el-option>
+                  </el-select>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
@@ -91,19 +115,18 @@
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="璇︾粏鍦板潃" prop="address_detail">
+                <el-form-item label="璇︾粏鍦板潃" prop="detailAddress">
                   <el-input
                     type="textarea"
                     :autosize="{ minRows: 2 }"
                     placeholder="璇疯緭鍏ュ唴瀹�"
-                    v-model="editConfig.infomation.address_detail"
-                    disabled
+                    v-model="editConfig.infomation.detailAddress"
                   ></el-input>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="缃戝潃" prop="webUrl">
-                  <el-input v-model="editConfig.infomation.webUrl" disabled></el-input>
+                <el-form-item label="缃戝潃" prop="url">
+                  <el-input v-model="editConfig.infomation.url"></el-input>
                 </el-form-item>
               </el-col>
             </el-row>
@@ -113,18 +136,18 @@
           <div class="basic-info-view">
             <el-row>
               <el-col :span="12">
-                <el-form-item label="鎴峰悕" prop="account_name">
-                  <el-input v-model="editConfig.infomation.account_name" disabled></el-input>
+                <el-form-item label="鎴峰悕" prop="accountName">
+                  <el-input v-model="editConfig.infomation.accountName"></el-input>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="寮�鎴疯" prop="account_name">
-                  <el-input v-model="editConfig.infomation.account_name" disabled></el-input>
+                <el-form-item label="寮�鎴疯" prop="bank">
+                  <el-input v-model="editConfig.infomation.bank"></el-input>
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="璐﹀彿" prop="account_name">
-                  <el-input v-model="editConfig.infomation.account_name" disabled></el-input>
+                <el-form-item label="璐﹀彿" prop="account">
+                  <el-input v-model="editConfig.infomation.account"></el-input>
                 </el-form-item>
               </el-col>
               <el-col :span="24">
@@ -137,21 +160,34 @@
                       <span style="margin-left: 5px">鍚堝悓闄勪欢</span>
                     </div>
                   </template>
-                  <div class="annex-view">
+                  <div v-if="file_id === 0" class="annex-view">
                     <div @click="addAnnexClick">
-                      <div style="display: flex; float: right">
-                        <div style="font-size: 16px"><i class="el-icon-paperclip"></i></div>
-                        <span>娣诲姞闄勪欢</span>
-                      </div>
+                      <el-upload
+                        class="upload-demo"
+                        :headers="headers"
+                        action=""
+                        :limit="1"
+                        :before-upload="beforeAvatarUpload"
+                        :on-exceed="handleExceed"
+                        :file-list="fileList"
+                        :show-file-list="false"
+                      >
+                        <div style="display: flex; float: right">
+                          <div style="font-size: 16px"><i class="el-icon-paperclip"></i></div>
+                          <span>娣诲姞闄勪欢</span>
+                        </div>
+                      </el-upload>
                     </div>
                   </div>
-                  <div class="file-content">
-                    <div>鏂囦欢鍚嶇О</div>
+                  <!-- v-if="file_name && file_name.length > 0" -->
+                  <div v-else class="file-content">
+                    <div>{{ file_name }}</div>
                     <div>
-                      <el-button type="text">棰勮</el-button>
-                      <el-button type="text">涓嬭浇</el-button>
-                      <el-button type="text">鍒犻櫎</el-button>
+                      <el-button type="text" @click="previewClick" style="margin-left: 10px">棰勮</el-button>
+                      <el-button type="text" @click="downloadClick">涓嬭浇</el-button>
+                      <el-button type="text" @click="delContractClick">鍒犻櫎</el-button>
                     </div>
+                    <div ref="file"></div>
                   </div>
                 </el-form-item>
               </el-col>
@@ -170,8 +206,20 @@
 </template>
 
 <script>
-import { getAddContact, getUpdateContact } from "@/api/client/contacts"
+import {
+  createSupplier,
+  createContract,
+  updateSupplier,
+  getIndustryList,
+  getSupplierTypeList,
+  // downloadContract
+  // previewContract
+} from "@/api/supplierManage/supplier"
 import EditDropdownDialog from "@/views/other/commonDialog/EditDropdownDialog"
+import { getMemberListFromGrpc } from "@/api/common/other"
+import download from "downloadjs"
+// import { renderAsync } from "docx-preview"
+import axios from "axios"
 export default {
   name: "AddSupplierDialog",
   props: {
@@ -187,14 +235,19 @@
     }
   },
   components: { EditDropdownDialog },
-  computed: {},
+  computed: {
+    headers() {
+      const authorization = "Bearer "+document.cookie.replace(/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, "$1")|| ''
+      return { authorization }
+    }
+  },
   data() {
     return {
-      dialogWidth: "80%",
+      dialogWidth: "50%",
       editConfig: this.addCommonConfig,
       rules: {
-        supplier_name: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
-        member_id: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
+        name: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
+        responsiblePersonName: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
         phone: [
           { required: false, message: "", trigger: "blur" },
           { len: 11, message: "闀垮害鍦�11涓瓧绗�", trigger: "blur" },
@@ -213,22 +266,58 @@
           }
         ]
       },
-      supplierTypeOptions: [], // 渚涘簲鍟嗙被鍨�
-      industryOptions: [], // 鎵�灞炶涓�
-      memberOptions: [],
+      supplierTypeOptions: [{ id: 1, name: "渚涘簲鍟嗙被鍨�1" }], // 渚涘簲鍟嗙被鍨�
+      industryOptions: [{ id: 1, name: "鎵�灞炶涓�1" }], // 鎵�灞炶涓�
+      memberOptions: [{ id: 1, username: "admin" }],
       editDropdownConfig: {
         editVisible: false,
         title: "",
         infomation: {}
-      }
+      },
+      fileList: [],
+      file_name: this.addCommonConfig.infomation.file_name,
+      file_id: this.addCommonConfig.infomation.fileId,
+      previewUrl: "",
+      loading: false
     }
   },
   created() {
-    if (this.editConfig.title !== "鏂板缓" && this.editConfig.infomation.province_id !== 0) {
-      this.getCityList(this.editConfig.infomation.province_id, "edit")
+    this.getSupplierTypeList()
+    this.getIndustryList()
+    this.getMemberList()
+    if (this.editConfig.title === "淇敼") {
+      // this.previewContract()
     }
   },
   methods: {
+    // 閿�鍞礋璐d汉
+    async getMemberList() {
+      await getMemberListFromGrpc({
+        page: 1,
+        pageSize: 100
+      }).then((res) => {
+        console.log(res)
+        this.memberOptions = res.data.list
+      })
+    },
+    // 渚涘簲鍟嗙被鍨�
+    async getSupplierTypeList() {
+      await getSupplierTypeList({
+        page: 1,
+        pageSize: 100
+      }).then((res) => {
+        this.supplierTypeOptions = res.data.list
+      })
+    },
+    // 鎵�灞炶涓�
+    async getIndustryList() {
+      await getIndustryList({
+        page: 1,
+        pageSize: 100
+      }).then((res) => {
+        this.industryOptions = res.data.list
+      })
+    },
     handleClose() {
       this.editConfig.visible = false
     },
@@ -238,17 +327,13 @@
         if (valid) {
           console.log(this.editConfig.infomation)
           const params = this.saveParams()
-          console.log(params)
           if (this.editConfig.title === "鏂板缓") {
-            getAddContact(params)
+            createSupplier(params)
               .then((res) => {
                 console.log(res)
                 this.editConfig.visible = false
                 if (res.code === 200) {
-                  this.$message({
-                    message: "娣诲姞鎴愬姛",
-                    type: "success"
-                  })
+                  this.$message.success("娣诲姞鎴愬姛")
                   this.$parent.getData()
                 }
               })
@@ -256,21 +341,13 @@
                 console.log(err)
               })
           } else {
-            getUpdateContact(params)
-              .then((res) => {
-                console.log(res)
-                this.editConfig.visible = false
-                if (res.code === 200) {
-                  this.$message({
-                    message: "缂栬緫鎴愬姛",
-                    type: "success"
-                  })
-                  this.$parent.getData()
-                }
-              })
-              .catch((err) => {
-                console.log(err)
-              })
+            updateSupplier(params).then((res) => {
+              this.editConfig.visible = false
+              if (res.code === 200) {
+                this.$message.success("缂栬緫鎴愬姛")
+                this.$parent.getData()
+              }
+            })
           }
         } else {
           console.log("error submit")
@@ -281,22 +358,22 @@
     saveParams() {
       let data = this.editConfig.infomation
       let params = {
-        id: this.editConfig.title === "鏂板缓" ? 0 : data.id,
-        birthday: data.birthday || "",
-        city_id: data.city_id || 0,
-        client_id: this.clientId || 0,
-        country_id: data.country_id || 0,
-        desc: data.desc || "",
+        account: data.account || "",
+        accountName: data.accountName || "",
+        bank: data.bank || "",
+        contact: data.contact || "",
+        detailAddress: data.detailAddress || "",
         email: data.email || "",
-        is_first: data.is_first || false,
-        member_id: data.member_id || 0,
+        fileId: this.file_id || 0,
+        id: data.ID || 0,
+        industry: data.industry || "",
         name: data.name || "",
         number: data.number || "",
         phone: data.phone || "",
-        position: data.position || "",
-        province_id: data.province_id || 0,
-        region_id: data.region_id || 0,
-        wechat: data.wechat || ""
+        responsiblePersonName: data.responsiblePersonName || document.cookie.replace(/(?:(?:^|.*;\s*)username\s*=\s*([^;]*).*$)|^.*$/, "$1"),
+        status: data.status || 0,
+        supplierType: data.supplierType || "",
+        url: data.url || ""
       }
       return params
     },
@@ -311,6 +388,94 @@
     setIndustry() {
       this.editDropdownConfig.editVisible = true
       this.editDropdownConfig.title = "鎵�灞炶涓�"
+    },
+    //  鏂囦欢涓婁紶--start
+    beforeAvatarUpload(file) {
+      // 鏂囦欢绫诲瀷鍒ゆ柇
+      var testmsg = file.name.substring(file.name.lastIndexOf(".") + 1)
+      const extension = testmsg === "doc"
+      const extension2 = testmsg === "pdf"
+      const extension3 = testmsg === "docx"
+      if (!extension && !extension2 && !extension3) {
+        this.$message({
+          message: "涓婁紶鏂囦欢鍙兘鏄� word銆乸df鏍煎紡!",
+          type: "warning"
+        })
+        this.fileList = []
+      } else {
+        // 鍙傛暟鎷兼帴
+        console.log(file)
+        let fd = new FormData()
+        fd.append("file", file)
+        fd.append("name", file.name)
+        // 璋冪敤鎺ュ彛
+        createContract(fd).then((res) => {
+          if (res.code == 200) {
+            this.file_name = file.name
+            this.file_id = res.data.id
+          }
+        })
+      }
+    },
+    // 鏂囦欢瓒呭嚭涓暟闄愬埗鏃剁殑閽╁瓙
+    handleExceed(files, fileList) {
+      console.log(fileList)
+      this.$message.warning(`褰撳墠闄愬埗閫夋嫨 1 涓枃浠讹紝鏈閫夋嫨浜� ${files.length} 涓枃浠禶)
+    },
+    // 涓嬭浇鍚堝悓
+    downloadClick() {
+      let url = "/api/downloadContract?id=" + this.file_id
+      download(url, "", "")
+    },
+    // 鍒犻櫎鍚堝悓
+    delContractClick() {
+      // deleteContract({
+      //   id: this.file_id
+      // }).then((res) => {
+      //   console.log(res)
+      //   this.$message.success(res.msg)
+      this.file_id = 0
+      // })
+    },
+    // 棰勮鍚堝悓
+    // async previewClick() {
+    //   this.previewUrl = "/api/con/previewContract?id=" + this.file_id
+    //   if (this.file_name.includes("pdf")) {
+    //     window.open(this.previewUrl, "_blank")
+    //   } else {
+    //     let routeUrl = this.$router.resolve({
+    //       path: "/PreviewFile",
+    //       query: {
+    //         //瑕佷紶鐨勫弬鏁�
+    //         previewUrl: this.previewUrl
+    //       }
+    //     })
+    //     window.open(routeUrl.href, "_blank")
+    //   }
+    // }
+    async previewClick() {  
+      this.previewUrl = "/api/previewContract?id=" + this.file_id  
+      if (this.file_name.includes("pdf")) {  
+        console.log("鏄痯df鏂囦欢")
+        await axios.get(this.previewUrl, { headers: { "Authorization":"Bearer "+ document.cookie.replace(/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, "$1")} })  
+          .then(response => {  
+            window.open(this.previewUrl, "_blank") 
+            console.log("response",response,this.previewUrl)
+          })  
+          .catch(error => {  
+            console.error(error);  
+          });  
+      } else {  
+        console.log(this.previewUrl,"鐪嬬湅鏄暐瀛�")
+        let routeUrl = this.$router.resolve({  
+          path: "/PreviewFile",  
+          query: {  
+            //瑕佷紶鐨勫弬鏁�  
+            previewUrl: this.previewUrl  
+          }  
+        })  
+        window.open(routeUrl.href, "_blank")  
+      }  
     }
   }
 }
@@ -358,11 +523,6 @@
       .file-content {
         display: flex;
       }
-    }
-    .dialog-footer {
-      background-color: #f5f5f5;
-      height: 55px;
-      line-height: 55px;
     }
   }
 }

--
Gitblit v1.8.0