emis-app/common/scanUtil.js

93 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-05-08 07:27:30 +00:00
import dayjs from "dayjs"
2024-06-14 15:43:50 +00:00
import { showToast, playAudio } from "@/common/untool"
import { audioTypeEnum } from "@/common/enum"
2024-06-15 15:17:03 +00:00
import * as apiService from "@/common/api"
2024-05-08 07:27:30 +00:00
export const scanTypeEnum = {
lanShou: 10, // 揽收
faJian: 20, // 发件
daoJian: 30, // 到件
paiJian: 40, // 派件
2024-05-08 07:51:44 +00:00
qianShou: 50, // 签收
2024-06-12 15:41:48 +00:00
zhuangChe: 301, // 装车、装柜、整车
xieChe: 302, // 卸车
2024-05-30 10:49:05 +00:00
liuCang: 70, // 留仓
2024-05-30 10:19:13 +00:00
zhuanJian: 80, // 转件
2024-05-30 11:24:27 +00:00
heBao: 200, // 合包
chaiBao: 201, // 拆包
2024-05-30 10:49:05 +00:00
qingGuan: 800, // 清关
baoGUan: 700, // 报关
2024-05-08 07:27:30 +00:00
}
2024-06-15 15:17:03 +00:00
export const getScanParams = (type, model = {}, extModel = {})=> {
2024-06-15 06:53:59 +00:00
let scanDate = dayjs().format("YYYY-MM-DD HH:mm:ss")
2024-05-08 07:27:30 +00:00
return {
scanType: type, // 扫描类型
2024-06-15 15:17:03 +00:00
opType: 2, // 动作, 1 检查; 2 确认
2024-05-08 07:27:30 +00:00
scanData: [{
2024-06-15 06:53:59 +00:00
scanDate,
2024-05-08 07:27:30 +00:00
...model,
2024-06-15 15:17:03 +00:00
}],
...extModel,
2024-05-08 07:27:30 +00:00
}
}
export const ansScanResponse = ({ res, title })=> {
let resItem = res?.data?.scanResult?.[0] || {}
2024-05-10 01:25:24 +00:00
resItem.data && ( Object.assign(resItem, { ...resItem.data }) )
2024-05-08 07:27:30 +00:00
let result = resItem?.result
let bl = false
if(result == "success") {
bl = true
2024-06-15 06:53:59 +00:00
if(title) {
playAudio(audioTypeEnum.correct)
showToast(`${title}成功`)
}
2024-05-08 07:27:30 +00:00
} else {
2024-06-14 15:43:50 +00:00
switch (resItem?.message){
case '重复扫描':
playAudio(audioTypeEnum.repetitive)
break;
case '运单号不存在':
playAudio(audioTypeEnum.dotexist)
break;
default:
2024-06-15 06:53:59 +00:00
// playAudio(audioTypeEnum.networkError)
2024-06-14 15:43:50 +00:00
break;
}
2024-05-08 09:39:40 +00:00
showToast(resItem?.message || `${title}失败`)
2024-05-08 07:27:30 +00:00
}
return {
bl,
resItem,
}
2024-06-15 15:17:03 +00:00
}
// 扫描预检-- 接口
export const preCheckScan = async ({ param, extParam, list, scanType })=> {
let scnParam = getScanParams(scanType, { ...param }, { ...(extParam || {}), opType: 1 })
let res = await apiService.scanRecord({...scnParam, _loading: true})
let { bl, resItem } = ansScanResponse({ res })
if(bl) {
// 更新list
if(list) {
let existItem = list.filter(t=> t.billCode == resItem.billCode)[0]
if(existItem?.billCode) {
bl = false // 已扫描, list已存在
playAudio(audioTypeEnum.repetitive)
showToast('重复扫描')
} else {
list.unshift({ ...resItem })
}
}
}
return bl
}
// 扫描确认-- 接口
export const confirmScanUpload = async ({ param, extParam, list, scanType })=> {
let scnParam = getScanParams(scanType, { ...param }, { ...(extParam || {}) })
let res = await apiService.scanRecord({...scnParam, _loading: true})
let { bl, resItem } = ansScanResponse({ res })
return bl
2024-05-08 07:27:30 +00:00
}