Commit 28ba2892 by wuqian

检索校验

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