From ce5f5a956f536c23418873801d64344ad9046e3f Mon Sep 17 00:00:00 2001 From: HongxuanG <1359774872@qq.com> Date: Tue, 18 Aug 2026 14:06:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(storegoods):=20=E6=96=B0=E5=A2=9E=E6=88=90?= =?UTF-8?q?=E5=93=81=E9=87=87=E8=B4=AD=E8=BF=9B=E4=BB=93=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- src/common/http.api.js | 25 +- src/common/storeGoodsPurchaseIn.js | 473 +++++++++++++ .../card/storeGoodsPurchaseInItem.vue | 67 ++ src/pages.json | 28 + .../storegoods/storeGoodsPurchaseInAdd.vue | 167 +++++ .../storegoods/storeGoodsPurchaseInEdit.vue | 147 ++++ .../storegoods/storeGoodsPurchaseInList.vue | 263 ++++++++ .../storegoods/storeGoodsPurchaseInMixin.js | 627 ++++++++++++++++++ .../storegoods/storeGoodsPurchaseInView.vue | 153 +++++ src/pages/sys/workbench/index.vue | 6 + 10 files changed, 1948 insertions(+), 8 deletions(-) create mode 100644 src/common/storeGoodsPurchaseIn.js create mode 100644 src/components/card/storeGoodsPurchaseInItem.vue create mode 100644 src/pages/storegoods/storeGoodsPurchaseInAdd.vue create mode 100644 src/pages/storegoods/storeGoodsPurchaseInEdit.vue create mode 100644 src/pages/storegoods/storeGoodsPurchaseInList.vue create mode 100644 src/pages/storegoods/storeGoodsPurchaseInMixin.js create mode 100644 src/pages/storegoods/storeGoodsPurchaseInView.vue diff --git a/src/common/http.api.js b/src/common/http.api.js index b28753f..481dcc5 100644 --- a/src/common/http.api.js +++ b/src/common/http.api.js @@ -9,13 +9,7 @@ const install = (Vue, vm) => { console.log('install u',config) // 接口前缀统一走 hcscm(apiurl 已在 config.js 配置为 hcscm 服务) - // 部分基础资料(往来单位、营销体系)仍在 hcscm_weave const getApiUrl = () => String(vm.$store.state.apiurl || ''); - const getWeaveApiUrl = () => { - const url = getApiUrl(); - if (url.indexOf('hcscm_weave') !== -1) return url; - return url.replace('/hcscm/', '/hcscm_weave/'); - }; const GFM_OTHER_DELIVERY_PREFIX = '/grey_fabric_manage/gfmOtherDeliveryOrder/'; const gfmOtherDeliveryUrl = (name) => getApiUrl() + GFM_OTHER_DELIVERY_PREFIX + name; @@ -32,6 +26,9 @@ const install = (Vue, vm) => { const FPM_PROCESS_OUT_PREFIX = '/product/fpmProcessOutOrder/'; const fpmProcessOutUrl = (name) => getApiUrl() + FPM_PROCESS_OUT_PREFIX + name; + const FPM_PRC_IN_PREFIX = '/product/fpmPrcInOrder/'; + const fpmPrcInUrl = (name) => getApiUrl() + FPM_PRC_IN_PREFIX + name; + // 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下 vm.$u.api = { @@ -100,6 +97,18 @@ const install = (Vue, vm) => { getOutTypeEnum: (params = {}) => vm.$u.get(getApiUrl() + '/product/enum/getProcessOutTypeTypeEnum', params), }, + // 成品采购进仓单 + fpmPrcInOrder: { + list: (params = {}) => vm.$u.get(fpmPrcInUrl('getFpmPrcInOrderList'), params), + detail: (params = {}) => vm.$u.get(fpmPrcInUrl('getFpmPrcInOrder'), params), + add: (params = {}) => vm.$u.postJson(fpmPrcInUrl('addFpmPrcInOrder'), params), + scanUpdate: (params = {}) => vm.$u.putJson(fpmPrcInUrl('updateFpmPrcInOrder'), params), + statusPass: (params = {}) => vm.$u.putJson(fpmPrcInUrl('updateFpmPrcInOrderStatusPass'), params), + statusWait: (params = {}) => vm.$u.putJson(fpmPrcInUrl('updateFpmPrcInOrderStatusWait'), params), + statusReject: (params = {}) => vm.$u.putJson(fpmPrcInUrl('updateFpmPrcInOrderStatusReject'), params), + statusCancel: (params = {}) => vm.$u.putJson(fpmPrcInUrl('updateFpmPrcInOrderStatusCancel'), params), + }, + // 物理仓库下拉 physicalWarehouse: { getDropdownList: (params = {}) => vm.$u.get('/warehouse/physicalWarehouse/getPhysicalWarehouseDropdownList', params), @@ -110,9 +119,9 @@ const install = (Vue, vm) => { getByQrCode: (params = {}) => vm.$u.get('/warehouse/warehouseBin/getWarehouseBin', params), }, - // 营销体系下拉(基础资料在 hcscm_weave) + // 营销体系下拉 saleSystem: { - getDropdownList: (params = {}) => vm.$u.get(getWeaveApiUrl() + '/saleSystem/getSaleSystemDropdownList', params), + getDropdownList: (params = {}) => vm.$u.get(getApiUrl() + '/saleSystem/getSaleSystemDropdownList', params), }, // 往来单位列表 diff --git a/src/common/storeGoodsPurchaseIn.js b/src/common/storeGoodsPurchaseIn.js new file mode 100644 index 0000000..3b285ae --- /dev/null +++ b/src/common/storeGoodsPurchaseIn.js @@ -0,0 +1,473 @@ +/** + * 成品采购进仓单常量与数据工具 + * + * 真实接口请求统一注册在 src/common/http.api.js 的 vm.$u.api.fpmPrcInOrder 下。 + */ +import dayjs from 'dayjs'; + +export const AUDIT_STATUS = { + PENDING: 1, + APPROVED: 2, + REJECTED: 3, + VOIDED: 4, +}; + +export const DRAFT_AUDIT_STATUS = 0; +export const DRAFT_AUDIT_STATUS_NAME = '待保存'; + +export const AUDIT_STATUS_MAP = { + 1: '待审核', + 2: '已审核', + 3: '已驳回', + 4: '已作废', +}; + +/** 操作类型:1录入 3删除 */ +export const ARRANGE_TYPE = { + IN: 1, + DEL: 3, +}; + +/** 入仓类型:采购进仓单 */ +export const IN_ORDER_TYPE_PURCHASE = 4; + +export const IN_ORDER_TYPE_MAP = { + [IN_ORDER_TYPE_PURCHASE]: '采购进仓单', +}; + +/** 订单类型:1大货 2剪板 3客订大货 4客订剪板 */ +export const SALE_MODE = { + BULK: 1, + SHEAR: 2, + CUSTOMER_BULK: 3, + CUSTOMER_SHEAR: 4, +}; + +export const SALE_MODE_MAP = { + [SALE_MODE.BULK]: '大货', + [SALE_MODE.SHEAR]: '剪板', + [SALE_MODE.CUSTOMER_BULK]: '客订大货', + [SALE_MODE.CUSTOMER_SHEAR]: '客订剪板', +}; + +export const SALE_MODE_OPTIONS = [ + { value: SALE_MODE.BULK, label: SALE_MODE_MAP[SALE_MODE.BULK] }, + { value: SALE_MODE.SHEAR, label: SALE_MODE_MAP[SALE_MODE.SHEAR] }, + { value: SALE_MODE.CUSTOMER_BULK, label: SALE_MODE_MAP[SALE_MODE.CUSTOMER_BULK] }, + { value: SALE_MODE.CUSTOMER_SHEAR, label: SALE_MODE_MAP[SALE_MODE.CUSTOMER_SHEAR] }, +]; + +/** 往来单位类型:成品供应商 */ +export const BUSINESS_UNIT_TYPE_PRODUCT_SUPPLIER = 15; + +/** 成品物理仓类型 */ +export const WAREHOUSE_TYPE_FINISHED = 103; + +/** 默认仓库名称 */ +export const DEFAULT_WAREHOUSE_NAME = '成品仓'; + +/** 默认纸筒重量(公斤,表单展示值) */ +export const DEFAULT_PAPER_TUBE_WEIGHT = 1.5; + +/** 默认包装重量(公斤,表单展示值) */ +export const DEFAULT_PACKAGE_WEIGHT = 0.3; + +export const LIST_PAGE_SIZE = 100; + +export const STATUS_ACTION_CONFIG = { + approve: { status: AUDIT_STATUS.APPROVED, msg: '确认审核该单据?', apiKey: 'statusPass' }, + void: { status: AUDIT_STATUS.VOIDED, msg: '确认作废该单据?', apiKey: 'statusCancel' }, + unapprove: { status: AUDIT_STATUS.PENDING, msg: '确认消审该单据?', apiKey: 'statusWait' }, +}; + +export function getStatusOptions() { + return Object.keys(AUDIT_STATUS_MAP).map((value) => ({ + value, + label: AUDIT_STATUS_MAP[value], + })); +} + +export function mapToSelectOptions(data) { + const list = Array.isArray(data) ? data : (data && (data.list || data.items || data.records)) || []; + return list.map((item) => ({ + value: item.id, + label: item.name || item.label || item.code || String(item.id), + })); +} + +/** 匹数:后端 ×100 存储 */ +export function formatRoll(value) { + const n = Number(value || 0) / 100; + return Number.isInteger(n) ? n : Number(n.toFixed(2)); +} + +/** 数量(公斤):后端 ×10000 存储 */ +export function formatWeightKg(value) { + const n = Number(value || 0) / 10000; + return Number(n.toFixed(2)); +} + +/** 公斤展示值转后端存储(×10000) */ +export function toWeightStorage(value) { + return Math.round(Number(value || 0) * 10000); +} + +export function normalizeOrder(order) { + if (!order) return null; + return { + id: order.id, + order_no: order.order_no || '', + audit_status: order.audit_status, + audit_status_name: order.audit_status_name || AUDIT_STATUS_MAP[order.audit_status] || '', + biz_unit_id: order.biz_unit_id || '', + biz_unit_name: order.biz_unit_name || '', + warehouse_id: order.warehouse_id || '', + warehouse_name: order.warehouse_name || '', + sale_system_id: order.sale_system_id || '', + sale_system_name: order.sale_system_name || '', + sale_mode: order.sale_mode || '', + sale_mode_name: order.sale_mode_name || SALE_MODE_MAP[order.sale_mode] || '', + in_order_type: order.in_order_type || IN_ORDER_TYPE_PURCHASE, + in_order_type_name: order.in_order_type_name + || IN_ORDER_TYPE_MAP[order.in_order_type] + || IN_ORDER_TYPE_MAP[IN_ORDER_TYPE_PURCHASE], + paper_tube_weight: formatWeightKg(order.paper_tube_weight), + package_weight: formatWeightKg(order.package_weight), + remark: order.remark || '', + warehouse_in_time: (order.warehouse_in_time || '').slice(0, 10), + creator_name: order.creator_name || '', + create_time: order.create_time || '', + auditor_name: order.auditor_name || '', + audit_time: order.audit_time || '', + total_roll: formatRoll(order.total_roll), + total_weight: formatWeightKg(order.total_weight), + total_length: formatRoll(order.total_length), + item_data: (order.item_data || []).map(normalizeItem), + _raw: order, + }; +} + +export function normalizeFineCode(fc) { + if (!fc) return null; + const weightRaw = fc.base_unit_weight != null + ? fc.base_unit_weight + : (fc.settle_weight != null ? fc.settle_weight : fc.weight); + const qrCode = fc.qr_code || fc.long_code || ''; + const barCode = fc.bar_code || fc.digital_code || fc.short_code || ''; + return { + id: fc.id, + volume_number: fc.volume_number != null && fc.volume_number !== '' ? String(fc.volume_number) : '', + roll: formatRoll(fc.roll), + weight: formatWeightKg(weightRaw), + bar_code: barCode, + qr_code: qrCode, + digital_code: fc.digital_code || '', + long_code: fc.long_code || '', + short_code: fc.short_code || '', + dye_factory_dyelot_number: fc.dye_factory_dyelot_number || fc.dyelot_number || '', + warehouse_bin_name: fc.warehouse_bin_name || '', + shelf_no: fc.shelf_no || '', + scan_code: qrCode || barCode || '', + paper_tube_weight: fc.paper_tube_weight != null && fc.paper_tube_weight !== '' + ? formatWeightKg(fc.paper_tube_weight) + : null, + package_weight: fc.package_weight != null && fc.package_weight !== '' + ? formatWeightKg(fc.package_weight) + : null, + }; +} + +export function normalizeItem(item) { + const weightRaw = item.in_weight != null ? item.in_weight : item.total_weight; + return { + id: item.id, + quote_order_no: item.quote_order_no || '', + product_code: item.product_code || '', + product_name: item.product_name || '', + product_color_code: item.product_color_code || '', + product_color_name: item.product_color_name || '', + dye_factory_dyelot_number: item.dye_factory_dyelot_number || '', + dye_factory_color_code: item.dye_factory_color_code || '', + in_roll: formatRoll(item.in_roll), + in_weight: formatWeightKg(weightRaw), + item_fc_data: (item.item_fc_data || []).map(normalizeFineCode).filter(Boolean), + }; +} + +/** + * 明细分组:成品编号 → 成品色号 → 细码 + */ +export function buildItemGroups(items) { + const productMap = new Map(); + (items || []).forEach((item) => { + const productKey = item.product_code || '-'; + if (!productMap.has(productKey)) { + productMap.set(productKey, { + group_key: `p:${productKey}`, + product_code: item.product_code || '', + product_name: item.product_name || '', + in_roll: 0, + in_weight: 0, + colors: new Map(), + }); + } + const productGroup = productMap.get(productKey); + if (!productGroup.product_name && item.product_name) { + productGroup.product_name = item.product_name; + } + + const colorKey = item.product_color_code || item.product_color_name || '-'; + if (!productGroup.colors.has(colorKey)) { + productGroup.colors.set(colorKey, { + group_key: `p:${productKey}|c:${colorKey}`, + product_color_code: item.product_color_code || '', + product_color_name: item.product_color_name || '', + quote_order_no: item.quote_order_no || '', + dye_factory_dyelot_number: item.dye_factory_dyelot_number || '', + in_roll: 0, + in_weight: 0, + fine_codes: [], + }); + } + const colorGroup = productGroup.colors.get(colorKey); + productGroup.in_roll = Number((productGroup.in_roll + Number(item.in_roll || 0)).toFixed(2)); + productGroup.in_weight = Number((productGroup.in_weight + Number(item.in_weight || 0)).toFixed(2)); + colorGroup.in_roll = Number((colorGroup.in_roll + Number(item.in_roll || 0)).toFixed(2)); + colorGroup.in_weight = Number((colorGroup.in_weight + Number(item.in_weight || 0)).toFixed(2)); + if (item.quote_order_no) colorGroup.quote_order_no = item.quote_order_no; + if (item.dye_factory_dyelot_number) { + colorGroup.dye_factory_dyelot_number = item.dye_factory_dyelot_number; + } + if (!colorGroup.product_color_name && item.product_color_name) { + colorGroup.product_color_name = item.product_color_name; + } + colorGroup.fine_codes.push(...(item.item_fc_data || [])); + }); + + return Array.from(productMap.values()).map((product) => ({ + group_key: product.group_key, + product_code: product.product_code, + product_name: product.product_name, + in_roll: product.in_roll, + in_weight: product.in_weight, + colors: Array.from(product.colors.values()), + })); +} + +export function getEmptyScanDetail() { + return { + quote_order_no: '', + dyelot_number: '', + volume_number: '', + product_code: '', + product_color_code: '', + order_roll: 0, + item_roll: 0, + order_weight: 0, + item_weight: 0, + }; +} + +/** 刚扫细码的数量(公斤存储值):优先细码 weight */ +function pickScannedFineWeight(res) { + if (!res) return 0; + if (res.weight != null && res.weight !== '') return res.weight; + if (res.base_unit_weight != null && res.base_unit_weight !== '') return res.base_unit_weight; + if (res.settle_weight != null && res.settle_weight !== '') return res.settle_weight; + if (res.actually_weight != null && res.actually_weight !== '') return res.actually_weight; + return res.item_weight; +} + +/** 从扫码接口返回构建详情区(匹数÷100,数量÷10000) */ +export function buildScanDetailFromScanResponse(res) { + if (!res) return getEmptyScanDetail(); + return { + quote_order_no: res.quote_order_no || '', + dyelot_number: res.dyelot_number || '', + volume_number: res.volume_number != null && res.volume_number !== '' ? String(res.volume_number) : '', + product_code: res.product_code || '', + product_color_code: res.product_color_code || '', + order_roll: formatRoll(res.order_roll != null ? res.order_roll : res.total_roll), + item_roll: formatRoll(res.item_roll != null ? res.item_roll : res.roll), + order_weight: formatWeightKg(res.order_weight != null ? res.order_weight : res.total_weight), + // 本行数量:刚扫这条细码的重量(weight),不是明细行合计 + item_weight: formatWeightKg(pickScannedFineWeight(res)), + }; +} + +/** 校验纸筒/包装重量(扫码时提交) */ +export function validateScanWeights(paperTubeWeight, packageWeight) { + if (paperTubeWeight === '' || paperTubeWeight == null) { + return '请输入纸筒重量'; + } + if (Number.isNaN(Number(paperTubeWeight))) return '纸筒重量格式不正确'; + if (packageWeight === '' || packageWeight == null) { + return '请输入包装重量'; + } + if (Number.isNaN(Number(packageWeight))) return '包装重量格式不正确'; + return ''; +} + +/** 构建扫码请求参数(纸筒/包装重量在扫码时提交,公斤值需 ×10000) */ +export function buildScanUpdateParams({ + id, + scanCode, + arrangeType, + warehouseBinId, + paperTubeWeight, + packageWeight, +}) { + const code = (scanCode || '').trim(); + const params = { + id: Number(id), + arrange_type: arrangeType, + paper_tube_weight: toWeightStorage(paperTubeWeight), + package_weight: toWeightStorage(packageWeight), + }; + if (warehouseBinId) { + params.warehouse_bin_id = Number(warehouseBinId); + } + // 长度大于25走二维码,否则走条码 + if (code.length > 25) { + params.qr_code = code; + } else { + params.bar_code = code; + } + return params; +} + +export function buildStatusParam(id) { + return { id: String(id) }; +} + +export function formatDisplayTime(value, format = 'YYYY-MM-DD') { + if (!value) return ''; + const parsed = dayjs(value); + return parsed.isValid() ? parsed.format(format) : String(value).slice(0, 10); +} + +export function canScanAtStatus(status) { + return [AUDIT_STATUS.PENDING, AUDIT_STATUS.REJECTED].includes(status); +} + +export function isLockedOrderStatus(status) { + return [AUDIT_STATUS.APPROVED, AUDIT_STATUS.VOIDED].includes(status); +} + +export function fetchAllOrderList(listFn, params = {}, pageSize = LIST_PAGE_SIZE) { + const pickBatch = (res) => { + if (Array.isArray(res)) return res; + if (!res || typeof res !== 'object') return []; + return res.list || res.records || res.items || []; + }; + const loadPage = (page, acc) => listFn({ ...params, page, size: pageSize }) + .then((res) => { + const batch = pickBatch(res); + if (!batch.length) return acc; + // 一次返回超过 pageSize:后端忽略分页,视为全量,避免死循环翻页 + if (batch.length > pageSize) return acc.concat(batch); + // 翻页后与首页首条相同:后端忽略 page,避免死循环 + if ( + page > 1 + && acc.length + && batch[0] + && acc[0] + && String(batch[0].id) === String(acc[0].id) + ) { + return acc; + } + const merged = acc.concat(batch); + const total = !Array.isArray(res) && res != null ? Number(res.total) : NaN; + if (!Number.isNaN(total) && merged.length >= total) return merged; + if (batch.length < pageSize) return merged; + return loadPage(page + 1, merged); + }); + return loadPage(1, []); +} + +export function getFormStatusActionButtons(headerSaved, orderId, status) { + if (!headerSaved || !orderId || !canScanAtStatus(status)) return []; + return [ + { label: '审核', action: 'approve' }, + { label: '作废', action: 'void' }, + ]; +} + +export function getViewStatusActionButtons(status) { + if (status === AUDIT_STATUS.PENDING || status === AUDIT_STATUS.REJECTED) { + return [ + { label: '编辑', action: 'edit' }, + { label: '审核', action: 'approve' }, + { label: '作废', action: 'void' }, + ]; + } + if (status === AUDIT_STATUS.APPROVED) { + return [{ label: '消审', action: 'unapprove' }]; + } + return []; +} + +export function orderToFormFields(order) { + return { + order_no: order.order_no, + biz_unit_id: order.biz_unit_id, + biz_unit_name: order.biz_unit_name, + warehouse_id: order.warehouse_id, + warehouse_name: order.warehouse_name, + sale_system_id: order.sale_system_id, + sale_system_name: order.sale_system_name, + sale_mode: order.sale_mode || '', + sale_mode_name: order.sale_mode_name || SALE_MODE_MAP[order.sale_mode] || '', + in_order_type: order.in_order_type || IN_ORDER_TYPE_PURCHASE, + in_order_type_name: order.in_order_type_name + || IN_ORDER_TYPE_MAP[order.in_order_type] + || IN_ORDER_TYPE_MAP[IN_ORDER_TYPE_PURCHASE], + paper_tube_weight: String(DEFAULT_PAPER_TUBE_WEIGHT), + package_weight: String(DEFAULT_PACKAGE_WEIGHT), + remark: order.remark, + item_data: order.item_data, + }; +} + +/** 从仓库下拉中选出默认成品仓 */ +export function pickDefaultWarehouse(options, loginWarehouseId, loginWarehouseName) { + const list = options || []; + const byName = list.find((item) => item.label === DEFAULT_WAREHOUSE_NAME); + if (byName) return byName; + if (loginWarehouseId) { + const byId = list.find((item) => String(item.value) === String(loginWarehouseId)); + if (byId) return byId; + if (loginWarehouseName) { + return { value: loginWarehouseId, label: loginWarehouseName }; + } + } + return list[0] || null; +} + +/** + * 确认并执行审核状态变更 + */ +export function confirmOrderStatusAction(vm, { orderId, action, onSuccess }) { + const cfg = STATUS_ACTION_CONFIG[action]; + if (!cfg || !orderId) return; + const api = vm.$u.api.fpmPrcInOrder; + const requestFn = api[cfg.apiKey]; + if (typeof requestFn !== 'function') return; + uni.showModal({ + title: '提示', + content: cfg.msg, + success: (res) => { + if (!res.confirm) return; + uni.showLoading({ title: '处理中...' }); + requestFn(buildStatusParam(orderId)) + .then(() => { + if (typeof onSuccess === 'function') return onSuccess(); + uni.hideLoading(); + }) + .catch((e) => { + uni.hideLoading(); + if (vm.showError) vm.showError(e.message || '操作失败'); + }); + }, + }); +} diff --git a/src/components/card/storeGoodsPurchaseInItem.vue b/src/components/card/storeGoodsPurchaseInItem.vue new file mode 100644 index 0000000..14ec1d5 --- /dev/null +++ b/src/components/card/storeGoodsPurchaseInItem.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/src/pages.json b/src/pages.json index f876213..736b166 100644 --- a/src/pages.json +++ b/src/pages.json @@ -449,6 +449,34 @@ "navigationBarTitleText": "查看加工进仓单", "enablePullDownRefresh": false } + },{ + "path" : "pages/storegoods/storeGoodsPurchaseInList", + "style" : + { + "navigationBarTitleText": "成品采购进仓", + "enablePullDownRefresh": false + } + },{ + "path" : "pages/storegoods/storeGoodsPurchaseInAdd", + "style" : + { + "navigationBarTitleText": "新增采购进仓单", + "enablePullDownRefresh": false + } + },{ + "path" : "pages/storegoods/storeGoodsPurchaseInEdit", + "style" : + { + "navigationBarTitleText": "编辑采购进仓单", + "enablePullDownRefresh": false + } + },{ + "path" : "pages/storegoods/storeGoodsPurchaseInView", + "style" : + { + "navigationBarTitleText": "采购进仓单详情", + "enablePullDownRefresh": false + } },{ "path" : "pages/storegoods/storeGoodsProcessReturnInList", "style" : diff --git a/src/pages/storegoods/storeGoodsPurchaseInAdd.vue b/src/pages/storegoods/storeGoodsPurchaseInAdd.vue new file mode 100644 index 0000000..aec8ccd --- /dev/null +++ b/src/pages/storegoods/storeGoodsPurchaseInAdd.vue @@ -0,0 +1,167 @@ + + + + + diff --git a/src/pages/storegoods/storeGoodsPurchaseInEdit.vue b/src/pages/storegoods/storeGoodsPurchaseInEdit.vue new file mode 100644 index 0000000..5ce0f70 --- /dev/null +++ b/src/pages/storegoods/storeGoodsPurchaseInEdit.vue @@ -0,0 +1,147 @@ + + + + + diff --git a/src/pages/storegoods/storeGoodsPurchaseInList.vue b/src/pages/storegoods/storeGoodsPurchaseInList.vue new file mode 100644 index 0000000..944eb39 --- /dev/null +++ b/src/pages/storegoods/storeGoodsPurchaseInList.vue @@ -0,0 +1,263 @@ + + + + + diff --git a/src/pages/storegoods/storeGoodsPurchaseInMixin.js b/src/pages/storegoods/storeGoodsPurchaseInMixin.js new file mode 100644 index 0000000..172705b --- /dev/null +++ b/src/pages/storegoods/storeGoodsPurchaseInMixin.js @@ -0,0 +1,627 @@ +/** + * 成品采购进仓单表单 mixin(新增/编辑共用) + * + * 1. 先填表头(供应商 / 仓库 / 营销体系 / 订单类型 / 备注)提交 add,拿到 id 后可扫码 + * 2. 先扫仓位(getWarehouseBin:传 qr_code + warehouse_id),校验后扫布匹二维码 + * 3. 扫码走 updateFpmPrcInOrder(arrange_type: 1 录入 / 3 删除,带 warehouse_bin_id、纸筒/包装重量) + * 4. 手机扫码成功展示详情后自动再次调起扫码,形成连续扫 + */ +import util from '@/common/util'; +import scanMixin from '@/common/scanMixin.js'; +import { initTts, speak } from '@/common/tts.js'; +import { + AUDIT_STATUS_MAP, + ARRANGE_TYPE, + BUSINESS_UNIT_TYPE_PRODUCT_SUPPLIER, + WAREHOUSE_TYPE_FINISHED, + IN_ORDER_TYPE_PURCHASE, + IN_ORDER_TYPE_MAP, + SALE_MODE, + SALE_MODE_MAP, + SALE_MODE_OPTIONS, + DEFAULT_PAPER_TUBE_WEIGHT, + DEFAULT_PACKAGE_WEIGHT, + normalizeOrder, + mapToSelectOptions, + canScanAtStatus, + isLockedOrderStatus, + getFormStatusActionButtons, + orderToFormFields, + confirmOrderStatusAction, + DRAFT_AUDIT_STATUS, + DRAFT_AUDIT_STATUS_NAME, + getEmptyScanDetail, + buildScanDetailFromScanResponse, + buildScanUpdateParams, + pickDefaultWarehouse, + validateScanWeights, +} from '@/common/storeGoodsPurchaseIn'; + +export default { + mixins: [scanMixin], + data() { + return { + pageMode: 'add', + orderId: 0, + form: this.getEmptyForm(), + headerSaved: false, + selectShow: false, + selectList: [], + selectType: '', + canScan: false, + QRBarCode: '', + BarCodeDelStatus: false, + BillDataMessage: '', + scanDetail: getEmptyScanDetail(), + auditStatus: 0, + supplierOptions: [], + warehouseOptions: [], + saleSystemOptions: [], + saleModeOptions: SALE_MODE_OPTIONS, + dropdownLoading: false, + /** 仓位 */ + warehouseBinId: 0, + warehouseBinCode: '', + warehouseBinName: '', + /** 手机连续扫码开关:成功后自动再调起;取消/失败则关闭 */ + phoneContinuousScan: false, + /** 手机扫当前目标:bin | qr */ + phoneScanTarget: 'bin', + }; + }, + computed: { + isReadonly() { + return this.pageMode === 'view'; + }, + isEditable() { + return this.pageMode === 'add' || this.pageMode === 'edit'; + }, + headerEditable() { + return this.pageMode === 'add' && !this.headerSaved; + }, + /** 纸筒/包装重量随扫码提交,保存前后及可扫编辑态均可改 */ + canEditWeights() { + return this.isEditable && (this.headerEditable || this.canScan); + }, + statusActionButtons() { + return getFormStatusActionButtons(this.headerSaved, this.orderId, this.auditStatus); + }, + displayAuditStatus() { + if (this.pageMode === 'add' && !this.headerSaved) return DRAFT_AUDIT_STATUS; + return this.auditStatus; + }, + displayAuditStatusName() { + if (this.pageMode === 'add' && !this.headerSaved) return DRAFT_AUDIT_STATUS_NAME; + return AUDIT_STATUS_MAP[this.auditStatus] || ''; + }, + /** 录入需先选仓位;删除模式仅需单据可扫 */ + canScanQr() { + if (!this.canScan) return false; + if (this.BarCodeDelStatus) return true; + return !!this.warehouseBinId; + }, + /** 扫码栏在可扫状态下始终展示(含删除勾选) */ + showQrScanBar() { + return this.canScan; + }, + qrDisabledTip() { + if (!this.canScan) return '请先提交保存后再扫码'; + if (!this.warehouseBinId && !this.BarCodeDelStatus) return '请先扫描仓位后再扫布匹二维码'; + return '当前状态不可扫码'; + }, + }, + onShow() { + this.isPageActive = true; + initTts(); + if (this.canScan && this.isEditable) { + this.registerOrderScanBroadcast(); + } + }, + onHide() { + this.isPageActive = false; + this.phoneContinuousScan = false; + this.unregisterScanBroadcast(); + }, + onUnload() { + this.isPageActive = false; + this.phoneContinuousScan = false; + this.unregisterScanBroadcast(); + }, + methods: { + clearWarehouseBin() { + this.warehouseBinId = 0; + this.warehouseBinCode = ''; + this.warehouseBinName = ''; + this.phoneContinuousScan = false; + }, + handleBinPhoneScan() { + if (!this.canScan || !this.orderId) { + this.showError('请先提交保存后再扫码'); + return; + } + this.phoneContinuousScan = false; + this.phoneScanTarget = 'bin'; + this.openPhoneScan({ + callback: (scanResult) => { + this.warehouseBinCode = String(scanResult || '').trim().replace(/[\r\n]/g, ''); + this.$nextTick(() => this.resolveWarehouseBin()); + }, + fail: () => {}, + }); + }, + handlePhoneScan() { + if (!this.canScan || !this.orderId) { + this.showError('请先提交保存后再扫码'); + return; + } + // 删除模式可直接扫布匹码;录入模式无仓位时先扫仓位 + if (!this.BarCodeDelStatus && !this.warehouseBinId) { + this.handleBinPhoneScan(); + return; + } + this.phoneScanTarget = 'qr'; + this.phoneContinuousScan = true; + this.openContinuousPhoneScan(); + }, + openContinuousPhoneScan() { + if (!this.phoneContinuousScan || !this.canScanQr || !this.isPageActive) { + this.phoneContinuousScan = false; + return; + } + this.openPhoneScan({ + callback: (scanResult) => { + this.QRBarCode = String(scanResult || '').trim().replace(/[\r\n]/g, ''); + this.$nextTick(() => this.handleScan({ fromPhone: true })); + }, + fail: () => { + this.phoneContinuousScan = false; + }, + }); + }, + scheduleNextPhoneScan() { + if (!this.phoneContinuousScan || !this.canScanQr || !this.isPageActive) { + this.phoneContinuousScan = false; + return; + } + setTimeout(() => { + this.openContinuousPhoneScan(); + }, 400); + }, + registerOrderScanBroadcast() { + this.registerScanBroadcast((scanResult) => { + const code = String(scanResult || '').trim().replace(/[\r\n]/g, ''); + if (!code) return; + // 删除模式:直接按布匹码删除;未扫仓位时枪扫优先解析为仓位 + if (!this.BarCodeDelStatus && !this.warehouseBinId) { + this.warehouseBinCode = code; + this.$nextTick(() => this.resolveWarehouseBin()); + return; + } + this.QRBarCode = code; + this.$nextTick(() => this.handleScan()); + }); + }, + resolveWarehouseBin() { + const code = (this.warehouseBinCode || '').trim(); + if (!this.canScan || !this.orderId) { + this.showError('请先提交保存后再扫码'); + return; + } + if (!code) return; + if (!this.form.warehouse_id) { + this.showError('单据缺少仓库信息'); + return; + } + uni.showLoading({ title: '识别仓位...' }); + return this.$u.api.warehouseBin.getByQrCode({ + qr_code: code, + warehouse_id: Number(this.form.warehouse_id), + }) + .then((data) => { + uni.hideLoading(); + if (!data || !data.id) { + throw new Error('未识别到仓位'); + } + // 返回 physical_warehouse_id,与单据仓库校验 + if ( + data.physical_warehouse_id + && String(data.physical_warehouse_id) !== String(this.form.warehouse_id) + ) { + this.warehouseBinId = 0; + this.warehouseBinName = ''; + throw new Error('该仓位不属于当前仓库'); + } + this.warehouseBinId = data.id; + this.warehouseBinCode = data.code || data.qr_code || code; + this.warehouseBinName = data.name || ''; + this.BillDataMessage = ''; + speak('仓位成功'); + uni.showToast({ title: '仓位识别成功', icon: 'success' }); + }) + .catch((e) => { + uni.hideLoading(); + this.warehouseBinId = 0; + this.warehouseBinName = ''; + this.showError(e.message || '仓位识别失败'); + }); + }, + syncCanScanFromStatus(status) { + const nextCanScan = this.isEditable && canScanAtStatus(status); + if (this.canScan && !nextCanScan) { + this.phoneContinuousScan = false; + this.unregisterScanBroadcast(); + } + this.canScan = nextCanScan; + }, + loadBaseDropdowns() { + if (this.dropdownLoading) return Promise.resolve(); + this.dropdownLoading = true; + if (this.headerEditable) this.applyDefaultSaleSystem(); + return Promise.all([ + this.ensureSupplierOptions().catch((e) => { + console.error('加载供应商失败', e); + return []; + }), + this.ensureWarehouseOptions().catch((e) => { + console.error('加载仓库失败', e); + return []; + }), + this.ensureSaleSystemOptions().catch((e) => { + console.error('加载营销体系失败', e); + return []; + }), + ]).finally(() => { + this.dropdownLoading = false; + }); + }, + ensureSupplierOptions() { + if (this.supplierOptions.length) return Promise.resolve(this.supplierOptions); + return this.$u.api.businessUnit.list({ unit_type_id: BUSINESS_UNIT_TYPE_PRODUCT_SUPPLIER }) + .then((res) => { + this.supplierOptions = mapToSelectOptions(res); + return this.supplierOptions; + }); + }, + ensureWarehouseOptions() { + if (this.warehouseOptions.length) return Promise.resolve(this.warehouseOptions); + return this.$u.api.physicalWarehouse.getDropdownList({ warehouse_type_id: WAREHOUSE_TYPE_FINISHED }) + .then((res) => { + this.warehouseOptions = mapToSelectOptions(res); + if (this.headerEditable && !this.form.warehouse_id) { + this.applyDefaultWarehouse(); + } + return this.warehouseOptions; + }); + }, + ensureSaleSystemOptions() { + if (this.saleSystemOptions.length) return Promise.resolve(this.saleSystemOptions); + return this.$u.api.saleSystem.getDropdownList() + .then((res) => { + this.saleSystemOptions = mapToSelectOptions(res); + if (this.headerEditable) this.applyDefaultSaleSystem(); + return this.saleSystemOptions; + }); + }, + applyDefaultWarehouse() { + const app = getApp(); + const picked = pickDefaultWarehouse( + this.warehouseOptions, + app && app.globalData ? app.globalData.StoreNameID : '', + app && app.globalData ? app.globalData.StoreName : '', + ); + if (!picked) return; + this.form.warehouse_id = picked.value; + this.form.warehouse_name = picked.label; + }, + applyDefaultSaleSystem() { + if (this.form.sale_system_id) { + if (!this.form.sale_system_name && this.saleSystemOptions.length) { + const found = this.saleSystemOptions.find( + (item) => String(item.value) === String(this.form.sale_system_id), + ); + if (found) this.form.sale_system_name = found.label; + } + return; + } + const app = getApp(); + const gd = app && app.globalData ? app.globalData : {}; + const id = gd.PlanDepartmentID; + if (!id) return; + this.form.sale_system_id = id; + this.form.sale_system_name = gd.PlanDepartmentName || ''; + if (!this.form.sale_system_name && this.saleSystemOptions.length) { + const found = this.saleSystemOptions.find((item) => String(item.value) === String(id)); + if (found) this.form.sale_system_name = found.label; + } + }, + getEmptyForm() { + const app = getApp(); + const gd = app && app.globalData ? app.globalData : {}; + return { + order_no: '', + biz_unit_id: '', + biz_unit_name: '', + warehouse_id: '', + warehouse_name: '', + sale_system_id: gd.PlanDepartmentID || '', + sale_system_name: gd.PlanDepartmentName || '', + sale_mode: SALE_MODE.BULK, + sale_mode_name: SALE_MODE_MAP[SALE_MODE.BULK], + in_order_type: IN_ORDER_TYPE_PURCHASE, + in_order_type_name: IN_ORDER_TYPE_MAP[IN_ORDER_TYPE_PURCHASE], + paper_tube_weight: String(DEFAULT_PAPER_TUBE_WEIGHT), + package_weight: String(DEFAULT_PACKAGE_WEIGHT), + remark: '', + item_data: [], + }; + }, + loadOrder(id, options = {}) { + const { rejectIfLocked = false } = options; + return this.$u.api.fpmPrcInOrder.detail({ id }) + .then((res) => { + const order = normalizeOrder(res); + if (!order) { + this.showError('单据不存在'); + return null; + } + if (rejectIfLocked && isLockedOrderStatus(order.audit_status)) { + this.showError('当前状态不可编辑'); + setTimeout(() => uni.navigateBack(), 1500); + return null; + } + this.orderId = order.id; + this.auditStatus = order.audit_status; + this.headerSaved = true; + this.form = orderToFormFields(order); + this.clearWarehouseBin(); + this.syncCanScanFromStatus(order.audit_status); + if (this.canScan) this.registerOrderScanBroadcast(); + return order; + }) + .catch((e) => { + this.showError(e.message || '加载单据失败'); + return null; + }); + }, + pickerSelectFun(type) { + if (!this.headerEditable) return; + this.selectType = type; + const openPicker = (list) => { + if (!list.length) { + this.showError('暂无可选数据'); + return; + } + this.selectList = list; + this.selectShow = true; + }; + if (type === '供应商') { + this.ensureSupplierOptions() + .then(openPicker) + .catch((e) => this.showError(e.message || '加载供应商失败')); + } else if (type === '仓库名称') { + this.ensureWarehouseOptions() + .then(openPicker) + .catch((e) => this.showError(e.message || '加载仓库失败')); + } else if (type === '营销体系') { + this.ensureSaleSystemOptions() + .then(openPicker) + .catch((e) => this.showError(e.message || '加载营销体系失败')); + } else if (type === '订单类型') { + openPicker(this.saleModeOptions); + } + }, + selectConfirmFun(e) { + const item = e[0]; + if (this.selectType === '供应商') { + this.form.biz_unit_id = item.value; + this.form.biz_unit_name = item.label; + } else if (this.selectType === '仓库名称') { + this.form.warehouse_id = item.value; + this.form.warehouse_name = item.label; + } else if (this.selectType === '营销体系') { + this.form.sale_system_id = item.value; + this.form.sale_system_name = item.label; + } else if (this.selectType === '订单类型') { + this.form.sale_mode = item.value; + this.form.sale_mode_name = item.label; + } + }, + validateForm() { + if (!this.form.biz_unit_id) return '请选择供应商'; + if (!this.form.warehouse_id) return '请选择仓库名称'; + if (!this.form.sale_system_id) return '请选择营销体系'; + if (!this.form.sale_mode) return '请选择订单类型'; + return ''; + }, + buildAddParam() { + return { + inOrderType: IN_ORDER_TYPE_PURCHASE, + biz_unit_id: Number(this.form.biz_unit_id), + warehouse_id: Number(this.form.warehouse_id), + sale_system_id: Number(this.form.sale_system_id), + sale_mode: Number(this.form.sale_mode), + remark: this.form.remark || '', + item_data: [], + }; + }, + submitSave() { + if (this.headerSaved) { + this.showError('表头已保存,请直接扫码'); + return; + } + const err = this.validateForm(); + if (err) { + this.showError(err); + return; + } + uni.showLoading({ title: '保存中...' }); + this.$u.api.fpmPrcInOrder.add(this.buildAddParam()) + .then((res) => { + this.orderId = (res && res.id) || 0; + if (!this.orderId) { + throw new Error('保存失败,未返回单据ID'); + } + return this.$u.api.fpmPrcInOrder.detail({ id: this.orderId }); + }) + .then((detail) => { + uni.hideLoading(); + const order = normalizeOrder(detail); + this.applyOrder(order, { keepWeights: true }); + this.headerSaved = true; + this.clearWarehouseBin(); + this.syncCanScanFromStatus(order.audit_status); + this.showSuccess('保存成功,请先扫描仓位'); + this.registerOrderScanBroadcast(); + }) + .catch((e) => { + uni.hideLoading(); + this.showError(e.message || '保存失败'); + }); + }, + applyOrder(order, options = {}) { + if (!order) return; + this.auditStatus = order.audit_status; + const paperTubeWeight = this.form.paper_tube_weight; + const packageWeight = this.form.package_weight; + Object.assign(this.form, orderToFormFields(order)); + if (options.keepWeights) { + this.form.paper_tube_weight = paperTubeWeight; + this.form.package_weight = packageWeight; + } + }, + handleScan(options = {}) { + const fromPhone = !!options.fromPhone; + const code = (this.QRBarCode || '').trim(); + if (!this.canScan || !this.orderId) { + this.showError('请先提交保存后再扫码'); + this.QRBarCode = ''; + this.phoneContinuousScan = false; + return; + } + const isDelete = this.BarCodeDelStatus; + if (!isDelete && !this.warehouseBinId) { + this.showError('请先扫描仓位'); + this.QRBarCode = ''; + this.phoneContinuousScan = false; + return; + } + if (!code) { + this.QRBarCode = ''; + if (fromPhone) this.scheduleNextPhoneScan(); + return; + } + const arrangeType = isDelete ? ARRANGE_TYPE.DEL : ARRANGE_TYPE.IN; + this.doScanUpdate(code, arrangeType, { fromPhone }); + }, + BarCodeDelChange(e) { + this.BarCodeDelStatus = (e.detail.value || []).length > 0; + this.BillDataMessage = this.BarCodeDelStatus ? '删除模式:扫描细码即可删除' : ''; + }, + getFineCodeScanCode(fineCode) { + if (!fineCode) return ''; + return fineCode.qr_code + || fineCode.long_code + || fineCode.scan_code + || fineCode.digital_code + || fineCode.bar_code + || fineCode.short_code + || ''; + }, + onDeleteFineCode(fineCode) { + if (!this.canScan || !this.orderId) { + this.showError('当前状态不可删除'); + return; + } + const scanCode = this.getFineCodeScanCode(fineCode); + if (!scanCode) { + this.showError('该细码缺少条码,无法删除'); + return; + } + uni.showModal({ + title: '提示', + content: `确认删除细码 ${scanCode}?`, + success: (res) => { + if (!res.confirm) return; + this.doScanUpdate(scanCode, ARRANGE_TYPE.DEL); + }, + }); + }, + doScanUpdate(scanCode, arrangeType, options = {}) { + const { fromPhone = false } = options; + const isDelete = arrangeType === ARRANGE_TYPE.DEL; + if (!isDelete) { + const weightErr = validateScanWeights(this.form.paper_tube_weight, this.form.package_weight); + if (weightErr) { + this.showError(weightErr); + this.QRBarCode = ''; + this.phoneContinuousScan = false; + return; + } + } + uni.showLoading({ title: isDelete ? '删除中...' : '处理中...' }); + return this.$u.api.fpmPrcInOrder.scanUpdate(buildScanUpdateParams({ + id: this.orderId, + scanCode, + arrangeType, + // 删除不强制仓位;录入带当前仓位 + warehouseBinId: isDelete ? 0 : this.warehouseBinId, + paperTubeWeight: this.form.paper_tube_weight, + packageWeight: this.form.package_weight, + })) + .then((scanRes) => { + this.scanDetail = buildScanDetailFromScanResponse(scanRes); + this.BillDataMessage = isDelete ? '删除成功' : '扫描成功'; + this.QRBarCode = ''; + if (isDelete) { + speak('已删除'); + uni.showToast({ title: '删除成功', icon: 'success' }); + } else { + speak('成功'); + } + return this.$u.api.fpmPrcInOrder.detail({ id: this.orderId }) + .then((detail) => { + const order = normalizeOrder(detail); + if (order) { + this.form.item_data = order.item_data; + this.auditStatus = order.audit_status; + } + }) + .catch(() => null); + }) + .then(() => { + uni.hideLoading(); + if (fromPhone) this.scheduleNextPhoneScan(); + }) + .catch((e) => { + uni.hideLoading(); + this.phoneContinuousScan = false; + const message = e.message || (isDelete ? '删除失败' : '扫码失败'); + this.showError(message); + this.QRBarCode = ''; + }); + }, + handleStatusAction(action) { + confirmOrderStatusAction(this, { + orderId: this.orderId, + action, + onSuccess: () => this.$u.api.fpmPrcInOrder.detail({ id: this.orderId }) + .then((detail) => { + uni.hideLoading(); + const order = normalizeOrder(detail); + if (!order) return; + this.applyOrder(order); + this.syncCanScanFromStatus(order.audit_status); + this.showSuccess('操作成功'); + }), + }); + }, + showError(message) { + util.playErrorAudio(); + uni.showModal({ title: '提示', content: message, showCancel: false }); + }, + showSuccess(message) { + util.playSuccessAudio(); + uni.showToast({ title: message, icon: 'success' }); + }, + }, +}; diff --git a/src/pages/storegoods/storeGoodsPurchaseInView.vue b/src/pages/storegoods/storeGoodsPurchaseInView.vue new file mode 100644 index 0000000..de3fdfa --- /dev/null +++ b/src/pages/storegoods/storeGoodsPurchaseInView.vue @@ -0,0 +1,153 @@ + + + + + diff --git a/src/pages/sys/workbench/index.vue b/src/pages/sys/workbench/index.vue index ea577e0..9cd7a3c 100644 --- a/src/pages/sys/workbench/index.vue +++ b/src/pages/sys/workbench/index.vue @@ -45,6 +45,12 @@ 加工退货进仓 + + + + + 采购进仓 +