Parcourir la source

增加删除、按钮锁、导入限制、日期处理等、

lucky il y a 2 ans
Parent
commit
266ca4916e
1 fichiers modifiés avec 97 ajouts et 29 suppressions
  1. 97 29
      src/views/orderEntry/orderImport/index.vue

+ 97 - 29
src/views/orderEntry/orderImport/index.vue

@@ -6,7 +6,22 @@
         <h1></h1>
           <upload-excel :on-success="handleSuccess" :before-upload="beforeUpload" />
       <h1 style="color: #0099ff"></h1>
-        <ex-table :columns="columns" :table="table" :data="tableData"> </ex-table>
+        <ex-table :columns="columns" :table="table" :data="tableData"> 
+          <el-table-column width="50" type="index" />
+          <template #operation={scope}>
+            <el-tooltip
+            
+            effect="dark"
+            content="删除"
+            placement="top"
+          >
+            <i
+              class="el-icon-delete tb-icon"
+              @click="del(scope)"
+            ></i>
+          </el-tooltip>
+          </template>
+        </ex-table>
         <div class="btn">
       <el-button type="primary" @click="submit">提交</el-button>
       <el-button @click="cancel">取消</el-button>
@@ -47,7 +62,13 @@ export default {
       },
       // 表格 - 列参数
       columns: columns,
+
+      //按钮锁
+      btnFlag:false,
     };
+  },
+  mounted(){
+   
   },
   methods: {
     beforeUpload(file) {
@@ -67,6 +88,7 @@ export default {
         this.$message.error("表格无有效数据!");
         return;
       }
+
       let head = [
         "平台订单号",
         "其他单号(不必填)",
@@ -108,16 +130,40 @@ export default {
       this.tableHeader = header;
       this.tableData = [];
       let list = results;
+      // let r = /^\+?[1-9][0-9]*$/;
       // let tableOk = true;
       this.ruleForm.order_addr = [];
-      list.forEach((v1) => {
+      list.forEach((v1,index) => {
         let b = Object.values(v1);
+        let numFlag = false;
+        
+        try{
+          if(
+            !isNaN(b[5]) && !isNaN(b[6]) && !isNaN(b[7])
+          ){
+
+          }else{
+            this.$message.warning(`excel表格第${index+1}行,单价,数量,总金额必须是数字`);
+            numFlag = true;
+            throw Error();
+            
+          }
+
+
+          if(!Number.isInteger(Number(b[6]))){
+            this.$message.warning(`excel表格第${index+1}行,数量必须是整数`);
+            numFlag = true;
+            throw Error();
+          }
+        }catch(e){
 
+        }
+        if(numFlag){return;}
         // let item = this.get_code(b[3], b[4], b[5]);
         let model = {
           platform_code: b[0] + "",
           po_code: b[1] + "",
-          platform_time: this.formatDate(b[2], "/") + "",
+          platform_time: this.formatDate(b[2]) + "",
           sale_source: b[3] + "",
           plat_code: b[4] + "",
           price: b[5] + "",
@@ -142,28 +188,52 @@ export default {
     cancel() {
       this.tableData = [];
     },
+    //删除
+    del(scope){
+      console.log(scope.$index)
+      this.$confirm('是否删除本条导入数据?', '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }).then(() => {
+          this.tableData.splice(scope.$index,1)
+          this.$message({    
+            type: 'success',
+            message: '删除成功!'
+          });
+        }).catch(() => {
+          this.$message({
+            type: 'info',
+            message: '已取消删除'
+          });          
+        });
+      
+    },
     //日期转换
-    formatDate(numb, format) {
-      const time = new Date((numb - 1) * 24 * 3600000 + 1);
-      time.setYear(time.getFullYear() - 70);
-      const year = time.getFullYear() + "";
-      const month = time.getMonth() + 1 + "";
-      const date = time.getDate() + "";
-      if (format && format.length === 1) {
-        return year + format + month + format + date;
-      }
-      return (
-        year +
-        (month < 10 ? "0" + month : month) +
-        (date < 10 ? "0" + date : date)
-      );
+    formatDate(numb) {
+      const date = new Date(numb);
+        var Y = date.getFullYear() + '-';
+        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
+        var D = date.getDate() + ' ';
+        // var h = date.getHours() + ':';
+        // var m = date.getMinutes() + ':';
+        // var s = date.getSeconds();
+        return Y+M+D;
     },
     //提交
     async submit() {
+      if(this.btnFlag){
+        console.log("拦截点击")
+        return;
+      }
+      
       const model = {
         list: this.tableData,
       };
-    
+       if(model.list.length<=0){
+        this.$message.warning("导入数据不能为空");
+        return;
+      }
       let obj = [
         { name: "平台订单号", str: "platform_code" },
         { name: "销售渠道", str: "sale_source" },
@@ -200,29 +270,27 @@ export default {
         return;
       }
       if(flag){
+        //按钮锁开启
+        this.btnFlag = true;
         this.submitHttp(model)
       }
     },
-    async submitHttp(model) {
-      
-      if(model.list.length<=0){
-        this.$message.warning("导入数据不能为空");
-        return;
-      }
-     
+    async submitHttp(model) {  
       const res = await asyncRequest.orderimport(model);
       if (res && res.code === 0) {
         this.$notify.success({
           title: "成功!",
           message: "",
         });
-
         this.tableData = [];
+        
       } else if (res && res.code >= 100 && res.code <= 104) {
         await this.logout();
       } else {
         this.$message.warning(res.message);
       }
+      //关闭按钮锁
+      this.btnFlag = false;
     },
   },
 };
@@ -235,13 +303,13 @@ export default {
   box-sizing: border-box;
   height: 100vh;
   // overflow: hidden;
-  background: #f7f7f7e1;
+  background: #fff;
 }
 .con {
-  width: 95%;
+  width: 100%;
   margin: 0px auto;
   background: #fff;
-  padding: 50px;
+  // padding: 50px;
   box-sizing: border-box;