Commit 80de3fc5 by linjinhong Committed by qinjianhui

fix:修改问题

parent a8bb3cf3
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
title="称重分拣" title="称重分拣"
:before-close="handleClose" :before-close="handleClose"
v-model="isweight" v-model="isweight"
width="850px" width="1200px"
> >
<div <div
style=" style="
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<input <input
class="inputWeight" class="inputWeight"
@keyup.enter="weightChange" @keyup.enter="weightChange"
style="flex: 1" style="flex: 1; border: 3px solid blue"
ref="weighInput" ref="weighInput"
:placeholder=" :placeholder="
weight.weightInput weight.weightInput
...@@ -108,7 +108,7 @@ interface ILogisticsList { ...@@ -108,7 +108,7 @@ interface ILogisticsList {
basicsName: string basicsName: string
apiData: unknown apiData: unknown
} }
import BigNumber from 'bignumber.js'
import weight from '../components/weigh.js' import weight from '../components/weigh.js'
import { listByNoApi, orderWeighingApi } from '@/api/podCnOrder' import { listByNoApi, orderWeighingApi } from '@/api/podCnOrder'
import { logisticsCompanyAllCodelist } from '@/api/logistics.ts' import { logisticsCompanyAllCodelist } from '@/api/logistics.ts'
...@@ -128,14 +128,14 @@ const tableConfig = ref<TableColumn[]>([ ...@@ -128,14 +128,14 @@ const tableConfig = ref<TableColumn[]>([
prop: 'trackingNumber', prop: 'trackingNumber',
label: '跟踪号', label: '跟踪号',
attrs: { attrs: {
minWidth: 180, minWidth: 120,
}, },
}, },
{ {
prop: 'shopNumber', prop: 'shopNumber',
label: '店铺单号', label: '店铺单号',
attrs: { attrs: {
minWidth: 180, minWidth: 120,
}, },
}, },
{ {
...@@ -206,11 +206,17 @@ const getlogisticsCompanyAllCodelist = async () => { ...@@ -206,11 +206,17 @@ const getlogisticsCompanyAllCodelist = async () => {
} }
} }
const warehouseWeightTotal = () => { const warehouseWeightTotal = (): number => {
return tableData.value?.reduce((prev, cur: IpodCnWeighingParams) => { if (!tableData.value) return 0
prev += +(cur.outWarehouseWeight || 0)
return prev return Number(
}, 0) 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 = () => { const handleClose = () => {
...@@ -220,6 +226,16 @@ const handleClose = () => { ...@@ -220,6 +226,16 @@ const handleClose = () => {
const weightChange = async () => { const weightChange = async () => {
const noValue = weightText.value const noValue = weightText.value
if (!noValue) return weight.playAudio('weight_search_error') 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 = '' weightText.value = ''
console.log(343, weight.weightInput) console.log(343, weight.weightInput)
...@@ -233,19 +249,27 @@ const weightChange = async () => { ...@@ -233,19 +249,27 @@ const weightChange = async () => {
type: selectType.value, type: selectType.value,
no: noValue, no: noValue,
} }
weight.check(noValue, listByNoApi, params, (arr) => { if (logisticsCompanyCode.value)
tableData.value = [...arr] params.logisticsCompanyCode = logisticsCompanyCode.value
if (!(noValue.length < 7)) { weight.check(
tableData.value.forEach((el) => { noValue,
if (el.trackingNumber === noValue) { listByNoApi,
console.log(1111, el) 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) tableRef.value?.selectRowEvent(el)
} }
}) })
} }
console.log(284, arr) console.log(284, arr)
}) },
selectType.value,
)
weighInput.value?.focus() weighInput.value?.focus()
} catch (error) { } catch (error) {
console.log(error) console.log(error)
......
...@@ -15,11 +15,13 @@ class Lock { ...@@ -15,11 +15,13 @@ class Lock {
} }
} }
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import BigNumber from 'bignumber.js'
// 定义数据类型 // 定义数据类型
interface WeighItem { interface WeighItem {
id?: string id?: string
outWarehouseWeight?: string outWarehouseWeight?: string
status?: string
trackingNumber?: string trackingNumber?: string
shopNumber?: string shopNumber?: string
...@@ -51,12 +53,14 @@ type AudioFiles = Record<AudioKey, string> ...@@ -51,12 +53,14 @@ type AudioFiles = Record<AudioKey, string>
class Weigh extends Lock { class Weigh extends Lock {
public weightInput: boolean public weightInput: boolean
public list: WeighItem[] public list: WeighItem[]
public selectType: string
private audios: AudioFiles private audios: AudioFiles
private audioElements: Map<AudioKey, HTMLAudioElement> private audioElements: Map<AudioKey, HTMLAudioElement>
constructor() { constructor() {
super() super()
this.weightInput = true this.weightInput = true
this.selectType = 'trackingNumber'
this.list = [] this.list = []
this.audios = { this.audios = {
weight_warning: new URL( weight_warning: new URL(
...@@ -97,6 +101,7 @@ class Weigh extends Lock { ...@@ -97,6 +101,7 @@ class Weigh extends Lock {
clear(): void { clear(): void {
this.list = [] this.list = []
this.weightInput = true this.weightInput = true
this.selectType = 'trackingNumber'
} }
updatedList(data: WeighItem[]) { updatedList(data: WeighItem[]) {
...@@ -129,7 +134,9 @@ class Weigh extends Lock { ...@@ -129,7 +134,9 @@ class Weigh extends Lock {
apiCall: (params: SearchItem) => Promise<Data>, apiCall: (params: SearchItem) => Promise<Data>,
params: SearchItem, params: SearchItem,
callback?: (list: WeighItem[]) => void, callback?: (list: WeighItem[]) => void,
type?: string,
): void { ): void {
this.selectType = type as string
// 空值检查 // 空值检查
if (!value?.trim()) { if (!value?.trim()) {
this.playAudio('weight_warning') this.playAudio('weight_warning')
...@@ -173,20 +180,36 @@ class Weigh extends Lock { ...@@ -173,20 +180,36 @@ class Weigh extends Lock {
console.log('currentItem', this.list) console.log('currentItem', this.list)
if (!this.list.length) { if (!this.list.length) {
this.playAudio('weight_warning', '请先录入跟踪号') this.playAudio(
'weight_warning',
`请录入${this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'}`,
)
return return
} }
// 检查是否已录入重量 // 检查是否已录入重量
if (!this.hasPendingWeights()) { if (!this.hasPendingWeights()) {
this.playAudio('weight_warning', '请录入跟踪号') this.playAudio(
'weight_warning',
`请录入${this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'}`,
)
return return
} }
this.list = this.list.map((el) => { this.list = this.list.map((el) => {
if (!el.outWarehouseWeight) { 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 { return {
...el, ...el,
outWarehouseWeight: value, outWarehouseWeight: value,
wgap: Math.abs(Number(value) - Number(el.weight || 0)), wgap: wgap,
} }
} }
return el return el
...@@ -219,15 +242,28 @@ class Weigh extends Lock { ...@@ -219,15 +242,28 @@ class Weigh extends Lock {
const { data } = response const { data } = response
console.log(211, data) 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', '查询失败') this.playAudio('weight_search_error', '查询失败')
return return
} }
// 最终去重检查 // 最终去重检查
if ( if (
this.deduplicate( this.deduplicate(
(data[0] as WeighItem).trackingNumber as string, (waitWeighingList[0] as WeighItem).trackingNumber as string,
callback, callback,
) )
) { ) {
...@@ -235,7 +271,7 @@ class Weigh extends Lock { ...@@ -235,7 +271,7 @@ class Weigh extends Lock {
} }
// 添加新项目 // 添加新项目
this.addNewItem(data, callback) this.addNewItem(waitWeighingList, callback)
} catch (error) { } catch (error) {
console.error('跟踪号查询错误:', error) console.error('跟踪号查询错误:', error)
this.playAudio('weight_search_error') this.playAudio('weight_search_error')
...@@ -262,10 +298,14 @@ class Weigh extends Lock { ...@@ -262,10 +298,14 @@ class Weigh extends Lock {
playAudio(key: AudioKey, message?: string): void { playAudio(key: AudioKey, message?: string): void {
const messageMap: Record<AudioKey, string> = { const messageMap: Record<AudioKey, string> = {
weight_warning: '请录入跟踪号或重量', weight_warning: `请录入${
this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'
}或重量`,
weight_success: '', weight_success: '',
weight_repeat: '重复录入', weight_repeat: '重复录入',
weight_search_error: '请录入跟踪号或重量', weight_search_error: `请录入${
this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'
}或重量`,
weight_search_success: '', weight_search_success: '',
} }
......
...@@ -545,7 +545,7 @@ ...@@ -545,7 +545,7 @@
style="width: 150px" style="width: 150px"
> >
<ElOption <ElOption
v-for="(item, index) in ['否', '是']" v-for="(_, index) in ['否', '是']"
:key="index" :key="index"
:value="!!index" :value="!!index"
:label="index === 0 ? '否' : '是'" :label="index === 0 ? '否' : '是'"
......
...@@ -506,7 +506,7 @@ ...@@ -506,7 +506,7 @@
style="width: 150px" style="width: 150px"
> >
<ElOption <ElOption
v-for="(item, index) in ['否', '是']" v-for="(_, index) in ['否', '是']"
:key="index" :key="index"
:value="!!index" :value="!!index"
:label="index === 0 ? '否' : '是'" :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