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