Commit 80de3fc5 by linjinhong Committed by qinjianhui

fix:修改问题

parent a8bb3cf3
......@@ -6,7 +6,7 @@
title="称重分拣"
:before-close="handleClose"
v-model="isweight"
width="850px"
width="1200px"
>
<div
style="
......@@ -27,7 +27,7 @@
<input
class="inputWeight"
@keyup.enter="weightChange"
style="flex: 1"
style="flex: 1; border: 3px solid blue"
ref="weighInput"
:placeholder="
weight.weightInput
......@@ -108,7 +108,7 @@ interface ILogisticsList {
basicsName: string
apiData: unknown
}
import BigNumber from 'bignumber.js'
import weight from '../components/weigh.js'
import { listByNoApi, orderWeighingApi } from '@/api/podCnOrder'
import { logisticsCompanyAllCodelist } from '@/api/logistics.ts'
......@@ -128,14 +128,14 @@ const tableConfig = ref<TableColumn[]>([
prop: 'trackingNumber',
label: '跟踪号',
attrs: {
minWidth: 180,
minWidth: 120,
},
},
{
prop: 'shopNumber',
label: '店铺单号',
attrs: {
minWidth: 180,
minWidth: 120,
},
},
{
......@@ -206,11 +206,17 @@ const getlogisticsCompanyAllCodelist = async () => {
}
}
const warehouseWeightTotal = () => {
return tableData.value?.reduce((prev, cur: IpodCnWeighingParams) => {
prev += +(cur.outWarehouseWeight || 0)
return prev
}, 0)
const warehouseWeightTotal = (): number => {
if (!tableData.value) return 0
return Number(
tableData.value
.reduce((prev: BigNumber, cur: IpodCnWeighingParams) => {
const weight = new BigNumber(cur.outWarehouseWeight || 0)
return prev.plus(weight)
}, new BigNumber(0))
.toFixed(2), // 保留两位小数
)
}
const handleClose = () => {
......@@ -220,6 +226,16 @@ const handleClose = () => {
const weightChange = async () => {
const noValue = weightText.value
if (!noValue) return weight.playAudio('weight_search_error')
if (weight.weightInput) {
if (noValue.length < 7)
return weight.playAudio(
'weight_search_error',
`没有该${
selectType.value === 'trackingNumber' ? '跟踪号' : '店铺单号'
}相关的订单`,
)
}
weightText.value = ''
console.log(343, weight.weightInput)
......@@ -233,19 +249,27 @@ const weightChange = async () => {
type: selectType.value,
no: noValue,
}
weight.check(noValue, listByNoApi, params, (arr) => {
tableData.value = [...arr]
if (!(noValue.length < 7)) {
tableData.value.forEach((el) => {
if (el.trackingNumber === noValue) {
console.log(1111, el)
if (logisticsCompanyCode.value)
params.logisticsCompanyCode = logisticsCompanyCode.value
weight.check(
noValue,
listByNoApi,
params,
(arr) => {
tableData.value = [...arr]
if (!(noValue.length < 7)) {
tableData.value.forEach((el) => {
if (el.trackingNumber === noValue || el.shopNumber === noValue) {
console.log(1111, el)
tableRef.value?.selectRowEvent(el)
}
})
}
console.log(284, arr)
})
tableRef.value?.selectRowEvent(el)
}
})
}
console.log(284, arr)
},
selectType.value,
)
weighInput.value?.focus()
} catch (error) {
console.log(error)
......
......@@ -15,11 +15,13 @@ class Lock {
}
}
import { ElMessage } from 'element-plus'
import BigNumber from 'bignumber.js'
// 定义数据类型
interface WeighItem {
id?: string
outWarehouseWeight?: string
status?: string
trackingNumber?: string
shopNumber?: string
......@@ -51,12 +53,14 @@ type AudioFiles = Record<AudioKey, string>
class Weigh extends Lock {
public weightInput: boolean
public list: WeighItem[]
public selectType: string
private audios: AudioFiles
private audioElements: Map<AudioKey, HTMLAudioElement>
constructor() {
super()
this.weightInput = true
this.selectType = 'trackingNumber'
this.list = []
this.audios = {
weight_warning: new URL(
......@@ -97,6 +101,7 @@ class Weigh extends Lock {
clear(): void {
this.list = []
this.weightInput = true
this.selectType = 'trackingNumber'
}
updatedList(data: WeighItem[]) {
......@@ -129,7 +134,9 @@ class Weigh extends Lock {
apiCall: (params: SearchItem) => Promise<Data>,
params: SearchItem,
callback?: (list: WeighItem[]) => void,
type?: string,
): void {
this.selectType = type as string
// 空值检查
if (!value?.trim()) {
this.playAudio('weight_warning')
......@@ -173,20 +180,36 @@ class Weigh extends Lock {
console.log('currentItem', this.list)
if (!this.list.length) {
this.playAudio('weight_warning', '请先录入跟踪号')
this.playAudio(
'weight_warning',
`请录入${this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'}`,
)
return
}
// 检查是否已录入重量
if (!this.hasPendingWeights()) {
this.playAudio('weight_warning', '请录入跟踪号')
this.playAudio(
'weight_warning',
`请录入${this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'}`,
)
return
}
this.list = this.list.map((el) => {
if (!el.outWarehouseWeight) {
// 确保输入值也是BigNumber处理过的
const valueNum = Number(value) || 0
const weightNum = Number(el.weight) || 0
const wgap = new BigNumber(valueNum)
.minus(weightNum)
.abs()
.decimalPlaces(2, BigNumber.ROUND_HALF_UP) // 明确指定四舍五入规则
.toNumber()
return {
...el,
outWarehouseWeight: value,
wgap: Math.abs(Number(value) - Number(el.weight || 0)),
wgap: wgap,
}
}
return el
......@@ -219,15 +242,28 @@ class Weigh extends Lock {
const { data } = response
console.log(211, data)
const waitWeighingList = data.filter(
(el) => el.status === 'WAIT_WEIGHING',
)
if (waitWeighingList.length === 0) {
this.playAudio(
'weight_search_error',
`必须是待称重状态的订单下的${
this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'
}才能使用`,
)
return
}
if (!data.length) {
if (!waitWeighingList.length) {
this.playAudio('weight_search_error', '查询失败')
return
}
// 最终去重检查
if (
this.deduplicate(
(data[0] as WeighItem).trackingNumber as string,
(waitWeighingList[0] as WeighItem).trackingNumber as string,
callback,
)
) {
......@@ -235,7 +271,7 @@ class Weigh extends Lock {
}
// 添加新项目
this.addNewItem(data, callback)
this.addNewItem(waitWeighingList, callback)
} catch (error) {
console.error('跟踪号查询错误:', error)
this.playAudio('weight_search_error')
......@@ -262,10 +298,14 @@ class Weigh extends Lock {
playAudio(key: AudioKey, message?: string): void {
const messageMap: Record<AudioKey, string> = {
weight_warning: '请录入跟踪号或重量',
weight_warning: `请录入${
this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'
}或重量`,
weight_success: '',
weight_repeat: '重复录入',
weight_search_error: '请录入跟踪号或重量',
weight_search_error: `请录入${
this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'
}或重量`,
weight_search_success: '',
}
......
......@@ -545,7 +545,7 @@
style="width: 150px"
>
<ElOption
v-for="(item, index) in ['否', '是']"
v-for="(_, index) in ['否', '是']"
:key="index"
:value="!!index"
:label="index === 0 ? '否' : '是'"
......
......@@ -506,7 +506,7 @@
style="width: 150px"
>
<ElOption
v-for="(item, index) in ['否', '是']"
v-for="(_, index) in ['否', '是']"
:key="index"
:value="!!index"
:label="index === 0 ? '否' : '是'"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment