|
|
@@ -399,6 +399,191 @@ $(function () {
|
|
|
drugBarStat();
|
|
|
});
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ // 测试箱子码功能
|
|
|
+ $("#testBoxCode").click(function () {
|
|
|
+ // 使用测试箱子码
|
|
|
+ let testBoxCode = "86049630001501940064";
|
|
|
+ getTraceCodesByBoxCode(testBoxCode);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 箱子码输入框功能
|
|
|
+ let boxCodeInputTimer = null;
|
|
|
+
|
|
|
+ // 弹框打开时自动获取焦点
|
|
|
+ $("#barListModal").on('shown.bs.modal', function () {
|
|
|
+ setTimeout(function() {
|
|
|
+ $("#boxCodeInput").focus();
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 箱子码输入框防抖处理
|
|
|
+ $("#boxCodeInput").on('input', function() {
|
|
|
+ let boxCode = $(this).val();
|
|
|
+
|
|
|
+ // 清除之前的定时器
|
|
|
+ if (boxCodeInputTimer) {
|
|
|
+ clearTimeout(boxCodeInputTimer);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果输入框有值,设置0.5秒防抖
|
|
|
+ if (boxCode && boxCode.trim() !== '') {
|
|
|
+ boxCodeInputTimer = setTimeout(function() {
|
|
|
+ getTraceCodesByBoxCode(boxCode);
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 手动触发按钮
|
|
|
+ $("#manualTriggerBoxCode").click(function() {
|
|
|
+ let boxCode = $("#boxCodeInput").val();
|
|
|
+ if (!boxCode || boxCode.trim() === '') {
|
|
|
+ errorMesageSimaple("请输入箱子码!");
|
|
|
+ $("#boxCodeInput").focus();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清除防抖定时器
|
|
|
+ if (boxCodeInputTimer) {
|
|
|
+ clearTimeout(boxCodeInputTimer);
|
|
|
+ }
|
|
|
+
|
|
|
+ getTraceCodesByBoxCode(boxCode);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 回车键触发
|
|
|
+ $("#boxCodeInput").on('keypress', function(e) {
|
|
|
+ if (e.which === 13) { // 回车键
|
|
|
+ e.preventDefault();
|
|
|
+ $("#manualTriggerBoxCode").click();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 根据箱子码获取追溯码的函数
|
|
|
+ function getTraceCodesByBoxCode(boxCode) {
|
|
|
+ // 显示加载提示
|
|
|
+ showLoading("正在获取追溯码...");
|
|
|
+
|
|
|
+ // 调用接口
|
|
|
+ request({
|
|
|
+ url: '/Taobao/getCodeByParent',
|
|
|
+ method: 'GET',
|
|
|
+ data: { parentCode: boxCode }
|
|
|
+ }).then((res) => {
|
|
|
+ hideLoading();
|
|
|
+
|
|
|
+ if (res && res.code === 200) {
|
|
|
+ // 根据接口返回的数据结构,传递整个响应数据
|
|
|
+ processTraceCodes(res);
|
|
|
+ } else {
|
|
|
+ errorMesageSimaple("获取追溯码失败:" + (res.message || "未知错误"));
|
|
|
+ }
|
|
|
+ }).catch((error) => {
|
|
|
+ hideLoading();
|
|
|
+
|
|
|
+ // 检查是否是成功的响应被当作错误处理了
|
|
|
+ if (error && error.code === 200) {
|
|
|
+ processTraceCodes(error);
|
|
|
+ } else {
|
|
|
+ errorMesageSimaple("获取追溯码失败:" + (error.message || "未知错误"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理追溯码数据的函数
|
|
|
+ function processTraceCodes(traceCodesData) {
|
|
|
+ let currentTraceCodes = $("#drugTracCodgStr").val();
|
|
|
+ let newTraceCodes = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 根据接口返回的数据结构,提取 data.data[0].codeRelationList 中的 code 值
|
|
|
+ if (traceCodesData && traceCodesData.data && traceCodesData.data.data && Array.isArray(traceCodesData.data.data) && traceCodesData.data.data.length > 0) {
|
|
|
+ let firstDataItem = traceCodesData.data.data[0];
|
|
|
+
|
|
|
+ if (firstDataItem && firstDataItem.codeRelationList && Array.isArray(firstDataItem.codeRelationList)) {
|
|
|
+ // 提取 codeRelationList 数组中每一项的 code 值
|
|
|
+ let codeList = firstDataItem.codeRelationList.map(function(item) {
|
|
|
+ return item.code;
|
|
|
+ }).filter(function(code) {
|
|
|
+ return code && code.trim() !== '';
|
|
|
+ });
|
|
|
+
|
|
|
+ // 将提取的 code 值用换行符连接
|
|
|
+ newTraceCodes = codeList.join('\n');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有找到正确的数据结构,尝试其他格式
|
|
|
+ if (!newTraceCodes) {
|
|
|
+ if (Array.isArray(traceCodesData)) {
|
|
|
+ // 如果是数组格式
|
|
|
+ newTraceCodes = traceCodesData.join('\n');
|
|
|
+ } else if (typeof traceCodesData === 'string') {
|
|
|
+ // 如果是字符串格式,按逗号或换行分割
|
|
|
+ newTraceCodes = traceCodesData.replace(/[,,]/g, '\n');
|
|
|
+ } else if (traceCodesData && typeof traceCodesData === 'object') {
|
|
|
+ // 如果是对象格式,尝试提取追溯码字段
|
|
|
+ if (traceCodesData.traceCodes) {
|
|
|
+ newTraceCodes = Array.isArray(traceCodesData.traceCodes) ?
|
|
|
+ traceCodesData.traceCodes.join('\n') :
|
|
|
+ traceCodesData.traceCodes;
|
|
|
+ } else if (traceCodesData.data) {
|
|
|
+ newTraceCodes = Array.isArray(traceCodesData.data) ?
|
|
|
+ traceCodesData.data.join('\n') :
|
|
|
+ traceCodesData.data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并到现有追溯码中
|
|
|
+ if (currentTraceCodes && currentTraceCodes.trim() !== '') {
|
|
|
+ // 如果已有追溯码,在末尾添加新的
|
|
|
+ $("#drugTracCodgStr").val(currentTraceCodes + '\n' + newTraceCodes);
|
|
|
+ } else {
|
|
|
+ // 如果没有追溯码,直接设置
|
|
|
+ $("#drugTracCodgStr").val(newTraceCodes);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自动触发追溯码检查
|
|
|
+ drugBarStat();
|
|
|
+
|
|
|
+ // 显示成功消息
|
|
|
+ if (newTraceCodes) {
|
|
|
+ let codeCount = newTraceCodes.split('\n').length;
|
|
|
+ successMesage("成功获取 " + codeCount + " 个追溯码!");
|
|
|
+ } else {
|
|
|
+ errorMesageSimaple("未找到有效的追溯码数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ console.error("处理追溯码数据时出错:", error);
|
|
|
+ errorMesageSimaple("处理追溯码数据时出错:" + error.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 显示加载提示的函数
|
|
|
+ function showLoading(message) {
|
|
|
+ // 如果页面有loading组件,使用现有的
|
|
|
+ if (typeof showLoadingMessage === 'function') {
|
|
|
+ showLoadingMessage(message);
|
|
|
+ } else {
|
|
|
+ // 简单的loading提示
|
|
|
+ console.log(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 隐藏加载提示的函数
|
|
|
+ function hideLoading() {
|
|
|
+ // 如果页面有loading组件,使用现有的
|
|
|
+ if (typeof hideLoadingMessage === 'function') {
|
|
|
+ hideLoadingMessage();
|
|
|
+ } else {
|
|
|
+ // 简单的loading提示
|
|
|
+ console.log("加载完成");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
});
|
|
|
|
|
|
/**
|