Browse Source

fix: 修改整体批量导入实重功能

lyc 2 months ago
parent
commit
2ed1fb2a02
4 changed files with 376 additions and 81 deletions
  1. BIN
      public/xlsx/weightTemplate.xlsx
  2. 70 0
      src/api/order.js
  3. 36 0
      src/styles/index.scss
  4. 270 81
      src/views/orders/batchImportWeight.vue

BIN
public/xlsx/weightTemplate.xlsx


+ 70 - 0
src/api/order.js

@@ -143,6 +143,73 @@ export function _updateChange17TrackingInfo(data) {
   })
 }
 
+/**
+ *
+ * @param {*} data
+ * @returns
+ */
+export function _GetNewFee(data) {
+  return request({
+    url: '/order/GetNewFee',
+    method: 'post',
+    data
+  })
+}
+
+
+/**
+ * 保存列表结果
+ * @param {*} data
+ * @returns
+ */
+export function _SaveNewFee(data) {
+  return request({
+    url: '/order/SaveNewFee',
+    method: 'post',
+    data
+  })
+}
+
+/**
+ * 保存列表结果后显示的数据
+ * @param {*} data
+ * @returns
+ */
+export function _GetCustomerWeightSupplementary(data) {
+  return request({
+    url: '/order/GetCustomerWeightSupplementary',
+    method: 'post',
+    data
+  })
+}
+
+/**
+ * 查询明细分页数据
+ * @param {*} groupId
+ * @returns
+ */
+export function _GetDetail(groupId) {
+  return request({
+    url: '/order/GetDetail',
+    method: 'get',
+    params: { groupId }
+  })
+}
+
+/**
+ * 上传费用
+ * @param {*} data
+ * @returns
+ */
+export function _UpdateSupplementaryGroup(GroupId) {
+  return request({
+    url: '/order/UpdateSupplementaryGroup',
+    method: 'get',
+    params: { GroupId }
+  })
+}
+
+
 const requestWms = createService('https://wms.xingyunyi.cn/api', true)
 /**
  * 获取上门取件预报列表
@@ -184,3 +251,6 @@ export function AddScanform(data) {
     data
   })
 }
+
+
+

+ 36 - 0
src/styles/index.scss

@@ -242,3 +242,39 @@ aside {
     color: rgb(100, 59, 226);
   }
 }
+
+.batch-import-weight-form {
+  .el-dialog__footer {
+    position: sticky;
+    bottom: 0;
+    background-color: #fff;
+    z-index: 999;
+  }
+  .useSystem-warp {
+    text-align: right;
+    margin-bottom: 6px;
+    .el-checkbox__inner {
+      border: 2px solid #DCDFE6;
+    }
+    .el-checkbox__input.is-checked .el-checkbox__inner {
+      border-color: #1890ff;
+    }
+    .el-checkbox__label {
+      font-weight: bold;
+    }
+  }
+}
+.saveNewFee-form {
+  .el-dialog__body {
+    padding: 10px 20px;
+  }
+  .el-checkbox__inner {
+    border: 2px solid #DCDFE6;
+    &.is-checked .el-checkbox__inner {
+      border-color: #1890ff;
+    }
+  }
+  .el-checkbox__label {
+    font-weight: bold;
+  }
+}

+ 270 - 81
src/views/orders/batchImportWeight.vue

@@ -29,11 +29,11 @@
               <el-button type="primary" plain :loading="confirmLoading" size="small">选择文件</el-button>
             </el-upload>
           </el-form-item>
-          <el-form-item>
+          <!-- <el-form-item>
             <el-button type="warning" size="small" :loading="confirmLoading" @click="hanleRefreshError">批量错误重试</el-button>
-          </el-form-item>
+          </el-form-item> -->
         </el-form>
-        <div class="count-warp" v-show="batchListSource.length > 0">
+        <!-- <div class="count-warp" v-show="batchListSource.length > 0">
           <div v-if="countingNum.totalNum > 0">
             <div>
               批量导入实重总数量:<span class="total">{{ countingNum.totalNum }}</span>
@@ -46,10 +46,11 @@
               批量导入实重总数量:<span class="total">{{ countingNum.totalNum }}</span>
             </div>
           </div>
-        </div>
+        </div> -->
         <vxe-table
           border
-          :data="pageListSourceData"
+          :data="customerWeightSupplementaryData"
+          :loading="customerWeightLoading"
           :row-config="{isHover: true}"
           :row-class-name="rowClassName"
           :height="tableHeight"
@@ -60,39 +61,46 @@
           :scroll-y="{enabled: false}"
           :column-config="{ resizable: true }"
         >
-          <vxe-column title="提交时间" field="CreateTime" :min-width="150" />
-          <vxe-column title="运单号" field="TransferNumber" :min-width="260" />
-          <vxe-column title="实重(克)" field="Weight" :min-width="100" />
-          <vxe-column title="提示内容" field="ResultMessage" :min-width="280">
+          <vxe-column title="文件名" field="FileName" :min-width="130" />
+          <vxe-column title="补款条数" field="RowQty" :min-width="130" />
+          <vxe-column title="补款金额" field="SumSupplementary" :min-width="130" />
+          <vxe-column title="是否上传金额" field="ResultMessage" :min-width="130">
             <template #default="{ row }">
-              <div v-show="row.ResultMessage !== '-'">
-                {{ row.ResultMessage }}
-              </div>
-              <el-button
-                type="text"
-                v-show="row.ResultMessage === '-'"
-                :loading="row.ResultMessage === '-'"
-              />
+              <el-tag :type="row.IsPost ? 'success' : ''">
+                {{ row.IsPost ? '是' : '否' }}
+              </el-tag>
+            </template>
+          </vxe-column>
+          <vxe-column title="创建时间" field="CreateTime" :min-width="180">
+            <template #default="{ row }">
+              {{ row.CreateTime | getDealTimeStr }}
+            </template>
+          </vxe-column>
+          <vxe-column title="操作" :width="220">
+            <template #default="{ row }">
+              <el-button type="primary" size="mini" @click="onViewDetails(row)" :loading="row.detailLoading">查看明细</el-button>
+              <el-button type="success" size="mini" @click="onUploadFee(row)">上传费用</el-button>
             </template>
           </vxe-column>
         </vxe-table>
         <el-pagination
-          background
           :page-sizes="[20, 50, 100, 150, 200]"
-          :current-page="listSourcePage"
-          :page-size="listSourceSize"
-          layout="prev, pager, next ,total ,sizes"
-          :total="totalListSource"
-          @current-change="pageListSourceChange"
-          @size-change="sizeListSourceChange"
+          :current-page="pagerDto.PageIndex"
+          :page-size="pagerDto.PageSize"
+          background
+          layout="prev, pager, next ,total ,jumper,sizes,slot "
+          :total="pagerDto.total"
+          @current-change="pagerSerach"
+          @size-change="sizeChange"
         />
       </div>
     </el-card>
     <el-dialog
-      title="实重列表数据"
-      width="820px"
       top="6vh"
-      custom-class="counting-list-form"
+      :title="getEditWeightTitle"
+      width="1300px"
+      :fullscreen="true"
+      custom-class="batch-import-weight-form"
       :before-close="closeDialogWeight"
       :close-on-click-modal="false"
       :visible.sync="dialogWeight"
@@ -102,36 +110,65 @@
           border
           show-overflow
           ref="costListTableRef"
+          :loading="pageWeightThrowingLoading"
           :data="pageWeightThrowingData"
-          :edit-rules="editRules"
-          :edit-config="{ trigger: 'click', mode: 'row' }"
           :scroll-y="{enabled: false}"
           :column-config="{ resizable: true }">
-          <vxe-column field="TransferNumber" :min-width="240" title="运单号" :edit-render="{ autofocus: '.el-input__inner' }">
-            <template #edit="r">
-              <el-input v-model="r.row.TransferNumber" />
+          <vxe-column field="TrackingNumber" :min-width="280" title="跟踪号" />
+          <vxe-column field="ReceiverTime" :min-width="154" title="收件时间">
+            <template #default="{ row }">
+              {{ row.ReceiverTime | getDealTimeStr }}
             </template>
           </vxe-column>
-          <vxe-column field="Weight" :width="220" title="实重(克)" :edit-render="{ autofocus: '.el-input__inner' }">
-            <template #edit="r">
-              <el-input-number v-model="r.row.Weight" :controls="false"></el-input-number>
+          <vxe-column field="OldZone" :min-width="100" title="计费分区" />
+          <vxe-column field="OldWeight" :min-width="100" title="原单实重" />
+          <vxe-column field="OldFee" :min-width="100" title="原单派送费" />
+          <vxe-column field="InputFee" :min-width="100" title="导入派送费" />
+          <vxe-column field="InputFee_OldFee" :min-width="100" title="补收金额" />
+          <vxe-column field="SystemFee" :min-width="100" title="计算金额" />
+          <vxe-column field="SystemFee_InputFee" :min-width="100" title="计算减导入" />
+          <vxe-column field="IsSuccess" :min-width="100" title="是否异常">
+            <template #default="{ row }">
+              <el-tag :type="!row.IsSuccess ? 'danger' : ''">
+                {{ !row.IsSuccess ? '是' : '否' }}
+              </el-tag>
             </template>
           </vxe-column>
+          <vxe-column field="ErrorMessage" :min-width="240" title="异常信息" />
         </vxe-table>
-        <el-pagination
-          background
-          :page-sizes="[20, 50, 100, 150, 200]"
-          :current-page="weightThrowingDataPage"
-          :page-size="weightThrowingDataSize"
-          layout="prev, pager, next ,total ,sizes"
-          :total="totalWeightThrowing"
-          @current-change="pageThrowingChange"
-          @size-change="sizeThrowingChange"
-        />
+        <div style="text-align: right;">
+          <el-pagination
+            background
+            :page-sizes="[20, 50, 100, 150, 200]"
+            :current-page="weightThrowingDataPage"
+            :page-size="weightThrowingDataSize"
+            layout="prev, pager, next ,total ,sizes"
+            :total="totalWeightThrowing"
+            @current-change="pageThrowingChange"
+            @size-change="sizeThrowingChange"
+          />
+        </div>
       </el-form>
       <span slot="footer" class="dialog-footer">
-        <el-button @click="closeDialogWeight">取 消</el-button>
-        <el-button type="primary" :loading="confirmLoading" @click="hanleSubmitWeight">导入实重</el-button>
+        <el-button @click="closeDialogWeight">
+          {{ !getEditWeight ? '取 消' : '关 闭' }}
+        </el-button>
+        <el-button type="primary" :loading="confirmLoading" @click="hanleSubmitWeight" v-if="!getEditWeight">确定保存</el-button>
+      </span>
+    </el-dialog>
+    <el-dialog
+      title="提示"
+      top="30vh"
+      width="380px"
+      custom-class="saveNewFee-form"
+      :visible.sync="useSystemDialogVisible"
+      :before-close="closeSaveNewFee">
+      <div>
+        <el-checkbox v-model="saveNewFeeParams.useSystem" label="是否使用系统运费"></el-checkbox>
+      </div>
+      <span slot="footer" class="dialog-footer">
+        <el-button @click="closeSaveNewFee">取 消</el-button>
+        <el-button type="primary" @click="okSaveNewFee" :loading="saveNewFeeLoading">确 定</el-button>
       </span>
     </el-dialog>
   </div>
@@ -141,10 +178,17 @@
 import { getToken } from '@/utils/auth'
 import { deepClone, defineThrottle, getCurrentDateTime } from '@/utils';
 import XLSX from 'xlsx';
+import { _GetCustomerWeightSupplementary, _GetDetail, _GetNewFee, _SaveNewFee, _UpdateSupplementaryGroup } from '@/api/order'
 import axios from 'axios';
 
 export default {
   name: 'BatchImportWeight',
+  filters: {
+    getDealTimeStr(timerStr) {
+      if (!timerStr) return ''
+      return timerStr.replace('T', ' ')
+    }
+  },
   data() {
     const validatePositiveInteger = ({ cellValue }) => {
       if (!Number.isInteger(cellValue) || cellValue <= 0) {
@@ -158,14 +202,14 @@ export default {
       countingThrowingList: [],
       weightThrowingData: [],
       editRules: {
-        TransferNumber: [
+        TrackingNumber: [
           {
             required: true,
             message: '运单号不能为空',
             trigger: 'blur'
           },
         ],
-        Weight: [
+        ActiveWeight: [
           {
             required: true,
             message: '实重(克)不能为空',
@@ -178,6 +222,7 @@ export default {
         ]
       },
       dialogWeight: false,
+      editWeightId: undefined,
       batchListSource: [],
       confirmLoading: false,
       countingNum: {//汇总数量
@@ -192,6 +237,21 @@ export default {
       weightThrowingDataSize: 20,
       listSourcePage: 1,
       listSourceSize: 20,
+      pageWeightThrowingLoading: false,
+      saveNewFeeParams: {
+        fileName: '',
+        useSystem: false,
+        serviceWeightResult: []
+      },
+      useSystemDialogVisible: false,
+      saveNewFeeLoading: false,
+      customerWeightSupplementaryData: [],
+      customerWeightLoading: false,
+      pagerDto: {
+        PageIndex: 1,
+        PageSize: 20,
+        total: 0
+      },
     }
   },
   computed: {
@@ -211,8 +271,15 @@ export default {
       const end = start + this.listSourceSize;
       return this.batchListSource.slice(start, end);
     },
+    getEditWeight() {
+      return this.editWeightId >= 0 ? true : false
+    },
+    getEditWeightTitle() {
+      return this.getEditWeight ? '查看实重数据' : '上传实重数据'
+    }
   },
   mounted() {
+    this.initSaveNewFeeList();
     this.createThrottledResize()
     window.addEventListener('resize', this.throttledResize)
   },
@@ -244,6 +311,7 @@ export default {
     // 上传xlsx文件
     uploadSuccess(file) {
       const _this = this
+      this.saveNewFeeParams.fileName = file.name
       // 处理文件选择的逻辑
       const excelFile = file.raw;
       const isXlsx = excelFile.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
@@ -267,7 +335,7 @@ export default {
           const headers = jsonData[0]
           const isHead = _this.checkArrayHead(headers)
           if (!isHead) {
-            _this.$message({ message: 'Excel表头顺序必须是(运单号、实重(克))!', type: 'error' })
+            _this.$message({ message: 'Excel表头顺序必须是(运单号、实重(克)、运费)!', type: 'error' })
             return false
           }
           const merges = worksheet['!merges'];
@@ -290,8 +358,9 @@ export default {
             _this.$message.error('最多上传1000条数据!');
             return
           }
-          _this.weightThrowingData = _this.dealCountingThrowing(paramsCountingThrowings)
-          _this.hanleOpenEditCounting()
+          const weightThrowingData = _this.dealCountingThrowing(paramsCountingThrowings)
+          _this.getNewFeeList(weightThrowingData)
+          _this.hanleOpenEditWeight()
         } catch (e) {
           _this.$message({ message: e, type: 'warning' })
         } finally {
@@ -303,7 +372,7 @@ export default {
     },
     // 校验表头
     checkArrayHead(arr) {
-      const xlsxHead = ["运单号", "实重(克)"]
+      const xlsxHead = ["运单号", "实重(克)", "运费"]
       if (arr && arr.length !== xlsxHead.length) return false
       if (arr.every((item, index) => item === xlsxHead[index])) {
         return true;
@@ -316,15 +385,46 @@ export default {
       const result = [];
       // 遍历原始数组
       array.forEach(arrItem => {
-        const TransferNumber = arrItem[0] || '';
-        const Weight = arrItem[1] || '';
-        result.push({
-          TransferNumber,
-          Weight,
-        })
+        const TrackingNumber = arrItem[0];
+        const ActiveWeight = arrItem[1];
+        const Fee = arrItem[2];
+        if (TrackingNumber && ActiveWeight && Fee) {
+          result.push({
+            TrackingNumber,
+            ActiveWeight,
+            Fee
+          })
+        }
       });
       return result
     },
+    // 获取上传文件后的数据
+    getNewFeeList(list) {
+      const newsList = list.map(item => ({ TrackingNumber: item.TrackingNumber, ActiveWeight: item.ActiveWeight, Fee: item.Fee }))
+      this.pageWeightThrowingLoading = true
+      _GetNewFee(newsList).then((res) => {
+        this.weightThrowingData = res
+      }).finally(() => {
+        this.pageWeightThrowingLoading = false
+      })
+      // const weightThrowingData = [
+      //   {
+      //     "TrackingNumber": "4209894092001903608804663394184958",
+      //     "IsSuccess": true,
+      //     "ErrorMessage": null,
+      //     "ReceiverTime": "2024-05-31T11:13:50",
+      //     "OldWeight": 0.500,
+      //     "OldFee": 9.18,
+      //     "oldZone": "5",
+      //     "SystemFee": 9.18,
+      //     "NewWeight": 0.5,
+      //     "InputFee": 7.87,
+      //     "InputFee_OldFee": -1.31,
+      //     "SystemFee_OldFee": 0.00
+      //   }
+      // ]
+      // this.weightThrowingData = weightThrowingData
+    },
     // 表格错误样式
     rowClassName({ row }) {
       if(row.ResultState === 500) return 'error-bg'
@@ -350,14 +450,14 @@ export default {
     // 请求
     getCancelOrder(rowData, rowIndex) {
       return new Promise((resolve) => {
-        if(rowData.TransferNumber) {
+        if(rowData.TrackingNumber) {
           // 初始化时间
           const createTime = getCurrentDateTime()
           this.$set(this.batchListSource[rowIndex], 'CreateTime', createTime);
           const currentIndex = this.batchListSource.findIndex((i) => i.id === rowData.id)
           const data = {
-            TrackingNumber: rowData.TransferNumber,
-            ActiveWeight: rowData.Weight,
+            TrackingNumber: rowData.TrackingNumber,
+            ActiveWeight: rowData.ActiveWeight,
           }
           axios({
             method: 'post',
@@ -427,7 +527,7 @@ export default {
       try {
         this.confirmLoading = true
         const list = this.batchListSource.map((item, index) => {
-          if(item.TransferNumber) {
+          if(item.TrackingNumber) {
             item.id = `${index}_transferNumber`
             item.CreateTime = '-'
             item.ResultMessage = '-'
@@ -437,7 +537,7 @@ export default {
         this.batchListSource = list
         // 同步
         for await (const [rowIndex, rowData] of list.entries()) {
-          if (rowData.TransferNumber) {
+          if (rowData.TrackingNumber) {
             await this.getCancelOrder(rowData, rowIndex)
           }
         }
@@ -448,43 +548,132 @@ export default {
       }
     },
     // 显示隐藏
-    hanleOpenEditCounting() {
+    hanleOpenEditWeight() {
       this.dialogWeight = true
     },
     closeDialogWeight() {
       this.dialogWeight = false
+      this.editWeightId = undefined
+      this.weightThrowingData = []
     },
-    // 确定
+    // 确定保存
     async hanleSubmitWeight() {
-      const $table = this.$refs.costListTableRef
-      const isValid = await $table.validate(true).catch(errMap => errMap)
-      if (!isValid) {
-        this.batchListSource = this.weightThrowingData
-        this.countingNum.totalNum = this.batchListSource.length
-        this.closeDialogWeight()
-        this.updateBatchCountingOrder()
+      this.useSystemDialogVisible = true
+      const list = this.weightThrowingData.map(item => {
+        const { _X_ROW_KEY, ...rest } = item;
+        return rest;
+      });
+      this.saveNewFeeParams.serviceWeightResult = list
+      // const $table = this.$refs.costListTableRef
+      // const isValid = await $table.validate(true).catch(errMap => errMap)
+      // if (!isValid) {
+      //   this.batchListSource = this.weightThrowingData
+      //   this.countingNum.totalNum = this.batchListSource.length
+      //   this.closeDialogWeight()
+      //   this.updateBatchCountingOrder()
+      // }
+    },
+    initSaveNewFeeList() {
+      this.customerWeightLoading = true
+      _GetCustomerWeightSupplementary(this.pagerDto).then((res) => {
+        this.customerWeightSupplementaryData = res.Result
+        this.pagerDto.total = res.TotalCount
+      }).finally(() => {
+        this.customerWeightLoading = false
+      })
+      // this.batchListSource = [
+      //   {
+      //     "FileName":"1.xlsx", /*文件名*/
+      //     "RowQty":100,/*补款条数*/
+      //     "SumSupplementary":1000,/*补款金额*/
+      //     "IsPost":"true"/*是否上传金额*/
+      //   }
+      // ]
+      // this.countingNum.totalNum = this.batchListSource.length
+    },
+    closeSaveNewFee() {
+      this.useSystemDialogVisible = false
+      this.saveNewFeeParams.useSystem = false
+      this.saveNewFeeParams.fileName = ''
+    },
+    okSaveNewFee() {
+      const useSystem = this.saveNewFeeParams.useSystem ? true : undefined
+      const params = {
+        ...this.saveNewFeeParams,
+        useSystem
       }
+      this.saveNewFeeLoading = true
+      _SaveNewFee(params).then((res) => {
+        this.$message({ type: 'success', message: '保存成功' })
+        this.closeSaveNewFee()
+        this.closeDialogWeight()
+        this.initSaveNewFeeList()
+      }).finally(() => {
+        this.saveNewFeeLoading = false
+      })
+    },
+    // 查看明细
+    onViewDetails(row) {
+      if (!row.Id) return
+      this.editWeightId = row.Id
+      this.$set(row, 'detailLoading', true)
+      _GetDetail(row.Id).then((res) => {
+        this.weightThrowingData = res
+        this.hanleOpenEditWeight()
+      }).finally(() => {
+        this.$set(row, 'detailLoading', false)
+      })
     },
-    // 可编辑表格
+    // 上传费用
+    onUploadFee(row) {
+      if (!row.Id) return
+      const that = this
+      that.$confirm('是否继续上传费用?', '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning',
+        beforeClose: (action, instance, done) => {
+          if (action === 'confirm') {
+            instance.confirmButtonLoading = true;
+            _UpdateSupplementaryGroup(row.Id).then(() => {
+              this.$message({
+                type: 'success',
+                message: '操作成功'
+              });
+              done();
+              that.initSaveNewFeeList()
+            }).finally(() => {
+              instance.confirmButtonLoading = false;
+            })
+          } else {
+            done();
+          }
+        }
+      })
+    },
+    // 明细分页-前度
     pageThrowingChange(page) {
       this.weightThrowingDataPage = page;
     },
     sizeThrowingChange(size) {
       this.weightThrowingDataSize = size;
     },
-    // 不可编辑表格
-    pageListSourceChange(page) {
-      this.listSourcePage = page;
+    // 外层分页-后端
+    pagerSerach(p) {
+      this.pagerDto.PageIndex = p
+      this.initSaveNewFeeList()
+    },
+    sizeChange(s) {
+      this.pagerDto.PageIndex = 1
+      this.pagerDto.PageSize = s
+      this.initSaveNewFeeList()
     },
-    sizeListSourceChange(size) {
-      this.listSourceSize = size;
-    }
   }
 }
 </script>
 
 <style lang="scss" scoped>
-  .counting-list-form .el-input-number ::v-deep .el-input__inner {
+  .batch-import-weight-form .el-input-number ::v-deep .el-input__inner {
     text-align: left !important;
   }
   .batch-import-weight {