Files
FreeERP.Applet/miniprogram/pages/processEntry/processEntry.ts

383 lines
10 KiB
TypeScript
Raw Normal View History

2026-02-06 15:30:07 +08:00
import { loginStatusPage, post } from '@/utils/https';
2026-01-21 17:05:30 +08:00
import { formatTime, getAuthInfo, getDataSet, isArray, toArray, toObject } from '@/utils/util';
import { voiceRequest } from '@/utils/voiceUtil';
2025-12-26 17:26:32 +08:00
/** 拼接符号 */
2026-01-21 17:05:30 +08:00
const ProcessCodeConcatSymbol = '&&';
2025-12-26 17:26:32 +08:00
/** 撤回码标记 */
2026-01-21 17:05:30 +08:00
const RecallCodeMarking = '-';
2025-12-26 17:26:32 +08:00
/**
*
* @param {string} value
*/
const parseQrCode = (value: string) => {
2026-01-21 17:05:30 +08:00
value = `${value || ''}`;
2025-12-26 17:26:32 +08:00
const obj = {
/** 工序码 */
code: value,
/** 提成自定义字段 */
2026-01-21 17:05:30 +08:00
key: '',
2025-12-26 17:26:32 +08:00
/** - => 撤回码 */
2026-01-21 17:05:30 +08:00
type: '',
2025-12-26 17:26:32 +08:00
};
if (value.includes(ProcessCodeConcatSymbol)) {
obj.code = value.substring(0, value.indexOf(ProcessCodeConcatSymbol));
obj.key = value.substring(
2026-01-21 17:05:30 +08:00
value.indexOf(ProcessCodeConcatSymbol) + ProcessCodeConcatSymbol.length,
);
2025-12-26 17:26:32 +08:00
}
if (obj.code.includes(RecallCodeMarking)) {
obj.type = RecallCodeMarking;
2026-01-21 17:05:30 +08:00
obj.code = obj.code.replace(RecallCodeMarking, '');
2025-12-26 17:26:32 +08:00
}
return obj;
};
Page({
/**
*
*/
data: {
2026-01-21 17:05:30 +08:00
action: 'end',
processCodeMsg: '',
// rel_order_no: 'XSDD2026011500000190',
// process_code: 'jd',
rel_order_no: '',
process_code: '',
logsList: [] as any[],
2025-12-26 17:26:32 +08:00
show: false,
orders: [] as any[],
2025-12-26 17:26:32 +08:00
isLogin: false,
isScanCode: false,
voice: true,
loading: true,
authInfo: {},
hideTabKeys: [] as string[],
processItems: [] as any[],
2025-12-26 17:26:32 +08:00
backFlag: false,
2026-01-21 17:05:30 +08:00
selectedProcessCode: '',
result: '',
logType: '0',
rel_order_no_temp: '',
2025-12-26 17:26:32 +08:00
},
handleLogin(e: any) {
2026-01-21 17:05:30 +08:00
this.setData({ isLogin: e.detail });
2025-12-26 17:26:32 +08:00
if (e.detail) {
this.init();
}
},
backChange(e: any) {
2026-01-21 17:05:30 +08:00
const checked = e.detail.checked;
this.data.backFlag = checked;
this.setData({ backFlag: checked });
wx.setStorageSync('processBackFlag', checked ? 1 : 0);
2025-12-26 17:26:32 +08:00
if (this.data.selectedProcessCode) {
const { code, key } = parseQrCode(this.data.selectedProcessCode);
2026-01-21 17:05:30 +08:00
this.data.selectedProcessCode = `${code}${checked ? RecallCodeMarking : ''}`;
2025-12-26 17:26:32 +08:00
if (key) {
this.data.selectedProcessCode += `${ProcessCodeConcatSymbol}${key}`;
}
}
2026-01-21 17:05:30 +08:00
wx.setStorageSync('selectedProcessCode', this.data.selectedProcessCode);
2025-12-26 17:26:32 +08:00
this.getProcessName();
},
getProcessName() {
if (this.data.selectedProcessCode) {
const { code, type } = parseQrCode(this.data.selectedProcessCode);
for (const ell of this.data.processItems) {
2026-01-21 17:05:30 +08:00
if (ell.process_code == code) {
2025-12-26 17:26:32 +08:00
this.setData({
2026-01-21 17:05:30 +08:00
processCodeMsg: `工序名称:${ell.process_name || ''}(${ell.process_code})`,
2025-12-26 17:26:32 +08:00
selectedProcessCode: this.data.selectedProcessCode,
process_code: this.data.selectedProcessCode,
2026-01-21 17:05:30 +08:00
action: type ? 'back' : 'end',
2025-12-26 17:26:32 +08:00
});
break;
}
}
}
},
processItemTap(e: any) {
2026-01-21 17:05:30 +08:00
this.data.selectedProcessCode = e.currentTarget.dataset.code + (this.data.backFlag ? '-' : '');
wx.setStorageSync('selectedProcessCode', this.data.selectedProcessCode);
2025-12-26 17:26:32 +08:00
this.setData({
selectedProcessCode: this.data.selectedProcessCode,
});
2026-01-21 17:05:30 +08:00
2025-12-26 17:26:32 +08:00
this.getProcessName();
},
getExecProcess() {
2026-01-21 17:05:30 +08:00
post('CompanyProcessV2/getProcessByCode').then((res: any) => {
2025-12-26 17:26:32 +08:00
this.data.processItems = toArray(res.data);
if (this.data.processItems.length == 1) {
2026-01-21 17:05:30 +08:00
this.data.selectedProcessCode = this.data.processItems[0].process_code;
2025-12-26 17:26:32 +08:00
this.getProcessName();
} else {
this.getProcessName();
}
this.setData({
processItems: this.data.processItems,
});
});
},
init() {
2026-01-21 17:05:30 +08:00
const companyInfo = toObject(wx.getStorageSync('company_info'));
const code = wx.getStorageSync('selectedProcessCode') || '';
2025-12-26 17:26:32 +08:00
this.data.selectedProcessCode = code;
this.data.process_code = code;
2026-01-21 17:05:30 +08:00
this.data.backFlag = wx.getStorageSync('processBackFlag') == 1;
const logType = wx.getStorageSync('processEntry_logType');
2025-12-26 17:26:32 +08:00
this.setData({
2026-01-21 17:05:30 +08:00
authInfo: getAuthInfo(),
hideTabKeys: companyInfo.staff_type == 3 ? ['2'] : [],
2025-12-26 17:26:32 +08:00
backFlag: this.data.backFlag,
selectedProcessCode: code,
process_code: code,
logType: logType || 0,
});
this.getExecProcess();
},
voiceChange(event: any) {
2025-12-26 17:26:32 +08:00
this.setData({
voice: event.detail,
});
2026-01-21 17:05:30 +08:00
wx.setStorageSync('processEntryVoice', `${event.detail}`);
2025-12-26 17:26:32 +08:00
},
getVoice(msg: string, cacheVoice?: boolean) {
2026-01-21 17:05:30 +08:00
return;
2025-12-26 17:26:32 +08:00
if (this.data.voice && msg) {
voiceRequest(msg, cacheVoice);
}
},
onLogTypeChange(e: any) {
2025-12-26 17:26:32 +08:00
const data = getDataSet(e);
this.setData({ logType: data.key });
2026-01-21 17:05:30 +08:00
wx.setStorageSync('processEntry_logType', data.key);
2025-12-26 17:26:32 +08:00
},
scanCode() {
this.data.isScanCode = true;
wx.scanCode({
onlyFromCamera: true,
2026-01-21 17:05:30 +08:00
scanType: ['qrCode'],
2025-12-26 17:26:32 +08:00
success: (res) => {
console.log(res);
2026-01-21 17:05:30 +08:00
const qrcode = res.result || '';
2025-12-26 17:26:32 +08:00
if (qrcode) {
2026-01-21 17:05:30 +08:00
if (qrcode.startsWith('XSDD')) {
2025-12-26 17:26:32 +08:00
if (this.data.process_code) {
this.data.rel_order_no = qrcode;
this.setData({
rel_order_no: qrcode,
});
this.processEnter();
} else {
2026-01-21 17:05:30 +08:00
wx.showToast({ title: '请扫流程码', icon: 'none' });
2025-12-26 17:26:32 +08:00
}
} else {
const code = parseQrCode(qrcode);
this.setData({
2026-01-21 17:05:30 +08:00
action: code.type == RecallCodeMarking ? 'back' : 'end',
rel_order_no: '',
2025-12-26 17:26:32 +08:00
});
this.getProcess(qrcode);
}
}
this.setData({
msg: JSON.stringify(res),
});
},
complete: () => {
this.data.isScanCode = false;
},
});
},
2026-01-21 17:05:30 +08:00
getProcess(process_code: any) {
const code = parseQrCode(process_code);
post('/CompanyProcessV2/getProcessByCode', {
2025-12-26 17:26:32 +08:00
curr_page: 1,
page_count: 1,
2026-01-21 17:05:30 +08:00
process_code: code.code,
2025-12-26 17:26:32 +08:00
})
.then((res: any) => {
2025-12-26 17:26:32 +08:00
const data = res.data;
if (Array.isArray(res.data) && data.length) {
this.setData({
2026-01-21 17:05:30 +08:00
processCodeMsg: `工序名称:${data[0].process_name || ''}(${process_code})`,
process_code: process_code,
selectedProcessCode: process_code,
2025-12-26 17:26:32 +08:00
});
2026-01-21 17:05:30 +08:00
this.getVoice(`${data[0].process_name}工序`, true);
wx.showToast({ title: '请扫订单二维码', icon: 'none' });
2025-12-26 17:26:32 +08:00
} else {
2026-01-21 17:05:30 +08:00
this.addMsg('未找到 ' + process_code + ' 工序');
wx.showToast({ title: '未找到该工序', icon: 'error' });
2025-12-26 17:26:32 +08:00
this.getVoice(`未找到工序`, true);
}
})
.catch(() => {
2026-01-21 17:05:30 +08:00
this.addMsg('未找到 ' + process_code + ' 工序');
wx.showToast({ title: '未找到该工序', icon: 'error' });
2025-12-26 17:26:32 +08:00
});
},
processEnter() {
if (this.data.rel_order_no && this.data.process_code) {
this.data.rel_order_no_temp = this.data.rel_order_no;
this.setProcess();
}
},
LCProcessEnter(e: any) {
2025-12-26 17:26:32 +08:00
const item = this.data.orders[e.currentTarget.dataset.index];
2026-01-21 17:05:30 +08:00
this.data.rel_order_no_temp = item.order_no;
this.setProcess({
info_process_id: JSON.stringify([item.info_process_id]),
action: this.data.action,
if_scan: 1,
});
2025-12-26 17:26:32 +08:00
},
setProcess(other?: any) {
2025-12-26 17:26:32 +08:00
const code = parseQrCode(this.data.process_code);
const obj: any = {};
2025-12-26 17:26:32 +08:00
if (code.key) {
obj[this.data.rel_order_no_temp] = code.key;
}
2026-01-21 17:05:30 +08:00
post(
'ProduceOrder/setProcessV2',
other
? other
: {
order_no: this.data.rel_order_no_temp,
process_code: code.code,
action: this.data.action,
if_scan: 1,
},
)
.then((res: any) => {
2026-01-21 17:05:30 +08:00
if (isArray(res.data) && res.data.length) {
res.data.forEach((el: any) => {
2025-12-26 17:26:32 +08:00
el.product_info_str = toArray(el.product_info)
.map((ell) => {
2026-01-21 17:05:30 +08:00
return `${ell.room_name || '未命名'}(${ell.goods_name || '未命名'})`;
2025-12-26 17:26:32 +08:00
})
2026-01-21 17:05:30 +08:00
.join('');
2025-12-26 17:26:32 +08:00
el.sale_info_str = toArray(el.sale_info)
.map((ell) => {
return `${ell.goods_name}`;
})
2026-01-21 17:05:30 +08:00
.join('');
2025-12-26 17:26:32 +08:00
});
this.setData({
show: true,
orders: res.data,
});
} else {
this.addMsg(res.err_msg);
// this.getVoice(res.err_msg);
2026-01-21 17:05:30 +08:00
this.getVoice('通过');
2025-12-26 17:26:32 +08:00
this.setData({
show: false,
2026-01-21 17:05:30 +08:00
result: 'success',
2025-12-26 17:26:32 +08:00
});
wx.showToast({
title: res.err_msg,
2026-01-21 17:05:30 +08:00
icon: 'none',
2025-12-26 17:26:32 +08:00
});
}
})
.catch((res: any) => {
2025-12-26 17:26:32 +08:00
this.addMsg(res.err_msg);
2026-01-21 17:05:30 +08:00
if (res.err_code == '244269') {
2025-12-26 17:26:32 +08:00
this.setData({
2026-01-21 17:05:30 +08:00
result: 'success',
2025-12-26 17:26:32 +08:00
});
wx.showToast({
title: res.err_msg,
2026-01-21 17:05:30 +08:00
icon: 'none',
2025-12-26 17:26:32 +08:00
});
2026-01-21 17:05:30 +08:00
this.getVoice('通过');
2025-12-26 17:26:32 +08:00
} else {
this.setData({
2026-01-21 17:05:30 +08:00
result: 'error',
2025-12-26 17:26:32 +08:00
});
this.getVoice(res.err_msg);
}
});
},
2026-01-21 17:05:30 +08:00
addMsg(msg: any) {
2025-12-26 17:26:32 +08:00
const now = new Date();
this.data.logsList.unshift({
date: formatTime(now).substring(5),
2026-01-21 17:05:30 +08:00
msg: msg || '',
2025-12-26 17:26:32 +08:00
});
if (this.data.logsList.length > 100) {
this.data.logsList.length = 100;
}
this.setData({
logsList: this.data.logsList,
});
},
clearMsg() {
this.setData({ logsList: [] });
2025-12-26 17:26:32 +08:00
},
show() {
this.setData({ show: true });
2025-12-26 17:26:32 +08:00
},
onClose() {
this.setData({ show: false });
2025-12-26 17:26:32 +08:00
},
/**
* --
*/
onLoad(_options) {
2025-12-26 17:26:32 +08:00
this.setData({
loading: true,
2026-01-21 17:05:30 +08:00
voice: wx.getStorageSync('processEntryVoice') == 'false' ? false : true,
2025-12-26 17:26:32 +08:00
});
2026-02-06 15:30:07 +08:00
loginStatusPage(this);
2025-12-26 17:26:32 +08:00
},
/**
* --
*/
onReady() {},
/**
* --
*/
onShow() {
wx.hideHomeButton();
},
/**
* --
*/
onHide() {},
/**
* --
*/
onUnload() {},
/**
* --
*/
onPullDownRefresh() {},
/**
*
*/
onReachBottom() {},
/**
*
*/
onShareAppMessage() {},
});