Commit 28ba2892 by wuqian

检索校验

parent 16e6395a
......@@ -263,3 +263,10 @@ export interface shopRemark {
resendNum?: number | undefined | null
remark?: string | undefined | null
}
export interface ICompareObjects {
lanshouAddress?: string
lanshouName?: string
lanshouPhone?: string
lanshouPost?: string
lanshouRegion?: string
}
......@@ -4,6 +4,7 @@ import {
ProductList,
ShipmentForm,
ShipmentOrderRes,
ICompareObjects,
} from '@/types/api/order'
import { useValue } from '@/utils/hooks/useValue'
import { nextTick, ref } from 'vue'
......@@ -17,12 +18,14 @@ export default function useShipment(callback?: () => void) {
carriageAmount: '',
namespace: '',
})
const firstResult = ref<ICompareObjects | null>(null)
const shipmentFormRef = ref()
const productionOrderNumber = ref('')
const shipmentVisible = ref(false)
const isLock = ref(false)
const inputRef = ref()
const currentRow = ref<ProductList>()
// const currentRow = ref<ProductList>()
const currentRow = ref<ProductList | undefined>(undefined)
const shipmentLoading = ref(false)
const shipmentOrderRef = ref<ShipmentType>()
const searchShipmentByOrderNumber = async () => {
......@@ -48,7 +51,6 @@ export default function useShipment(callback?: () => void) {
}
}
if (rowData) {
currentRow.value = rowData
const unShipmentNum =
(rowData.num || 0) -
......@@ -92,45 +94,19 @@ export default function useShipment(callback?: () => void) {
shipmentLoading.value = true
const res = await getOrderBySubOrderNumber(code)
if (res.data) {
const code1 = code?.split('_')[0]
for (const item of res.data.productList || []) {
item.count = 0
if (item.subOrderNumber === code1) {
item.count =
(item.num || 0) -
((item.shipmentNum || 0) - (item.notPassNum || 0))
if (+item.count > 1) {
ElMessageBox.confirm(
`该产品未发数为${item.count}件`,
'重要提示',
{
confirmButtonText: '确定',
type: 'warning',
},
).catch(() => {})
}
currentRow.value = item
currentRow.value.orderNumber = res.data.orderNumber
if (firstResult.value === null) {
firstResult.value = res.data
canJoin(res.data, code)
} else {
if (!compareObjects(firstResult.value, res.data)) {
ElMessageBox.confirm('不能加入,地址信息不一致!', '重要提示', {
confirmButtonText: '确定',
type: 'warning',
}).catch(() => {})
} else {
canJoin(res.data, code)
}
}
const index = orderList.value.findIndex(
(item) => item.id === res.data.id,
)
if (index === -1) {
orderList.value.unshift(res.data)
}
playAudio('picking_search_success')
await nextTick()
if (shipmentOrderRef.value) {
const rowEl = shipmentOrderRef.value.listRef?.querySelector(
`div[data-id="${currentRow.value?.id}"]`,
)
if (!rowEl) return
rowEl.scrollIntoView()
}
}
inputRef.value.focus()
productionOrderNumber.value = ''
......@@ -145,6 +121,55 @@ export default function useShipment(callback?: () => void) {
shipmentLoading.value = false
}
}
const canJoin = async (data: any, code: string) => {
const code1 = code?.split('_')[0]
for (const item of data.productList || []) {
item.count = 0
if (item.subOrderNumber === code1) {
item.count =
(item.num || 0) - ((item.shipmentNum || 0) - (item.notPassNum || 0))
if (+item.count > 1) {
ElMessageBox.confirm(`该产品未发数为${item.count}件`, '重要提示', {
confirmButtonText: '确定',
type: 'warning',
}).catch(() => {})
}
currentRow.value = item
if (currentRow.value) {
currentRow.value.orderNumber = data.orderNumber
}
}
}
const index = orderList.value.findIndex((item) => item.id === data.id)
if (index === -1) {
orderList.value.unshift(data)
}
playAudio('picking_search_success')
await nextTick()
if (shipmentOrderRef.value) {
const rowEl = shipmentOrderRef.value.listRef?.querySelector(
`div[data-id="${currentRow.value?.id}"]`,
)
if (!rowEl) return
rowEl.scrollIntoView()
}
}
const compareObjects = (
obj1: ICompareObjects,
obj2: ICompareObjects,
): boolean => {
const keysToCompare: (keyof ICompareObjects)[] = [
'lanshouAddress',
'lanshouName',
'lanshouPhone',
'lanshouPost',
'lanshouRegion',
]
return keysToCompare.every((key) => obj1[key] === obj2[key])
} //将后面的查询结果和第一次的结果进行比较,相同才能加入,反之不能
const saveShipment = async () => {
if (orderList.value.length === 0) {
return ElMessage({
......@@ -200,6 +225,7 @@ export default function useShipment(callback?: () => void) {
const confirmDelivery = async () => {
shipmentVisible.value = true
productionOrderNumber.value = ''
firstResult.value = null //弹窗打开前先清空第一次的结果
resetOrderList()
resetShipmentForm()
}
......@@ -217,7 +243,10 @@ export default function useShipment(callback?: () => void) {
*/
const playAudio = (key: string) => {
const audio = new Audio()
const audioPath = new URL(`../../../assets/audio/${key}.mp3`, import.meta.url).href
const audioPath = new URL(
`../../../assets/audio/${key}.mp3`,
import.meta.url,
).href
audio.src = audioPath
audio.play()
}
......
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