立航 饭 1 week ago
parent
commit
bacf70a9e4
1 changed files with 78 additions and 76 deletions
  1. 78 76
      src/views/orders/batchImportWeightV2.vue

+ 78 - 76
src/views/orders/batchImportWeightV2.vue

@@ -5,7 +5,8 @@
         <el-divider content-position="left">批量导入实重</el-divider>
         <el-divider content-position="left">批量导入实重</el-divider>
         <el-alert
         <el-alert
           :closable="false"
           :closable="false"
-          type="info">
+          type="info"
+        >
           <div class="info-text">
           <div class="info-text">
             <span class="font-size">根据指定模板文件进行实重导入,点击此处</span><el-link type="primary" class="font-size">
             <span class="font-size">根据指定模板文件进行实重导入,点击此处</span><el-link type="primary" class="font-size">
               <a href="javascript:;" @click="downloadXlsx('weightsTemplate')">
               <a href="javascript:;" @click="downloadXlsx('weightsTemplate')">
@@ -33,7 +34,7 @@
             <el-button type="warning" size="small" :loading="confirmLoading" @click="hanleRefreshError">批量错误重试</el-button>
             <el-button type="warning" size="small" :loading="confirmLoading" @click="hanleRefreshError">批量错误重试</el-button>
           </el-form-item>
           </el-form-item>
         </el-form>
         </el-form>
-        <div class="count-warp" v-show="batchListSource.length > 0">
+        <div v-show="batchListSource.length > 0" class="count-warp">
           <div v-if="countingNum.totalNum > 0">
           <div v-if="countingNum.totalNum > 0">
             <div>
             <div>
               批量导入实重总数量:<span class="total">{{ countingNum.totalNum }}</span>
               批量导入实重总数量:<span class="total">{{ countingNum.totalNum }}</span>
@@ -70,8 +71,8 @@
                 {{ row.ResultMessage }}
                 {{ row.ResultMessage }}
               </div>
               </div>
               <el-button
               <el-button
-                type="text"
                 v-show="row.ResultMessage === '-'"
                 v-show="row.ResultMessage === '-'"
+                type="text"
                 :loading="row.ResultMessage === '-'"
                 :loading="row.ResultMessage === '-'"
               />
               />
             </template>
             </template>
@@ -100,14 +101,15 @@
     >
     >
       <el-form ref="costListFormRef">
       <el-form ref="costListFormRef">
         <vxe-table
         <vxe-table
+          ref="costListTableRef"
           border
           border
           show-overflow
           show-overflow
-          ref="costListTableRef"
           :data="pageWeightThrowingData"
           :data="pageWeightThrowingData"
           :edit-rules="editRules"
           :edit-rules="editRules"
           :edit-config="{ trigger: 'click', mode: 'row', autoClear: false }"
           :edit-config="{ trigger: 'click', mode: 'row', autoClear: false }"
           :scroll-y="{enabled: false}"
           :scroll-y="{enabled: false}"
-          :column-config="{ resizable: true }">
+          :column-config="{ resizable: true }"
+        >
           <vxe-column field="TransferNumber" :min-width="240" title="运单号" :edit-render="{ autofocus: '.el-input__inner' }">
           <vxe-column field="TransferNumber" :min-width="240" title="运单号" :edit-render="{ autofocus: '.el-input__inner' }">
             <template #edit="r">
             <template #edit="r">
               <el-input v-model="r.row.TransferNumber" />
               <el-input v-model="r.row.TransferNumber" />
@@ -115,14 +117,14 @@
           </vxe-column>
           </vxe-column>
           <vxe-column field="Weight" :width="220" title="实重(KG)" :edit-render="{ autofocus: '.el-input__inner' }">
           <vxe-column field="Weight" :width="220" title="实重(KG)" :edit-render="{ autofocus: '.el-input__inner' }">
             <template #edit="r">
             <template #edit="r">
-              <el-input-number v-model="r.row.Weight" :controls="false"></el-input-number>
+              <el-input-number v-model="r.row.Weight" :controls="false" />
             </template>
             </template>
           </vxe-column>
           </vxe-column>
           <vxe-column field="ReceiverTime" :width="220" title="收货时间" :edit-render="{ autofocus: '.el-input__inner' }">
           <vxe-column field="ReceiverTime" :width="220" title="收货时间" :edit-render="{ autofocus: '.el-input__inner' }">
             <template #edit="r">
             <template #edit="r">
               <el-date-picker
               <el-date-picker
-                style="width: 100%;"
                 v-model="r.row.ReceiverTime"
                 v-model="r.row.ReceiverTime"
+                style="width: 100%;"
                 type="date"
                 type="date"
                 placeholder="收货时间"
                 placeholder="收货时间"
                 value-format="yyyy-MM-dd"
                 value-format="yyyy-MM-dd"
@@ -151,9 +153,9 @@
 
 
 <script>
 <script>
 import { getToken } from '@/utils/auth'
 import { getToken } from '@/utils/auth'
-import { deepClone, defineThrottle, getCurrentDateTime } from '@/utils';
-import XLSX from 'xlsx';
-import axios from 'axios';
+import { deepClone, defineThrottle, getCurrentDateTime } from '@/utils'
+import XLSX from 'xlsx'
+import axios from 'axios'
 
 
 export default {
 export default {
   name: 'BatchImportWeight',
   name: 'BatchImportWeight',
@@ -162,7 +164,7 @@ export default {
       if (!Number.isInteger(cellValue) || cellValue <= 0) {
       if (!Number.isInteger(cellValue) || cellValue <= 0) {
         return new Error('实重(KG)必须是正整数');
         return new Error('实重(KG)必须是正整数');
       }
       }
-      return true;
+      return true
     }
     }
     return {
     return {
       header: { Authorization: 'token ' + getToken() },
       header: { Authorization: 'token ' + getToken() },
@@ -175,8 +177,8 @@ export default {
             required: true,
             required: true,
             message: '运单号不能为空',
             message: '运单号不能为空',
             trigger: 'blur'
             trigger: 'blur'
-          },
-        ],
+          }
+        ]
         // Weight: [
         // Weight: [
         //   {
         //   {
         //     required: true,
         //     required: true,
@@ -199,37 +201,37 @@ export default {
       dialogWeight: false,
       dialogWeight: false,
       batchListSource: [],
       batchListSource: [],
       confirmLoading: false,
       confirmLoading: false,
-      countingNum: {//汇总数量
+      countingNum: { // 汇总数量
         totalNum: 0,
         totalNum: 0,
         errorNum: 0,
         errorNum: 0,
         successNum: 0
         successNum: 0
       },
       },
       tableHeight: 480,
       tableHeight: 480,
       throttledResize: null,
       throttledResize: null,
-      saveServiceWeightUrl: "https://wms.xingyunyi.cn/api/Order/SaveOpWeight",
+      saveServiceWeightUrl: 'https://wms.xingyunyi.cn/api/Order/SaveOpWeight',
       weightThrowingDataPage: 1,
       weightThrowingDataPage: 1,
       weightThrowingDataSize: 20,
       weightThrowingDataSize: 20,
       listSourcePage: 1,
       listSourcePage: 1,
-      listSourceSize: 20,
+      listSourceSize: 20
     }
     }
   },
   },
   computed: {
   computed: {
     totalWeightThrowing() {
     totalWeightThrowing() {
-      return this.weightThrowingData.length;
+      return this.weightThrowingData.length
     },
     },
     pageWeightThrowingData() {
     pageWeightThrowingData() {
-      const start = (this.weightThrowingDataPage - 1) * this.weightThrowingDataSize;
-      const end = start + this.weightThrowingDataSize;
-      return this.weightThrowingData.slice(start, end);
+      const start = (this.weightThrowingDataPage - 1) * this.weightThrowingDataSize
+      const end = start + this.weightThrowingDataSize
+      return this.weightThrowingData.slice(start, end)
     },
     },
     totalListSource() {
     totalListSource() {
-      return this.batchListSource.length;
+      return this.batchListSource.length
     },
     },
     pageListSourceData() {
     pageListSourceData() {
-      const start = (this.listSourcePage - 1) * this.listSourceSize;
-      const end = start + this.listSourceSize;
-      return this.batchListSource.slice(start, end);
-    },
+      const start = (this.listSourcePage - 1) * this.listSourceSize
+      const end = start + this.listSourceSize
+      return this.batchListSource.slice(start, end)
+    }
   },
   },
   mounted() {
   mounted() {
     this.createThrottledResize()
     this.createThrottledResize()
@@ -249,7 +251,7 @@ export default {
     },
     },
     createThrottledResize() {
     createThrottledResize() {
       this.getTableHeight()
       this.getTableHeight()
-      this.throttledResize = defineThrottle(this.getTableHeight, 1000); // 使用lodash的throttle方法,设置节流的时间间隔为500ms
+      this.throttledResize = defineThrottle(this.getTableHeight, 1000) // 使用lodash的throttle方法,设置节流的时间间隔为500ms
     },
     },
     downloadXlsx(name) {
     downloadXlsx(name) {
       const fileUrl = `/xlsx/${name}.xlsx`
       const fileUrl = `/xlsx/${name}.xlsx`
@@ -264,8 +266,8 @@ export default {
     uploadSuccess(file) {
     uploadSuccess(file) {
       const _this = this
       const _this = this
       // 处理文件选择的逻辑
       // 处理文件选择的逻辑
-      const excelFile = file.raw;
-      const isXlsx = excelFile.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
+      const excelFile = file.raw
+      const isXlsx = excelFile.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
       if (!isXlsx) {
       if (!isXlsx) {
         this.$message({ message: '只能上传 xlsx 文件!', type: 'error' })
         this.$message({ message: '只能上传 xlsx 文件!', type: 'error' })
         return
         return
@@ -275,13 +277,13 @@ export default {
       // 构建fileReader对象
       // 构建fileReader对象
       const fileReader = new FileReader()
       const fileReader = new FileReader()
       // 该事件为读取完成时触发
       // 该事件为读取完成时触发
-      fileReader.onload = function (ev) {
+      fileReader.onload = function(ev) {
         try {
         try {
-          const data = new Uint8Array(ev.target.result);
-          const workbook = XLSX.read(data, { type: 'array' });
-          const sheetName = workbook.SheetNames[0];
-          const worksheet = workbook.Sheets[sheetName];
-          const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1, defval: '' });
+          const data = new Uint8Array(ev.target.result)
+          const workbook = XLSX.read(data, { type: 'array' })
+          const sheetName = workbook.SheetNames[0]
+          const worksheet = workbook.Sheets[sheetName]
+          const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1, defval: '' })
           // 规定这个表头
           // 规定这个表头
           const headers = jsonData[0]
           const headers = jsonData[0]
           const isHead = _this.checkArrayHead(headers)
           const isHead = _this.checkArrayHead(headers)
@@ -289,24 +291,24 @@ export default {
             _this.$message({ message: 'Excel表头顺序必须是(运单号、实重(克)、收货时间)!', type: 'error' })
             _this.$message({ message: 'Excel表头顺序必须是(运单号、实重(克)、收货时间)!', type: 'error' })
             return false
             return false
           }
           }
-          const merges = worksheet['!merges'];
+          const merges = worksheet['!merges']
           if (merges) {
           if (merges) {
             merges.forEach((mergeCell) => {
             merges.forEach((mergeCell) => {
-              const { s, e } = mergeCell;
-              const mergedCellValue = jsonData[s.r][s.c]; // 获取合并单元格的值
+              const { s, e } = mergeCell
+              const mergedCellValue = jsonData[s.r][s.c] // 获取合并单元格的值
               // 将合并单元格的值应用到所有合并的单元格中
               // 将合并单元格的值应用到所有合并的单元格中
               for (let row = s.r; row <= e.r; row++) {
               for (let row = s.r; row <= e.r; row++) {
                 for (let col = s.c; col <= e.c; col++) {
                 for (let col = s.c; col <= e.c; col++) {
-                  jsonData[row][col] = mergedCellValue;
+                  jsonData[row][col] = mergedCellValue
                 }
                 }
               }
               }
-            });
+            })
           }
           }
           _this.countingThrowingList = jsonData
           _this.countingThrowingList = jsonData
           const paramsCountingThrowings = deepClone(jsonData)
           const paramsCountingThrowings = deepClone(jsonData)
           paramsCountingThrowings.shift()
           paramsCountingThrowings.shift()
           if (paramsCountingThrowings.length > 1000) {
           if (paramsCountingThrowings.length > 1000) {
-            _this.$message.error('最多上传1000条数据!');
+            _this.$message.error('最多上传1000条数据!')
             return
             return
           }
           }
           _this.weightThrowingData = _this.dealCountingThrowing(paramsCountingThrowings)
           _this.weightThrowingData = _this.dealCountingThrowing(paramsCountingThrowings)
@@ -325,19 +327,19 @@ export default {
       const xlsxHead = ["运单号", "实重(KG)", "收货时间"]
       const xlsxHead = ["运单号", "实重(KG)", "收货时间"]
       if (arr && arr.length !== xlsxHead.length) return false
       if (arr && arr.length !== xlsxHead.length) return false
       if (arr.every((item, index) => item === xlsxHead[index])) {
       if (arr.every((item, index) => item === xlsxHead[index])) {
-        return true;
+        return true
       } else {
       } else {
-        return false;
+        return false
       }
       }
     },
     },
     dealCountingThrowing(array) {
     dealCountingThrowing(array) {
       if (!Array.isArray(array) && array.length === 0) return []
       if (!Array.isArray(array) && array.length === 0) return []
-      const result = [];
+      const result = []
       // 遍历原始数组
       // 遍历原始数组
       array.forEach(arrItem => {
       array.forEach(arrItem => {
-        const TransferNumber = arrItem[0];
-        const Weight = arrItem[1];
-        const ReceiverTime = arrItem[2];
+        const TransferNumber = arrItem[0]
+        const Weight = arrItem[1]
+        const ReceiverTime = arrItem[2]
         if (TransferNumber) {
         if (TransferNumber) {
           result.push({
           result.push({
             TransferNumber,
             TransferNumber,
@@ -345,26 +347,26 @@ export default {
             ReceiverTime
             ReceiverTime
           })
           })
         }
         }
-      });
+      })
       return result
       return result
     },
     },
     // 表格错误样式
     // 表格错误样式
     rowClassName({ row }) {
     rowClassName({ row }) {
-      if(row.ResultState === 500) return 'error-bg'
+      if (row.ResultState === 500) return 'error-bg'
     },
     },
     // 错误排序
     // 错误排序
     countingOrderSortList() {
     countingOrderSortList() {
       this.batchListSource = this.batchListSource.sort((a, b) => {
       this.batchListSource = this.batchListSource.sort((a, b) => {
         // 根据错误排序
         // 根据错误排序
         if (a.ResultState === 500 && b.ResultState === 200) {
         if (a.ResultState === 500 && b.ResultState === 200) {
-          return -1;
+          return -1
         } else if (a.ResultState === 200 && b.ResultState === 500) {
         } else if (a.ResultState === 200 && b.ResultState === 500) {
-          return 1;
+          return 1
         } else {
         } else {
           // 根据时间排序
           // 根据时间排序
-          return new Date(b.CreateTime) - new Date(a.CreateTime);
+          return new Date(b.CreateTime) - new Date(a.CreateTime)
         }
         }
-      });
+      })
       const errorList = this.batchListSource.filter(item => item.ResultState === 500)
       const errorList = this.batchListSource.filter(item => item.ResultState === 500)
       this.countingNum.errorNum = errorList.length
       this.countingNum.errorNum = errorList.length
       const successList = this.batchListSource.filter(item => item.ResultState === 200)
       const successList = this.batchListSource.filter(item => item.ResultState === 200)
@@ -373,41 +375,41 @@ export default {
     // 请求
     // 请求
     getCancelOrder(rowData, rowIndex) {
     getCancelOrder(rowData, rowIndex) {
       return new Promise((resolve) => {
       return new Promise((resolve) => {
-        if(rowData.TransferNumber) {
+        if (rowData.TransferNumber) {
           // 初始化时间
           // 初始化时间
           const createTime = getCurrentDateTime()
           const createTime = getCurrentDateTime()
-          this.$set(this.batchListSource[rowIndex], 'CreateTime', createTime);
+          this.$set(this.batchListSource[rowIndex], 'CreateTime', createTime)
           const currentIndex = this.batchListSource.findIndex((i) => i.id === rowData.id)
           const currentIndex = this.batchListSource.findIndex((i) => i.id === rowData.id)
           const data = {
           const data = {
             TrackingNumber: rowData.TransferNumber,
             TrackingNumber: rowData.TransferNumber,
             ActiveWeight: rowData.Weight,
             ActiveWeight: rowData.Weight,
-            ReceiverTime: rowData.ReceiverTime,
+            ReceiverTime: rowData.ReceiverTime
           }
           }
           axios({
           axios({
             method: 'post',
             method: 'post',
             url: this.saveServiceWeightUrl,
             url: this.saveServiceWeightUrl,
             data: JSON.stringify(data),
             data: JSON.stringify(data),
-            headers: { 'token': getToken(), 'Content-Type': 'application/json' },
+            headers: { 'token': getToken(), 'Content-Type': 'application/json' }
           }).then(result => {
           }).then(result => {
             const res = result.data
             const res = result.data
-            if(res.success && currentIndex >= 0) {
-              this.$set(this.batchListSource[currentIndex], 'ResultState', 200);
-              this.$set(this.batchListSource[currentIndex], 'ResultMessage', '导入成功');
+            if (res.success && currentIndex >= 0) {
+              this.$set(this.batchListSource[currentIndex], 'ResultState', 200)
+              this.$set(this.batchListSource[currentIndex], 'ResultMessage', '导入成功')
             } else {
             } else {
-              this.$set(this.batchListSource[currentIndex], 'ResultMessage', res.message);
-              this.$set(this.batchListSource[currentIndex], 'ResultState', 500);
+              this.$set(this.batchListSource[currentIndex], 'ResultMessage', res.message)
+              this.$set(this.batchListSource[currentIndex], 'ResultState', 500)
             }
             }
           }).catch(error => {
           }).catch(error => {
             const msg = error.response ? (error.response.data.message || error.response.data.errors || error.response.data) : error
             const msg = error.response ? (error.response.data.message || error.response.data.errors || error.response.data) : error
-            if(currentIndex >= 0) {
-              this.$set(this.batchListSource[currentIndex], 'ResultMessage', msg);
-              this.$set(this.batchListSource[currentIndex], 'ResultState', 500);
+            if (currentIndex >= 0) {
+              this.$set(this.batchListSource[currentIndex], 'ResultMessage', msg)
+              this.$set(this.batchListSource[currentIndex], 'ResultState', 500)
             }
             }
           }).finally(() => {
           }).finally(() => {
-            if(currentIndex >= 0) {
+            if (currentIndex >= 0) {
               // 更新时间
               // 更新时间
               const createTime = getCurrentDateTime()
               const createTime = getCurrentDateTime()
-              this.$set(this.batchListSource[currentIndex], 'CreateTime', createTime);
+              this.$set(this.batchListSource[currentIndex], 'CreateTime', createTime)
               this.countingOrderSortList()
               this.countingOrderSortList()
               resolve(true)
               resolve(true)
             }
             }
@@ -418,7 +420,7 @@ export default {
     // 错误重试
     // 错误重试
     async hanleRefreshError() {
     async hanleRefreshError() {
       const isEvery = this.batchListSource.every(item => item.ResultState === 200)
       const isEvery = this.batchListSource.every(item => item.ResultState === 200)
-      if(isEvery) {
+      if (isEvery) {
         this.$message({
         this.$message({
           type: 'warning',
           type: 'warning',
           message: '暂无运单号重试'
           message: '暂无运单号重试'
@@ -429,19 +431,19 @@ export default {
         this.confirmLoading = true
         this.confirmLoading = true
         // 同步
         // 同步
         for await (const [rowIndex, rowData] of this.batchListSource.entries()) {
         for await (const [rowIndex, rowData] of this.batchListSource.entries()) {
-          if(rowData.ResultState === 500) {
+          if (rowData.ResultState === 500) {
             await this.getCancelOrder(rowData, rowIndex)
             await this.getCancelOrder(rowData, rowIndex)
           }
           }
         }
         }
       } catch (error) {
       } catch (error) {
-        console.error(error);
+        console.error(error)
       } finally {
       } finally {
         this.confirmLoading = false
         this.confirmLoading = false
       }
       }
     },
     },
     // 批量导入实重
     // 批量导入实重
     async updateBatchCountingOrder() {
     async updateBatchCountingOrder() {
-      if(this.batchListSource.length === 0) {
+      if (this.batchListSource.length === 0) {
         this.$message({
         this.$message({
           type: 'warning',
           type: 'warning',
           message: '暂无运单号导入'
           message: '暂无运单号导入'
@@ -451,7 +453,7 @@ export default {
       try {
       try {
         this.confirmLoading = true
         this.confirmLoading = true
         const list = this.batchListSource.map((item, index) => {
         const list = this.batchListSource.map((item, index) => {
-          if(item.TransferNumber) {
+          if (item.TransferNumber) {
             item.id = `${index}_transferNumber`
             item.id = `${index}_transferNumber`
             item.CreateTime = '-'
             item.CreateTime = '-'
             item.ResultMessage = '-'
             item.ResultMessage = '-'
@@ -466,7 +468,7 @@ export default {
           }
           }
         }
         }
       } catch (error) {
       } catch (error) {
-        console.error(error);
+        console.error(error)
       } finally {
       } finally {
         this.confirmLoading = false
         this.confirmLoading = false
       }
       }
@@ -491,17 +493,17 @@ export default {
     },
     },
     // 可编辑表格
     // 可编辑表格
     pageThrowingChange(page) {
     pageThrowingChange(page) {
-      this.weightThrowingDataPage = page;
+      this.weightThrowingDataPage = page
     },
     },
     sizeThrowingChange(size) {
     sizeThrowingChange(size) {
-      this.weightThrowingDataSize = size;
+      this.weightThrowingDataSize = size
     },
     },
     // 不可编辑表格
     // 不可编辑表格
     pageListSourceChange(page) {
     pageListSourceChange(page) {
-      this.listSourcePage = page;
+      this.listSourcePage = page
     },
     },
     sizeListSourceChange(size) {
     sizeListSourceChange(size) {
-      this.listSourceSize = size;
+      this.listSourceSize = size
     }
     }
   }
   }
 }
 }