/** * 入库通用工具方法 */ /** * 显示操作确认模态框 * @param {string} title - 标题 * @param {string} content - 内容 * @param {boolean} showCancel - 是否显示取消按钮 * @returns {Promise} Promise对象 */ export function showOperationConfirm(title, content, showCancel = true) { return new Promise((resolve) => { uni.showModal({ title: title || '提示', content: content || '', showCancel: showCancel, cancelText: '取消', confirmText: '确定', success: function(res) { resolve(res); } }); }); } /** * 检查是否为重复箱 * @param {Array} list - 箱子列表 * @param {string} patchCode - 批次号 * @returns {boolean} 是否重复 */ export function isRepeatPackage(list, patchCode) { if (!list || list.length === 0) return false; for (let item of list) { if (item.patchCode === patchCode) { return true; } } return false; } /** * 检查是否更换了批次 * @param {Array} list - 箱子列表 * @param {string} productionTime - 批次时间 * @returns {boolean} 是否更换批次 */ export function isChangeBatch(list, productionTime) { if (!list || list.length === 0) return false; const lastItem = list[list.length - 1]; return lastItem.productionTime !== productionTime; } /** * 检查是否为重复箱(基于originalCode) * @param {Array} list - 箱子列表 * @param {string} originalCode - 原始编码 * @returns {boolean} 是否重复 */ export function isRepeatPackageByCode(list, originalCode) { if (!list || list.length === 0) return false; for (let item of list) { if (item.originalCode === originalCode) { return true; } } return false; } /** * 清除重复箱 * @param {Array} list - 箱子列表 * @returns {Array} 清除重复后的列表和重复箱信息 */ export function clearRepeatPackages(list) { let newArray = []; let seen = new Map(); let repeatPackage = []; list.forEach((item) => { if (!seen.has(item.originalCode)) { seen.set(item.originalCode, true); newArray.push(item); } else { repeatPackage.push(item.patchCode); } }); return { clearedList: newArray, repeatPackages: repeatPackage }; } /** * 防抖函数 * @param {Function} func - 要防抖的函数 * @param {number} delay - 延迟时间(ms) * @returns {Function} 防抖后的函数 */ export function debounce(func, delay) { let timeoutId; return function (...args) { // 清除之前的定时器 if (timeoutId) { clearTimeout(timeoutId); } // 设置新的定时器 timeoutId = setTimeout(() => { func.apply(this, args); }, delay); }; }