Commit 6d3b965d by wuqian

new-pod-cn

parent cc6f038d
......@@ -8,6 +8,7 @@ import {
WarehouseListData,
LogisticsData,
ExportParams,
IconfirmSubmit
} from '@/types/api/podCnOrder'
import { InterceptStateGroupData } from '@/types/api/podUsOrder'
import axios from './axios'
......@@ -32,6 +33,24 @@ export function syncReceiverAddress(data: number[]) {
data,
)
}
export function getPackingCnDataApi(
code: string,
factoryNo: number,
box: number | null,
warehouseId: number | string,
) {
return axios.get<never, BaseRespData<PodMakeOrderData>>(
'/factory/podJomallOrderCn/getPodBoxDetailsBySkuOrNo',
{
params: {
podJomallCnNo: code,
box,
factoryNo,
warehouseId,
},
},
)
}
export function refreshAddressApi(idList: number[]) {
return axios.post<never, BaseRespData<never>>(
'factory/podJomallOrderCn/syncReceiverAddress',
......@@ -382,10 +401,10 @@ export function replenishmentSuccessApi(data: number[]) {
)
}
//确认生产
export function confirmProductApi(orderIds: (string | number)[]) {
export function confirmProductApi(data:IconfirmSubmit) {
return axios.post<never, BaseRespData<never>>(
`factory/podJomallOrderCn/confirmProduct`,
orderIds,
data,
)
}
export function toOutOfStockApi(ids: number[]) {
......@@ -450,6 +469,14 @@ export function batchDownloadRecomposingApi(params: { id: number }) {
},
)
}
export function batchDownloadCnRecomposingApi(params: { id: number }) {
return axios.get<never, BaseRespData<never>>(
`factory/podBatchDownload/reCnComposingDesignImages`,
{
params,
},
)
}
// 生产完成
export function updateToWaitShipmentApi(params: {
cnUpdateParams: Array<{
......@@ -515,7 +542,7 @@ export function updateSelfLogistics(params: {
id?: string
}) {
return axios.post<never, BaseRespData<never>>(
'factory/podJomallOrderUs/updateSelfLogistics',
'factory/podJomallOrderCn/updateSelfLogistics',
params,
)
}
......
import { defineStore } from 'pinia'
import {
OrderData,
PodMakeOrderData,
ProductList,
} from '@/types/api/podMakeOrder'
import { getPodBoxListApi } from '@/api/podCnOrder'
export interface OrderStoreState {
podBoxList?: PodMakeOrderData[]
podBoxIndex?: number | null
socketConnect?: string
}
const useOrderStore = defineStore('order', {
state: () => {
return {
podBoxList: [],
podBoxIndex: null,
socketConnect: '',
} as OrderStoreState
},
actions: {
async setPodBoxList(content: {
boxList: PodMakeOrderData[] | OrderData | null
factoryNo: number | string
warehouseId: number | string
box?: number
data?: OrderData
}) {
const { factoryNo, warehouseId, boxList, box, data } = content
if (Array.isArray(boxList)) {
this.podBoxList = boxList
} else {
const index = this.podBoxList?.findIndex((item) => item.box === box)
if (index === -1) {
try {
const res = await getPodBoxListApi(factoryNo, warehouseId)
const boxList = res.data.map((item) => {
if (res.data) {
const productList = item?.data?.productList || []
const pickingNumber = productList.reduce(
(prev: number, item1: ProductList) => {
if (item1.count) {
return prev + item1.count
}
return prev
},
0,
)
if (item.data) {
item.data.pickingNumber = pickingNumber
}
}
return item
})
this.podBoxList = boxList
this.podBoxIndex = box
} catch (error) {
console.error(error)
}
} else if (box !== 0 && box !== undefined) {
const arr = this.podBoxList
if (arr) {
arr[box - 1] = {
box,
data: data || boxList || null,
}
}
this.podBoxList = arr
this.podBoxIndex = box
}
}
},
// 清空所有箱子
clearPodBoxList() {
this.podBoxList = []
},
// 设置当前箱子
setPodBox(box: number) {
this.podBoxIndex = box
},
// 清空当前箱子
clearPodBox() {
this.podBoxIndex = null
},
setSocketConnect(connect: string) {
this.socketConnect = connect
},
},
})
export default useOrderStore
......@@ -66,7 +66,6 @@ const useOrderStore = defineStore('order', {
data: data || boxList || null,
}
}
console.log('222arr1111', arr)
this.podBoxList = arr
this.podBoxIndex = box
}
......
......@@ -3,6 +3,11 @@ export interface Tab {
statusName?: string
quantity?: number
}
export interface IconfirmSubmit {
ids: string
warehouseId: number | null
warehouseName: string
}
export interface ExportParams extends SearchForm {
idList?: number[]
exportAll: boolean
......@@ -32,6 +37,8 @@ export interface SearchForm {
batchArrangeNumber?: string
craftCode?: string
thirdStockSku?: string
exceptionHandling?: number | undefined
interceptStatus?: number | string
}
export interface PodCnOrderListData {
id: number
......@@ -122,7 +129,9 @@ export interface ProductList {
isReplenishment?: boolean
thirdSkuCode?: string | null
supplierProductNo?: string | null
userMark?: string | null
replenishmentSumNum?: number | null
interceptStatus?: number | null
batchArrangeNumber?: string | null
}
export interface cardImages {
......
......@@ -45,5 +45,6 @@ export interface ProductList {
power?: boolean
variantImage?: string
podJomallUsNo?: string
podJomallCnNo?: string
previewImgs?: { sort: string | number; title: string; url: string }[]
}
import { getWsUrl } from '../api/axios'
import useOrderStore from '../store/cnOrder'
interface NotificationOptions {
body: string
icon: string
data: string
requireInteraction: boolean
}
export interface WebSocketMessage {
code?: string
content?: string
type?: string
data?: unknown
[key: string]: string | unknown | undefined
}
interface InitOptions {
account: string
factoryNo: string
}
type MessageCallback = (
data: WebSocketMessage,
sendSystemMessage: (msg: string) => void,
) => void
type OpenCallback = () => void
function sendSystemMessage(msg: string): void {
if (window.Notification && Notification.permission === 'granted') {
const notificationOptions: NotificationOptions = {
body: msg,
icon: './favicon.ico',
data: 'I like peas.',
requireInteraction: true,
}
const n = new Notification('消息通知', notificationOptions)
n.onclick = (event: Event) => {
event.preventDefault()
window.open('/home', '_blank')
}
setTimeout(() => {
n.close()
}, 10000)
}
}
const showReconnectingMsg = (): void => {
ElMessageBox.alert('消息服务已断开,正在重新连接,请稍候', {
showClose: true,
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
}
class Im {
private socket: WebSocket | null = null
private _wsUrl: string = ''
// private userId: string = ''
private _onMessageCallback?: MessageCallback
private _onOpenCallback?: OpenCallback
private _heartbeatTimer: number | null = null
private _heartbeatTimeoutTimer: number | null = null
private _reconnectingTimer: number | null = null
private num: number = 0
constructor() {
this._onWsOpen = this._onWsOpen.bind(this)
this._onWsMessage = this._onWsMessage.bind(this)
this._onWsClose = this._onWsClose.bind(this)
this._onWsError = this._onWsError.bind(this)
}
private _onWsOpen(): void {
console.log('服务器连接成功')
localStorage.setItem('socket_connect', 'online')
this._onOpenCallback?.()
this._startHeartbeat()
}
private _onWsMessage(event: MessageEvent): void {
let data: WebSocketMessage = {}
if (typeof event.data === 'string') {
try {
data = JSON.parse(event.data)
} catch (error) {
data = {}
}
}
this._onHeartbeatMessage()
this._onMessageCallback?.(data, sendSystemMessage)
}
private _onWsClose(): void {
console.log('服务器关闭')
this._destroyWebSocket(true)
}
private _onWsError(): void {
console.log('连接出错')
this._destroyWebSocket(true)
}
private _sendHeartbeat(): void {
if (!this.socket) return
this.send({ code: 'HEALTH' })
if (this._heartbeatTimeoutTimer) {
window.clearTimeout(this._heartbeatTimeoutTimer)
}
this._heartbeatTimeoutTimer = window.setTimeout(() => {
this._destroyWebSocket(true)
}, 5 * 1000)
}
private _onHeartbeatMessage(): void {
console.log('心跳')
useOrderStore().setSocketConnect('online')
if (this._heartbeatTimeoutTimer) {
window.clearTimeout(this._heartbeatTimeoutTimer)
}
}
private _startHeartbeat(): void {
this._stopHeartbeat()
this._sendHeartbeat()
this._heartbeatTimer = window.setInterval(
() => this._sendHeartbeat(),
10 * 1000,
)
}
private _stopHeartbeat(): void {
if (this._heartbeatTimer) {
window.clearInterval(this._heartbeatTimer)
}
if (this._heartbeatTimeoutTimer) {
window.clearTimeout(this._heartbeatTimeoutTimer)
}
}
private _scheduleReconnect(): void {
if (!this.num) this.num = 0
this.num++
if (this.num > 5) {
ElMessageBox.alert('尝试重连消息服务失败,请刷新重试')
return
}
showReconnectingMsg()
this._reconnectingTimer = window.setTimeout(() => {
this._createWebSocket()
}, 2000)
}
private _destroyWebSocket(reconnect?: boolean): void {
if (!this.socket) return
this._stopHeartbeat()
if (this._reconnectingTimer) {
window.clearTimeout(this._reconnectingTimer)
}
this.socket.removeEventListener('open', this._onWsOpen)
this.socket.removeEventListener('message', this._onWsMessage)
this.socket.removeEventListener('close', this._onWsClose)
this.socket.removeEventListener('error', this._onWsError)
this.socket.close(1000)
this.socket = null
localStorage.removeItem('socket_connect')
useOrderStore().setSocketConnect('offline')
if (reconnect) this._scheduleReconnect()
}
private _createWebSocket(): void {
if (!this._wsUrl) return
const socket = new WebSocket(this._wsUrl)
socket.addEventListener('open', this._onWsOpen)
socket.addEventListener('message', this._onWsMessage)
socket.addEventListener('close', this._onWsClose)
socket.addEventListener('error', this._onWsError)
this.socket = socket
}
init(
options: InitOptions,
msgfunc?: MessageCallback,
openfunc?: OpenCallback,
): Promise<void> {
return new Promise((resolve, reject) => {
const { account, factoryNo } = options
const socket_connect = localStorage.getItem('socket_connect')
if (socket_connect === 'online') {
resolve()
return
}
if (!window.WebSocket) {
reject(new Error('WebSocket is not supported'))
return
}
this._onMessageCallback = msgfunc
this._onOpenCallback = () => {
openfunc?.()
resolve()
}
this._destroyWebSocket()
this._wsUrl = `${getWsUrl()}/ws/websocket/${factoryNo}/${account}`
this._createWebSocket()
})
}
send(options: WebSocketMessage): void {
this.socket?.send(JSON.stringify(options))
}
close(): void {
this._destroyWebSocket()
}
}
export default new Im()
......@@ -227,17 +227,18 @@ import {
PodMakeOrderData,
ProductList,
} from '@/types/api/podMakeOrder'
import useOrderStore from '@/store/order'
import useOrderStore from '@/store/cnOrder'
import {
getPackingCnDataApi,
clearBoxApi,
clearAllBoxApi,
getPackingDataApi,
getPodBoxListApi,
submitInspectionApi,
} from '@/api/podUsOrder'
} from '@/api/podCnOrder'
import useUserStore from '@/store/user'
import { Check } from '@element-plus/icons-vue'
import socket from '@/utils/websocket'
import socket from '@/utils/cnWebsocket'
import { WarehouseListData } from '@/types/api/podUsOrder'
const { getCLodop } = useLodop()
......@@ -272,7 +273,7 @@ const podOrderDetailsColumns = computed(() => [
},
{
label: '生产单号',
prop: 'podJomallUsNo',
prop: 'podJomallCnNo',
width: 150,
align: 'center',
},
......@@ -326,9 +327,17 @@ watch(visible, async (value: boolean) => {
if (value) {
podOrderDetailsData.value = {}
currentCode = ''
warehouseId.value = props.warehouseList[0].id
_warehouseId.value = props.warehouseList[0].id
// warehouseId.value = props.warehouseList[0].id
// _warehouseId.value = props.warehouseList[0].id
const locaclWarehouseId = sessionStorage.getItem('locaclCnWarehouseId')
// 设置仓库ID,优先使用本地存储的值,否则使用列表中的第一个仓库
warehouseId.value = locaclWarehouseId
? JSON.parse(locaclWarehouseId)
: props.warehouseList[0].id
_warehouseId.value = locaclWarehouseId
? JSON.parse(locaclWarehouseId)
: props.warehouseList[0].id
if (userStore.user?.factory.id) {
try {
await socket.init(
......@@ -367,6 +376,7 @@ watch(boxIndex, (value: number | null) => {
if (value) {
const bool = !boxChange.value
boxChange.value = false
console.log('boxChange', bool, value)
renderItemBox(bool)
}
})
......@@ -440,15 +450,14 @@ const renderItemBox = (bool: boolean) => {
if (currentCode) {
const parts = currentCode.split('_')
currentCode =
parts.length > 3 && parts[3].startsWith('USPSC')
parts.length > 3 && parts[3].startsWith('CNPSC')
? parts[3]
: parts.length > 1
? parts[1]
: parts[0]
for (const product of productList) {
if (product.podJomallUsNo === currentCode) {
if (product.podJomallCnNo === currentCode) {
coverImage.value = product.previewImgs?.[0]?.url || ''
console.log(441, coverImage.value)
nextTick(() => {
tableRef.value?.setCurrentRow(product)
......@@ -460,7 +469,6 @@ const renderItemBox = (bool: boolean) => {
}
podOrderDetailsData.value = data
if (productList.every((item) => item.power)) {
print(data, false, () => {
renderLock = false
......@@ -473,7 +481,7 @@ const messageChange = (data: WebSocketMessage) => {
if (!data) return
const { code, ...more } = data
if (code === 'POD_PRINT_ORDER') {
if (code === 'FACTORY_POD_CN_PRINT_ORDER') {
try {
if (typeof more.txt === 'string') {
console.log(
......@@ -571,7 +579,7 @@ const getPackingData = async (code: string) => {
productionOrder.value = ''
return
}
const res = await getPackingDataApi(
const res = await getPackingCnDataApi(
code,
factoryNo,
boxIndex.value,
......@@ -584,7 +592,6 @@ const getPackingData = async (code: string) => {
return
}
const { box } = res.data
console.log('box', box)
if (box) {
boxIndex.value = box
......@@ -748,6 +755,7 @@ const handleClose = (done: () => void) => {
})
}
const onClose = () => {
// orderStore.clearPodBox()
emit('refresh')
}
// 下一步
......
......@@ -2,7 +2,7 @@
<el-dialog
title="处理结果"
v-model="resultDialog"
width="600px"
width="60%"
:close-on-click-modal="false"
@closed="closedFn"
>
......@@ -128,6 +128,7 @@ const copyAllCode = (field: string) => {
function closedFn() {
if (key === 'stockOut') return
emits('confirm', selectedList.value)
}
// 监听弹窗状态
......
<script setup lang="ts">
import { defineModel } from 'vue'
import { updateAddressApi } from '@/api/podUsOrder.ts'
import {AddressInfo} from '@/types/api/podUsOrder.ts'
import { updateAddressApi } from '@/api/podCnOrder.ts'
import {AddressInfo} from '@/types/api/podCnOrder.ts'
const emits = defineEmits(['success'])
defineProps<{
......
......@@ -357,9 +357,17 @@ watch(visible, async (value: boolean) => {
if (value) {
podOrderDetailsData.value = {}
currentCode = ''
warehouseId.value = props.warehouseList[0].id
_warehouseId.value = props.warehouseList[0].id
// warehouseId.value = props.warehouseList[0].id
// _warehouseId.value = props.warehouseList[0].id
const locaclWarehouseId = localStorage.getItem('locaclWarehouseId')
// 设置仓库ID,优先使用本地存储的值,否则使用列表中的第一个仓库
warehouseId.value = locaclWarehouseId
? JSON.parse(locaclWarehouseId)
: props.warehouseList[0].id
_warehouseId.value = locaclWarehouseId
? JSON.parse(locaclWarehouseId)
: props.warehouseList[0].id
if (userStore.user?.factory.id) {
try {
await socket.init(
......@@ -382,9 +390,9 @@ watch(visible, async (value: boolean) => {
initOrderDetailBox()
initPrintDevice()
const locaclPrinter = localStorage.getItem('sheetPrinter')
const locaclWarehouseId = localStorage.getItem('locaclWarehouseId')
// const locaclWarehouseId = localStorage.getItem('locaclWarehouseId')
if (locaclPrinter) sheetPrinter.value = JSON.parse(locaclPrinter)
if (locaclWarehouseId) warehouseId.value = JSON.parse(locaclWarehouseId)
// if (locaclWarehouseId) warehouseId.value = JSON.parse(locaclWarehouseId)
} else {
if (userStore.user?.factory.id) {
socket.send({
......
......@@ -2014,6 +2014,7 @@
v-model="podOrderVisible"
:print-order="printOrder"
:warehouse-list="warehouseList"
:is-cn="false"
@set-printer="handlePrinterChange"
@set-warehouseId="handleWarehouseIdChange"
@refresh="onFastRefresh"
......
......@@ -27,10 +27,10 @@ export default defineConfig({
host: true,
proxy: {
'/api': {
target: 'http://10.168.31.130:8060',
target: 'http://10.168.31.193:8060',
},
'/ws': {
target: 'ws://wkg.local.cn:8066',
target: 'http://10.168.31.193:8060',
ws: true,
changeOrigin: true,
},
......
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