002390 1 жил өмнө
parent
commit
481257f96a

+ 21 - 1
src/api/business/purchase/purchase-order.js

@@ -152,6 +152,8 @@ const toOA =(userName, fdId) => {
   })
   })
 }
 }
 
 
+
+
 // 采购订单修订导出
 // 采购订单修订导出
 const orderExport =(data) => {
 const orderExport =(data) => {
   return request({
   return request({
@@ -161,6 +163,23 @@ const orderExport =(data) => {
   })
   })
 }
 }
 
 
+// 行导入
+const orderImport = (data) =>{
+  return request({
+    url: "/pu/order/import",
+    method: "POST",
+    data: data,
+  });
+}
+// 模板下载
+const downloadFailData = (data) =>{
+  return request({
+    url: "/pu/order/downloadFailData",
+    method: "POST",
+    data: data,
+  });
+}
+
 export default {
 export default {
   list,
   list,
   details,
   details,
@@ -180,5 +199,6 @@ export default {
   returnedGoods,
   returnedGoods,
   toOA,
   toOA,
   orderExport,
   orderExport,
-
+  orderImport,
+  downloadFailData,
 }
 }

+ 61 - 13
src/components/BatchImport/index.vue

@@ -34,16 +34,13 @@ export default {
     },
     },
   },
   },
   computed:{
   computed:{
-    tips:{
-      get(){
-        // this.accept.
-      },
-      set(){},
-    },
      // 是否显示提示
      // 是否显示提示
      showTip() {
      showTip() {
       return this.isShowTip && (this.fileType || this.fileSize);
       return this.isShowTip && (this.fileType || this.fileSize);
     },
     },
+    accept(){
+      return this.fileType.map(item =>(`.${item}`)).join(',');
+    }
   },
   },
   data(){
   data(){
     return {
     return {
@@ -51,16 +48,27 @@ export default {
       visible:false,
       visible:false,
       loading:false,
       loading:false,
       fileList:[],
       fileList:[],
+      number: 0,
 
 
     }
     }
   },
   },
   methods:{
   methods:{
     // 确认上传
     // 确认上传
     async submitUpload(){
     async submitUpload(){
+      if(this.fileList.length){
+        this.$emit('import',this.fileList);
+      }else{
+      this.$notify.warning({
+        title:'警告',
+        message: '请上传文件之后在确认!',
+      });
 
 
+      }
+      
     },
     },
     // 模板下载
     // 模板下载
     async templateDownload(){
     async templateDownload(){
+      this.$emit('temDownload')
       // 放父组件
       // 放父组件
       // this.download('/system/material/download', {}, `物料基本信息模板.xlsx`);
       // this.download('/system/material/download', {}, `物料基本信息模板.xlsx`);
     },
     },
@@ -79,9 +87,41 @@ export default {
     onChange(file, fileList){
     onChange(file, fileList){
       this.fileList = fileList;
       this.fileList = fileList;
     },
     },
+    setVisible(prop){
+      this.visible = prop;
+    },
+    open(){
+      this.setVisible(true);
+    },
     // 取消
     // 取消
     cancal(){
     cancal(){
-      this.visible = false;
+      this.setVisible(false);
+    },
+     // 上传前校检格式和大小
+     handleBeforeUpload(file) {
+      // 校检文件类型
+      if (this.fileType) {
+        const fileName = file.name.split(".");
+        const fileExt = fileName[fileName.length - 1];
+        const isTypeOk = this.fileType.indexOf(fileExt) >= 0;
+        if (!isTypeOk) {
+          this.$modal.msgError(
+            `文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`
+          );
+          return false;
+        }
+      }
+      // 校检文件大小
+      if (this.fileSize) {
+        const isLt = file.size / 1024 / 1024 < this.fileSize;
+        if (!isLt) {
+          this.$modal.msgError(`上传文件大小不能超过 ${this.fileSize} MB!`);
+          return false;
+        }
+      }
+      this.$modal.loading("正在上传文件,请稍候...");
+      this.number++;
+      return true;
     },
     },
     
     
   },
   },
@@ -90,7 +130,12 @@ export default {
 </script>
 </script>
 
 
 <template>
 <template>
-  <el-button :disabled="disabled">
+  <el-button 
+    :disabled="disabled"
+    :size="size"
+    @click="open"
+    type="primary"
+  >
     {{ title }}
     {{ title }}
     <el-dialog 
     <el-dialog 
       :title="title" 
       :title="title" 
@@ -99,25 +144,28 @@ export default {
       width="35%" 
       width="35%" 
       center
       center
       :before-close="beforeClose"
       :before-close="beforeClose"
+      append-to-body
     >
     >
       <el-upload
       <el-upload
         ref="upload"
         ref="upload"
-        :accept="accept"
         action="#"
         action="#"
         :on-preview="handlePreview"
         :on-preview="handlePreview"
+        :accept="accept"
+        :before-upload="handleBeforeUpload"
         :on-remove="handleRemove"
         :on-remove="handleRemove"
         :file-list="fileList"
         :file-list="fileList"
         :auto-upload="false"
         :auto-upload="false"
         :on-change="onChange" 
         :on-change="onChange" 
         :limit="limit"
         :limit="limit"
-        append-to-body
+        :disabled="disabled"
+        style="text-align: center;"
       >
       >
         <el-button 
         <el-button 
           slot="trigger" 
           slot="trigger" 
           :size="size" 
           :size="size" 
           type="primary"
           type="primary"
         >选取文件</el-button>
         >选取文件</el-button>
-        <el-button 
+        <el-button
           v-if="isTemplate"
           v-if="isTemplate"
           style="margin-left: 10px;" 
           style="margin-left: 10px;" 
           :size="size" 
           :size="size" 
@@ -136,8 +184,8 @@ export default {
       </el-upload>
       </el-upload>
 
 
       <div slot="footer" class="dialog-footer">
       <div slot="footer" class="dialog-footer">
-        <el-button @click="cancal">取 消</el-button>
-        <el-button type="primary" @click="submitUpload">确 定</el-button>
+        <el-button type="primary" @click="submitUpload" :size="size">确 定</el-button>
+        <el-button @click="cancal" :size="size">取 消</el-button>
       </div>
       </div>
     </el-dialog>
     </el-dialog>
   </el-button>
   </el-button>

+ 46 - 0
src/views/purchase/purchase-order/add/index.vue

@@ -24,6 +24,7 @@ export default {
   components: {
   components: {
     FileUploadCenter: () => import("../components/FileUploadCenter/index.vue"),
     FileUploadCenter: () => import("../components/FileUploadCenter/index.vue"),
     popDialog: () => import("@/components/PopDialog/index.vue"),
     popDialog: () => import("@/components/PopDialog/index.vue"),
+    BatchImport: () => import("@/components/BatchImport/index.vue"),
   },
   },
 
 
   data() {
   data() {
@@ -499,6 +500,46 @@ export default {
     
     
     },
     },
 
 
+    async handelImport(fileList){
+
+      try {
+
+        let formData = new FormData();
+
+        formData.append('file',fileList[0].raw);
+
+        this.$modal.loading("正在上传文件,请稍候...");
+
+        let {code,data} = await orderApi.orderImport(formData);
+
+        if(code == 200) {
+          // puOrderExecuteList puOrderItemList
+
+          for (const key in data) {
+           this.params[key] = data[key];
+          }
+
+          let {setVisible} =  this.$refs.batchImport;
+
+          setVisible(false);
+
+          this.handleGetPrice();
+        }
+        
+      } catch (error) {
+        
+      }finally{
+        this.$modal.closeLoading();
+      }
+
+    },
+    
+    async handleTemDownload(){
+
+      this.download('/pu/order/downloadFailData',{}, `物料信息模板.xlsx`);
+    },
+
+
   },
   },
   created() {
   created() {
     console.log("ADD CREATED", this.params);
     console.log("ADD CREATED", this.params);
@@ -812,6 +853,11 @@ export default {
           <el-button size="mini" @click="addTableRow(params[tabName])"
           <el-button size="mini" @click="addTableRow(params[tabName])"
             >增行</el-button
             >增行</el-button
           >
           >
+          <BatchImport
+            ref="batchImport"
+            @import="handelImport"
+            @temDownload="handleTemDownload"
+          ></BatchImport>
         </el-row>
         </el-row>
       </el-card>
       </el-card>
     </el-form>
     </el-form>