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

443 lines
11 KiB
TypeScript
Raw Normal View History

2025-12-26 17:26:32 +08:00
import { loginStatus, post } from "@/utils/https";
import {
formatTime,
getAuthInfo,
getDataSet,
isArray,
toArray,
toObject,
} from "@/utils/util";
2025-12-26 17:26:32 +08:00
import { voiceRequest } from "@/utils/voiceUtil";
/** 拼接符号 */
const ProcessCodeConcatSymbol = "&&";
/** 撤回码标记 */
const RecallCodeMarking = "-";
/**
*
* @param {string} value
*/
const parseQrCode = (value: string) => {
2025-12-26 17:26:32 +08:00
value = `${value || ""}`;
const obj = {
/** 工序码 */
code: value,
/** 提成自定义字段 */
key: "",
/** - => 撤回码 */
type: "",
};
if (value.includes(ProcessCodeConcatSymbol)) {
obj.code = value.substring(0, value.indexOf(ProcessCodeConcatSymbol));
obj.key = value.substring(
value.indexOf(ProcessCodeConcatSymbol) + ProcessCodeConcatSymbol.length
);
2025-12-26 17:26:32 +08:00
}
if (obj.code.includes(RecallCodeMarking)) {
obj.type = RecallCodeMarking;
obj.code = obj.code.replace(RecallCodeMarking, "");
}
return obj;
};
Page({
/**
*
*/
data: {
action: "end",
processCodeMsg: "",
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,
selectedProcessCode: "",
result: "",
logType: "0",
/** 默认提成 */
defaultBonus: true,
showDefaultBonus: false,
defaultBonusConfig: {},
defaultBonusConfigKeys: [] as string[],
2025-12-26 17:26:32 +08:00
rel_order_no_temp: "",
},
handleLogin(e: any) {
2025-12-26 17:26:32 +08:00
if (e.detail) {
this.setData({ isLogin: true, authInfo: getAuthInfo() });
this.init();
} else {
this.setData({ isLogin: false });
}
},
backChange(e: any) {
2025-12-26 17:26:32 +08:00
this.data.backFlag = e.detail;
this.setData({ backFlag: e.detail });
wx.setStorageSync("processBackFlag", e.detail ? 1 : 0);
if (this.data.selectedProcessCode) {
const { code, key } = parseQrCode(this.data.selectedProcessCode);
this.data.selectedProcessCode = `${code}${
e.detail ? RecallCodeMarking : ""
}`;
2025-12-26 17:26:32 +08:00
if (key) {
this.data.selectedProcessCode += `${ProcessCodeConcatSymbol}${key}`;
}
}
this.getProcessName();
},
getProcessName() {
if (this.data.selectedProcessCode) {
const { code, type } = parseQrCode(this.data.selectedProcessCode);
for (const ell of this.data.processItems) {
if (ell.code == code) {
this.setData({
processCodeMsg: `工序名称:${ell.name || ""}(${ell.code})`,
selectedProcessCode: this.data.selectedProcessCode,
process_code: this.data.selectedProcessCode,
action: type ? "back" : "end",
});
break;
}
}
}
},
processItemTap(e: any) {
this.data.selectedProcessCode =
e.currentTarget.dataset.code + (this.data.backFlag ? "-" : "");
2025-12-26 17:26:32 +08:00
wx.setStorageSync("selectedProcessCode", this.data.selectedProcessCode);
this.setData({
selectedProcessCode: this.data.selectedProcessCode,
});
this.getProcessName();
},
getExecProcess() {
post("Orders/getExecProcess1").then((res: any) => {
2025-12-26 17:26:32 +08:00
this.data.processItems = toArray(res.data);
if (this.data.processItems.length == 1) {
this.data.selectedProcessCode = this.data.processItems[0].code;
this.getProcessName();
} else {
this.getProcessName();
}
this.setData({
processItems: this.data.processItems,
});
});
},
init() {
const companyInfo = toObject(wx.getStorageSync("company_info"));
const code = wx.getStorageSync("selectedProcessCode") || "";
this.data.selectedProcessCode = code;
this.data.process_code = code;
this.data.backFlag = wx.getStorageSync("processBackFlag") == 1;
const logType = wx.getStorageSync("processEntry_logType");
this.setData({
hideTabKeys: companyInfo.staff_type == 3 ? ["2"] : [],
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,
});
wx.setStorageSync("processEntryVoice", `${event.detail}`);
},
getVoice(msg: string, cacheVoice?: boolean) {
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 });
wx.setStorageSync("processEntry_logType", data.key);
},
scanCode() {
this.data.isScanCode = true;
wx.scanCode({
onlyFromCamera: true,
scanType: ["qrCode"],
success: (res) => {
console.log(res);
const qrcode = res.result || "";
if (qrcode) {
if (qrcode.startsWith("DD") || qrcode.startsWith("LC")) {
if (this.data.process_code) {
this.data.rel_order_no = qrcode;
this.setData({
rel_order_no: qrcode,
});
this.processEnter();
} else {
wx.showToast({
title: "请扫流程码",
icon: "none",
});
}
} else {
const code = parseQrCode(qrcode);
this.setData({
action: code.type == RecallCodeMarking ? "back" : "end",
rel_order_no: "",
});
this.getProcess(qrcode);
}
}
this.setData({
msg: JSON.stringify(res),
});
},
complete: () => {
this.data.isScanCode = false;
},
});
},
getProcess(real_code: any) {
2025-12-26 17:26:32 +08:00
const code = parseQrCode(real_code);
post("CompanyProcess/processChildList", {
curr_page: 1,
page_count: 1,
real_code: code.code,
})
.then((res: any) => {
2025-12-26 17:26:32 +08:00
const data = res.data;
if (Array.isArray(res.data) && data.length) {
this.setData({
processCodeMsg: `工序名称:${data[0].name || ""}(${real_code})`,
process_code: real_code,
selectedProcessCode: real_code,
});
this.getVoice(`${data[0].name}工序`, true);
wx.showToast({
title: "请扫订单二维码",
icon: "none",
});
} else {
this.addMsg("未找到 " + real_code + " 工序");
wx.showToast({
title: "未找到该工序",
icon: "error",
});
this.getVoice(`未找到工序`, true);
}
})
.catch(() => {
2025-12-26 17:26:32 +08:00
this.addMsg("未找到 " + real_code + " 工序");
wx.showToast({
title: "未找到该工序",
icon: "error",
});
});
},
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];
this.data.rel_order_no_temp = item.rel_order_no;
this.setProcess();
},
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;
}
post("Orders/setProcess", {
param: JSON.stringify({
rel_order_no: this.data.rel_order_no_temp,
process_code: code.code,
action: this.data.action,
if_scan: 1,
same_process: this.data.rel_order_no_temp.startsWith("LC")
? 1
: undefined,
2025-12-26 17:26:32 +08:00
// defaultBonus: getDefaultBonus() != "0",
}),
other: JSON.stringify({ ...other, ...obj }),
})
.then((res: any) => {
2025-12-26 17:26:32 +08:00
if (res.bonus == 1) {
const data = toObject(res.data);
this.setData({
defaultBonusConfig: data,
defaultBonusConfigKeys: Object.keys(data),
showDefaultBonus: true,
});
} else 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) => {
return `${ell.room_name || "未命名"}(${
ell.goods_name || "未命名"
})`;
2025-12-26 17:26:32 +08:00
})
.join("");
el.sale_info_str = toArray(el.sale_info)
.map((ell) => {
return `${ell.goods_name}`;
})
.join("");
});
this.setData({
show: true,
orders: res.data,
});
} else {
this.addMsg(res.err_msg);
// this.getVoice(res.err_msg);
this.getVoice("通过");
this.setData({
show: false,
result: "success",
showDefaultBonus: false,
});
wx.showToast({
title: res.err_msg,
icon: "none",
});
}
})
.catch((res: any) => {
2025-12-26 17:26:32 +08:00
this.addMsg(res.err_msg);
if (res.err_code == "244269") {
this.setData({
result: "success",
});
wx.showToast({
title: res.err_msg,
icon: "none",
});
this.getVoice("通过");
} else {
this.setData({
result: "error",
});
this.getVoice(res.err_msg);
}
});
},
onSelectBonus(e: any) {
2025-12-26 17:26:32 +08:00
const data = getDataSet(e);
this.setProcess({ [data.order_no]: data.key });
},
closeDefaultBonusHandle() {
this.setData({
showDefaultBonus: false,
});
},
// defaultBonusChange(e) {
// this.setData({
// defaultBonus: e.detail ? "1" : "0",
// });
// setDefaultBonus(e.detail ? "1" : "0");
// },
addMsg(msg: any) {
2025-12-26 17:26:32 +08:00
const now = new Date();
this.data.logsList.unshift({
date: formatTime(now).substring(5),
msg: msg || "",
});
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,
voice: wx.getStorageSync("processEntryVoice") == "false" ? false : true,
});
loginStatus()
.then(() => {
2025-12-26 17:26:32 +08:00
this.setData({
isLogin: true,
loading: false,
authInfo: getAuthInfo(),
});
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log("调用登录状态请求失败", err);
});
},
/**
* --
*/
onReady() {},
/**
* --
*/
onShow() {
wx.hideHomeButton();
this.setData({
// defaultBonus: getDefaultBonus() != "0",
});
// if (!this.data.isScanCode) {
// }
},
/**
* --
*/
onHide() {},
/**
* --
*/
onUnload() {},
/**
* --
*/
onPullDownRefresh() {},
/**
*
*/
onReachBottom() {},
/**
*
*/
onShareAppMessage() {},
});