emis-app/common/scanUtil.js
2024-06-28 16:44:23 +08:00

98 lines
2.5 KiB
JavaScript

import dayjs from "dayjs"
import { showToast, playAudio } from "@/common/untool"
import { audioTypeEnum } from "@/common/enum"
import * as apiService from "@/common/api"
export const scanTypeEnum = {
lanShou: 10, // 揽收
faJian: 20, // 发件
daoJian: 30, // 到件
paiJian: 40, // 派件
qianShou: 50, // 签收
tiHuo: 90, // 提货
zhuangChe: 301, // 装车、装柜、整车
xieChe: 302, // 卸车
liuCang: 70, // 留仓
zhuanJian: 80, // 转件
heBao: 200, // 合包
chaiBao: 201, // 拆包
qingGuan: 800, // 清关
baoGUan: 700, // 报关
}
export const getScanParams = (type, model = {}, extModel = {})=> {
let scanDate = dayjs().format("YYYY-MM-DD HH:mm:ss")
return {
scanType: type, // 扫描类型
opType: 2, // 动作, 1 检查; 2 确认
scanData: [{
scanDate,
...model,
}],
...extModel,
}
}
export const ansScanResponse = ({ res, title })=> {
let resItem = res?.data?.scanResult?.[0] || {}
resItem.data && ( Object.assign(resItem, { ...resItem.data }) )
let errorCode = resItem?.errorCode
let bl = false
if(errorCode == "0000") {
bl = true
if(title) {
playAudio(audioTypeEnum.correct)
showToast(`${title}成功`)
}
} else {
switch (errorCode){
case 'E603':
playAudio(audioTypeEnum.repetitive)
break;
case 'E602':
playAudio(audioTypeEnum.dotexist)
break;
// E601:参数错误
// E604:已签收
// E605:已组包
// E606:不允许操作
default:
// playAudio(audioTypeEnum.networkError)
break;
}
showToast(resItem?.message || `${title}失败`)
}
return {
bl,
resItem,
}
}
// 扫描预检-- 接口
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
}