let maxPageSize = 1000; export { maxPageSize } import { calc } from '@/common/calc' let jobStatusList = []; let itemStatusList = []; let locationAreaTypeList = []; let uomList = []; let inventoryStatusList = []; let containerTypeList = []; let packUnitList = []; let requestStatusList = []; let unplannedReceiptReasonList = []; let unplannedIissueReason = []; let scrapReasonList = []; let inspectFailedReasonList = []; let switchList = [] let businessList = [] //获取字典信息 export function clearCacheData() { jobStatusList = []; itemStatusList = []; locationAreaTypeList = []; uomList = []; inventoryStatusList = []; containerTypeList = []; packUnitList = []; requestStatusList = []; unplannedReceiptReasonList = []; unplannedIissueReason = []; scrapReasonList = []; inspectFailedReasonList = []; switchList = [] businessList = [] } //获取字典信息 export function getDirectoryInfo(type) { var result = []; var list = uni.getStorageSync("dictionary") if (list != undefined && list.length > 0) { for (let item of list) { if (item.type == type) { result = item.subList break; } } } return result } //将字典项转为数组 export function getDirectoryItemArray(data) { var array = [] if (data == undefined || data == null || data == "") { return array } if (data.indexOf(',') < 0) { array.push(data) } else { var arrayItems = data.split(',') arrayItems.forEach(res => { array.push(res) }) } return array } //查询字典项是否在列表中 export function checkDirectoryItemExist(list, type) { let exist = false; if (list == null || list.length == 0) { exist = true; } else { var temp = list.filter(res => { if (res == type) { return res } }) if (temp != undefined && temp.length > 0) { exist = true } } return exist } //获取任务状态 export function getJobStateInfo(value) { var resultInfo = ""; if (jobStatusList.length == 0) { jobStatusList = getDirectoryInfo("job_status") } if (jobStatusList.length > 0) { for (let item of jobStatusList) { if (item.value == value) { resultInfo = item break; } } } return resultInfo } //获取任务状态样式 export function getJobStateStyle(value) { let item = getJobStateInfo(value); if (item == null || item == '') { return 'other' } else { if (item.remark == '') { return 'other' } else { return item.remark; } } } //获取库位描述 export function getListLocationTypeDesc(lst) { let desc = ''; lst.forEach(res => { desc += getLocationTypeInfo(res).label + "," }) desc = desc.slice(0, -1); return desc; } //获取物品状态 export function getItemStateInfo(value) { var resultInfo = ""; if (itemStatusList.length == 0) { itemStatusList = getDirectoryInfo("item_status") } if (itemStatusList.length > 0) { for (let item of itemStatusList) { if (item.value == value) { resultInfo = item break; } } } return resultInfo } //获取库位类型 export function getLocationTypeInfo(value) { var resultInfo = ""; if (locationAreaTypeList.length == 0) { locationAreaTypeList = getDirectoryInfo("location_type") } if (locationAreaTypeList.length > 0) { for (let item of locationAreaTypeList) { if (item.value == value) { resultInfo = item break; } } } return resultInfo } //获取库位类型名称 export function getLocationTypeName(value) { let location = getLocationTypeInfo(value); return location == '' ? value : location.label; } //获取计量单位 export function getUomInfo(value) { var resultInfo = ""; if (uomList.length == 0) { uomList = getDirectoryInfo("uom") } if (uomList.length > 0) { for (let item of uomList) { if (item.value == value) { resultInfo = item break; } } } return resultInfo } //获取包装单位 export function getPackUnitInfo(value) { var resultInfo = ""; if (packUnitList.length == 0) { packUnitList = getDirectoryInfo("pack_unit") } if (packUnitList.length > 0) { for (let item of packUnitList) { if (item.value == value) { resultInfo = item break; } } } return resultInfo } //获取申请状态 export function getRequestStateInfo(value) { var resultInfo = ""; if (requestStatusList.length == 0) { requestStatusList = getDirectoryInfo("request_status") } if (requestStatusList.length > 0) { for (let item of requestStatusList) { if (item.value == value) { resultInfo = item break; } } } return resultInfo } //获取库存状态 export function getInventoryStatusInfo(value) { var resultInfo = ""; if (inventoryStatusList.length == 0) { inventoryStatusList = getDirectoryInfo("inventory_status") } if (inventoryStatusList.length > 0) { for (let item of inventoryStatusList) { if (item.value == value) { resultInfo = item break; } } } return resultInfo } //获取库存样式 export function getInventoryStatusStyle(value) { let item = getInventoryStatusInfo(value); if (item == null || item == '') { return 'other' } else { if (item.remark == '') { return 'other' } else { return item.remark; } } } //获取库存状态 export function getInventoryStatusName(value) { let item = getInventoryStatusInfo(value); if (item == null || item == '') { return value } else { if (item.label == '') { return value } else { return item.label; } } } //获取状态描述 export function getInventoryStatusDesc(lst) { let desc = ''; lst.forEach(res => { desc += getInventoryStatusInfo(res).label + "," }) desc = desc.slice(0, -1); return desc; } //获取器具状态 export function getContainerStatusInfo(value) { var resultInfo = ""; if (containerTypeList.length == 0) { containerTypeList = getDirectoryInfo("container_type") } if (containerTypeList.length > 0) { for (let item of containerTypeList) { if (item.value == value) { resultInfo = item break; } } } return resultInfo } //获取计划外入库原因 export function getUnPlannedReceiptReasonList(value) { if (unplannedReceiptReasonList.length == 0) { unplannedReceiptReasonList = getDirectoryInfo("unplanned_receipt_reason") } unplannedReceiptReasonList.forEach(res => { res.text = res.label; res.value = res.code }) return unplannedReceiptReasonList } //获取计划外出库原因 export function getUnPlannedIssuseReasonList(value) { if (unplannedIissueReason.length == 0) { unplannedIissueReason = getDirectoryInfo("unplanned_issue_reason") } unplannedIissueReason.forEach(res => { res.text = res.label; res.value = res.code }) return unplannedIissueReason } //获取检验不合格原因 export function getInspectReasonList(value) { if (inspectFailedReasonList.length == 0) { inspectFailedReasonList = getDirectoryInfo("inspect_failed_reason") } inspectFailedReasonList.forEach(res => { res.text = res.label; res.value = res.code }) return inspectFailedReasonList } //获取单据开关 export function getSwitchInfoByCode(code) { var isCheck = false var resultInfo = "" switchList = uni.getStorageSync("switch") for (let item of switchList) { if (item.code == code) { resultInfo = item break; } } isCheck = resultInfo.effectiveSetValue == "TRUE" ? true : false return isCheck; } //获取业务类型名称 export function getBusinessTypeName(code) { var resultInfo = null if (businessList.length == 0) { businessList = uni.getStorageSync("businessType") } for (let item of businessList) { if (item.code == code) { resultInfo = item break; } } return resultInfo.name; } // //数量状态 // export function getCoutJobStatuStyle(val) { // if (val == 1) return 'state_inspect' // else if (val == 2) return 'state_ok' // else if (val == 3) return 'state_nook' // else return 'other' // } // export function getCountJobStatuDesc(val) { // if (val == 1) return '待检' // else if (val == 2) return '合格' // else if (val == 3) return '不合格' // else return "未知" // } // export function getPartCodeState(val) { // if (val == 0) return '可用' // else if (val == 1) return '新增' // else if (val == 2) return '隔离' // else if (val == 3) return '未知' // else return '未知' // } // export function getLocationState(val) { // if (val == 'kwlxINSP') return '待检库' // else if (val == 'kwlxRAW') return '原料库' // else if (val == 'kwlxSEMI') return '半成品库' // else if (val == 'kwlxFG') return '成品库' // else if (val == 'kwlxWIP') return '线边库' // else if (val == 'kwlxHOLD') return '隔离库' // else if (val == 'kwlxSCRAP') return '报废库' // else if (val == 'kwlxNOK') return '不合格品库' // else if (val == 'kwxOVERFLOW') return '溢出库' // else if (val == 'kwlxCUsT') return '客户寄售库' // else if (val == 'kwlxOUTSIDE') return '外库' // else if (val == 'kwlxDIFF') return '盘点差异库' // else if (val == 'kwxTRANSPORT') return '在途库' // else return '未知' // } // export function getLocationStyle(val) { // if (val == 'kwlxRAW') return 'state_raw' // else if (val == 'kwlxFG') return 'state_fg' // else if (val == 'kwlxSEMI') return 'state_semi' // else if (val == 'kwlxHOLD') return 'state_hold' // else if (val == 4) return 'state_unk' // } // //任务状态 // export function getJobStatuStyle(val) { // if (val == 'JOB_PENDING') return 'job_state_un-doing' // else if (val == '1') return 'job_state_doing' // else if (val == 'reztDONE') return 'job_state_completed' // else if (val == 'rwztCLOSED') return 'job_state_close' // else if (val == 'rwztCANCELLED') return 'job_state_cancelled' // else return 'unk' // } // //任务状态 // //open pending completed close // export function getJobStatuDesc(val) { // if (val == 'JOB_PENDING') return '待处理' // else if (val == '1') return '执行中' // else if (val == 'reztDONE') return '完成' // else if (val == 'rwztCLOSED') return '关闭' // else if (val == 'rwztCANCELLED') return '作废' // else return '其他' // } // //检验任务状态 // export function getInspectTypeStyle(val) { // if (val == 0) return 'unk' // else if (val == 1) return 'exempt' // else if (val == 2) return 'full' // else if (val == 3) return 'sampling' // else if (val == 4) return 'pick' // else return 'other' // } // //open pending completed close // export function getInspectTypeDesc(val) { // if (val == 0) return '未知' // else if (val == 1) return '免检' // else if (val == 2) return '全检' // else if (val == 3) return '抽检' // else if (val == 4) return '挑选' // else return '其他' // } // //库存状态 // export function getInventoryStatusStyle(val) { // if (val == 'kcztUNK') return 'unk' // else if (val == 'kcztINSP') return 'inventory_status_insp' // else if (val == 'kcztOK') return 'inventory_status_ok' // else if (val == 'kcztNOK') return 'inventory_status_nok' // else if (val == 'kcztHOLD') return 'inventory_status_hold' // else if (val == 'kcztSCRAP') return 'inventory_status_scarp' // else return 'other' // } // //库存状态 // export function getInventoryStatusDesc(val) { // if (val == 'kcztUNK') return '未知' // else if (val == 'kcztINSP') return '待检' // else if (val == 'kcztOK') return '合格' // else if (val == 'kcztNOK') return '不合格' // else if (val == 'kcztHOLD') return '隔离' // else if (val == 'kcztSCRAP') return '报废' // else return '其他' // } // //库存状态 // export function getInventoryStatusStyle(val) { // if (val == 0) return 'unk' // else if (val == 1) return 'insp' // else if (val == 2) return 'ok' // else if (val == 3) return 'nok' // else if (val == 4) return 'hold' // else if (val == 5) return 'scarp' // else if (val == 6) return 'frozen' // else if (val == 31) return 'nok' // else return 'other' // } // //库存状态kcztINSP // export function getInventoryStatusDesc(val) { // if (val == 0) return '未知' // else if (val == 1) return '待检' // else if (val == 2) return '合格' // else if (val == 3) return '不合格' // else if (val == 4) return '隔离' // else if (val == 5) return '报废' // else if (val == 6) return '冻结' // else if (val == 31) return '不合格' // // else if (val == 31) return '目检不合格' // else return '其他' // } // //物料状态 // export function getItemStatusStyle(val) { // if (val == "wpztUNK") return 'item_unk' // else if (val == "wpztENABLE") return 'item_active' // else if (val == "wpztHOLD") return 'item_hold' // else if (val == "wpztNEW") return 'item_new' // else if (val == "wpztPLAN") return 'item_plan' // else if (val == "wpztDISABLE") return 'item_disable' // else return 'other' // } // export function getItemStatusStyle(val) { // if (val == 0) return 'unk_item' // else if (val == 1) return 'active_item' // else if (val == 2) return 'hold_item' // else if (val == 3) return 'new_item' // else if (val == 4) return 'plan_item' // else if (val == 5) return 'disable_item' // else return 'other' // } // //物料状态描述 // export function getItemStatusDesc(val) { // if (val == "wpztUNK") return '未知' // else if (val == "wpztENABLE") return '可用' // else if (val == "wpztHOLD") return '隔离' // else if (val == "wpztNEW") return '新增' // else if (val == "wpztPLAN") return '规划' // else if (val == "wpztDISABLE") return '禁用' // else return '其他' // } // //盘点状态 // export function getCountStageTypeStyle(val) { // if (val == 0) return 'unk' // else if (val == 1) return 'initial' // else if (val == 2) return 'afresh' // else if (val == 3) return 'supervision' // else return 'other' // } // //盘点状态 // export function getCountStageDesc(val) { // if (val == 0) return '未知' // else if (val == 1) return '初盘' // else if (val == 2) return '重盘' // else if (val == 3) return '监盘' // else return '其他' // } // //盘点计划类型 // export function getCheckTypeDesc(val) { // if (val == 0) return '未知' // else if (val == 1) return '周期盘点' // else if (val == 2) return '物理盘点' // else return '其他' // } // //盘点方式 // export function getCountMethodDesc(val) { // if (val == 0) return '未知' // else if (val == 1) return '库位盘点' // else if (val == 2) return '物品盘点' // else if (val == 3) return '库位物料盘点' // else return '其他' // } // //获取库位类型 // export function getLocationType(val) { // if (val == 'kwlxINSP') return 'location_inspect' // else if (val == 'kwlxRAW') return 'location_raw' // else if (val == 'kwlxSEMI') return 'location_semi' // else if (val == 'kwlxFG') return 'location_fg' // else if (val == 'kwlxWIP') return 'location_wip' // else if (val == 'kwlxHOLD') return 'location_hold' // else if (val == 'kwlxSCRAP') return 'location_scrap' // else if (val == 'kwlxNOK') return 'location_nok' // else if (val == 'kwxOVERFLOW') return 'location_overflow' // else if (val == 'kwlxCUsT') return 'location_cust' // else if (val == 'kwlxOUTSIDE') return 'location_outside' // else if (val == 'kwlxDIFF') return 'location_diff' // else if (val == 'kwxTRANSPORT') return 'location_transport' // else return 'location_other' // } // //获取库位类型描述 // export function getLocationTypeDesc(val) { // if (val == 'kwlxINSP') return '待检库' // else if (val == 'kwlxRAW') return '原料库' // else if (val == 'kwlxSEMI') return '半成品库' // else if (val == 'kwlxFG') return '成品库' // else if (val == 'kwlxWIP') return '线边库' // else if (val == 'kwlxHOLD') return '隔离库' // else if (val == 'kwlxSCRAP') return '报废库' // else if (val == 'kwlxNOK') return '不合格品库' // else if (val == 'kwxOVERFLOW') return '溢出库' // else if (val == 'kwlxCUsT') return '客户寄售库' // else if (val == 'kwlxOUTSIDE') return '外库' // else if (val == 'kwlxDIFF') return '盘点差异库' // else if (val == 'kwxTRANSPORT') return '在途库' // else return '其他' // } // //获取任务类型描述 // export function getJobType(val) { // if (val == 0) return 'uno' // else if (val == 1) return 'PurchaseReceiptJob' //采购收货 // else if (val == 2) return 'PurchaseReturnJob' //采购退货任务 // else if (val == 3) return 'InspectJob' //检验任务 // else if (val == 4) return 'PutawayJob' //上架任务 // else if (val == 5) return 'ProductReceiveJob' //完工收货任务 // else if (val == 6) return 'IssueJob' //发料任务 // else if (val == 7) return 'DeliverJob' //发货任务 // else if (val == 8) return 'CheckJob' //校验任务 // else if (val == 9) return 'CountJob' //盘点任务 // else return 'Other' // } export function getPackingNumberAndBatchByList(managementList, itemCode, packingNumber, locationCode, batch) { var itemInfo = { packingNumber: "", batch: "" } var manageType = queryManageModelByList(managementList, itemCode, locationCode) if (manageType == "BY_QUANTITY") { itemInfo.packingNumber = "" itemInfo.batch = "" } else if (manageType == "BY_BATCH") { itemInfo.packingNumber = "" itemInfo.batch = batch } else if (manageType == "BY_PACKAGING") { itemInfo.packingNumber = packingNumber itemInfo.batch = batch } else if (manageType == "BY_UNIQUE_ID") { itemInfo.packingNumber = packingNumber itemInfo.batch = batch } else if (manageType == "") { itemInfo.packingNumber = packingNumber itemInfo.batch = batch } return itemInfo; } export function queryManageModelByList(managementList, itemCode, locationCode) { var result = managementList.find(res => { if (res.itemCode == itemCode && res.locationCode == locationCode) { return res.ManagementPrecision } }) if (result != undefined) { return result.ManagementPrecision } else { return "" } } // 获取业务类型字典项 export function getBusinessTypeDesc(type) { if (type == "SupplierDeliver") { return "供应商发货" } else if (type = "PurchaseReceipt") { return "采购收货"; } else if (type = "PurchaseReturn") { return "采购退货"; } else if (type = "PurchasePutaway") { return "采购上架"; } } export function queryManageModel(managementList, itemCode) { var result = managementList.filter(res => { if (res.itemCode == itemCode) { return res.ManagementPrecision } }) if (result != undefined) { return result[0].ManagementPrecision } else { return "" } } export function getPackingNumberAndBatch(managementList, itemCode, packingNumber, batch) { var itemInfo = { packingNumber: "", batch: "" } var manageType = queryManageModel(managementList, itemCode) if (manageType == "BY_QUANTITY") { itemInfo.packingNumber = "" itemInfo.batch = "" } else if (manageType == "BY_BATCH") { itemInfo.packingNumber = "" itemInfo.batch = batch } else if (manageType == "BY_PACKAGING") { itemInfo.packingNumber = packingNumber itemInfo.batch = batch } else if (manageType == "BY_UNIQUE_ID") { itemInfo.packingNumber = packingNumber itemInfo.batch = batch } return itemInfo; } // //提示是否消息 export function showConfirmMsg(content, callback) { uni.showModal({ title: '提示', cancelText: '否', confirmText: '是', content: content, success: function(res) { if (res.confirm) { callback(true); } else { callback(false); } }, }) } export function compare(key) { return function(a, b) { var val1 = a[key]; var val2 = b[key]; return val2 - val1; } } export function compareTime() { return function(a, b) { // 按照时间降序 return Date.parse(a.time) - Date.parse(a.time) } } //升序 export function compareAsc(key) { return function(a, b) { var val1 = a[key]; var val2 = b[key]; return val1 - val2; } } //倒序 export function compareDesc(key) { return function(a, b) { var val1 = a[key]; var val2 = b[key]; return val2 - val1; } } export function goHome() { uni.reLaunch({ url: '/pages/index/index' }).catch((e) => {}); } /** * 获取当天时间2023-11-07 00:00:00-->2023-11-07 23:59:59 */ export function getTodayDate() { var startTime = new Date(new Date().toLocaleDateString()).getTime(); var endTime = startTime + 24 * 60 * 60 * 1000 - 1 console.log("获取时间", startTime + "," + endTime) return startTime + "," + endTime; } export function getCurrDateOneMonthsTimes() { var end = Date.now() // var end = new Date('2019/12/31 15:18').getTime() var day = 31 var enda = new Date(end); var endm = enda.getMonth() + 1; var d = enda.getDate(); if (endm == 4 || endm == 6 || endm == 9 || endm == 11) { day = 30 } else { if (d == 31) { day = 30 } if (endm == 7 || endm == 12) { day = 31 } } if (endm == 1) { var endy = enda.getFullYear(); day = 31 if (d == 31) { day = 28 } if (d == 30) { day = 29 } if (d == 29) { day = 30 } if (endy % 4 == 0) { day = 31 if (d == 31) { day = 29 } if (d == 30) { day = 30 } if (d == 29) { day = 31 } } } if (endm == 2) { var endy = enda.getFullYear(); day = 28 if (endy % 4 == 0) { day = 29 } } var start = 1000 * 60 * 60 * 24 * day var interval = end + start; return interval; } export function getCurrDateTimes() { var time = (new Date()).getTime(); return time; } //2024717 export function getBatch() { var date = new Date(); var year = date.getFullYear(); //年 var month = date.getMonth() + 1; //月 var day = date.getDate(); //日 var batch = year.toString() + month.toString() + day.toString() return batch; } //20270717 export function getBatch8() { var date = new Date(); //获取日期部分 var year = date.getFullYear(); //年 var month = date.getMonth() + 1; //月 var day = date.getDate(); //日 month = month < 10 ? "0" + month : month; day = day < 10 ? "0" + day : day; return year + month + day; } /** * 获取前几天和后几天的日期 2024-07-07 */ export function lastThreeDays(grapDay) { let dates = []; for (let i = grapDay; i >= 0; i--) { // 创建新的Date对象,并减去i天 let date = new Date(); date.setDate(date.getDate() - i); // 将格式化的日期字符串添加到数组中 dates.push(formatDate(date)); } for (let i = 0; i { //播放结束 music = null; }); } export function newMessageAudio() { var music = null; music = uni.createInnerAudioContext(); //创建播放器对象 music.src = "../../static/video/error.wav"; music.volume = 1; music.play(); //执行播放 music.onEnded(() => { //播放结束 music = null; }); } export function vibrate() { uni.vibrateLong({ success: function() { } }) } export function getDataSource(subList) { let items = []; subList.forEach(detail => { var item = items.find(r => r.itemCode == detail.itemCode) if (item == undefined) { item = createItemInfo(detail); let newDetail = createDetailInfo(detail); // item.subList.push(newDetail); items.push(item) } else { item.qty = calc.add(item.qty, detail.qty) let newDetail = createDetailInfo(detail); // item.subList.push(newDetail); } }) return items; } export function createItemInfo(res) { let item = { itemCode: res.itemCode, itemName: res.itemName, packQty: Number(res.packQty), packUnit: res.packUnit, qty: Number(res.qty), handleQty: 0, uom: res.uom, subList: [] } return item; } export function createDetailInfo(data) { data.scaned = false; // data.record = {}; let detail = data; return detail; } export function updateTitle(title) { uni.setNavigationBarTitle({ title: title }) } export function clearTirmAndWrap(content) { return content.replace(/<\/?.+?\/?>|\r|\n|\s*/g, '') } export function navigateBack(backIndex) { let canNavBack = getCurrentPages() if (canNavBack && canNavBack.length - 1 > backIndex) { uni.navigateBack({ delta: backIndex }) } else { history.back(); } } /** * 深度克隆对象 * @param {*} target */ export function deepCopyData(target) { // 克隆原始类型和null if (!(target !== null && (typeof target === 'object' || typeof target === 'function'))) { return target; } let cloneTarget = Array.isArray(target) ? [] : {}; // 克隆对象和数组 for (const key in target) { cloneTarget[key] = deepCopyData(target[key]); } return cloneTarget; } //数组去重重复数据 export function uniqueArray(arr) { return arr.filter((item, index, self) => self.indexOf(item) === index); }