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,34 +94,57 @@ export default function useShipment(callback?: () => void) { ...@@ -92,34 +94,57 @@ 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) {
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)
}
}
}
inputRef.value.focus()
productionOrderNumber.value = ''
isLock.value = false
} catch (e) {
productionOrderNumber.value = ''
isLock.value = false
inputRef.value.focus()
//showError(e)
playAudio('picking_search_error')
} finally {
shipmentLoading.value = false
}
}
const canJoin = async (data: any, code: string) => {
const code1 = code?.split('_')[0] const code1 = code?.split('_')[0]
for (const item of res.data.productList || []) { for (const item of data.productList || []) {
item.count = 0 item.count = 0
if (item.subOrderNumber === code1) { if (item.subOrderNumber === code1) {
item.count = item.count =
(item.num || 0) - (item.num || 0) - ((item.shipmentNum || 0) - (item.notPassNum || 0))
((item.shipmentNum || 0) - (item.notPassNum || 0))
if (+item.count > 1) { if (+item.count > 1) {
ElMessageBox.confirm( ElMessageBox.confirm(`该产品未发数为${item.count}件`, '重要提示', {
`该产品未发数为${item.count}件`,
'重要提示',
{
confirmButtonText: '确定', confirmButtonText: '确定',
type: 'warning', type: 'warning',
}, }).catch(() => {})
).catch(() => {})
} }
currentRow.value = item currentRow.value = item
currentRow.value.orderNumber = res.data.orderNumber if (currentRow.value) {
currentRow.value.orderNumber = data.orderNumber
} }
} }
const index = orderList.value.findIndex( }
(item) => item.id === res.data.id, const index = orderList.value.findIndex((item) => item.id === data.id)
)
if (index === -1) { if (index === -1) {
orderList.value.unshift(res.data) orderList.value.unshift(data)
} }
playAudio('picking_search_success') playAudio('picking_search_success')
await nextTick() await nextTick()
...@@ -132,19 +157,19 @@ export default function useShipment(callback?: () => void) { ...@@ -132,19 +157,19 @@ export default function useShipment(callback?: () => void) {
rowEl.scrollIntoView() rowEl.scrollIntoView()
} }
} }
inputRef.value.focus() const compareObjects = (
productionOrderNumber.value = '' obj1: ICompareObjects,
isLock.value = false obj2: ICompareObjects,
} catch (e) { ): boolean => {
productionOrderNumber.value = '' const keysToCompare: (keyof ICompareObjects)[] = [
isLock.value = false 'lanshouAddress',
inputRef.value.focus() 'lanshouName',
//showError(e) 'lanshouPhone',
playAudio('picking_search_error') 'lanshouPost',
} finally { 'lanshouRegion',
shipmentLoading.value = false ]
} 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