diff --git a/src/api/pricingTable.js b/src/api/pricingTable.js index a4fc0af..bc7fc9a 100644 --- a/src/api/pricingTable.js +++ b/src/api/pricingTable.js @@ -1,5 +1,10 @@ import request from '@/utils/request' -import { orgTaxTypeLabel } from '@/constants/orgTaxType' +import { + ORG_TAX_TYPE_GENERAL, + ORG_TAX_TYPE_RECEIPT, + ORG_TAX_TYPE_SMALL, + orgTaxTypeLabel, +} from '@/constants/orgTaxType' import { pickGoodsNameFromListedRow } from '@/utils/goodsCategorys' function str(v) { @@ -26,6 +31,18 @@ export const PRICING_TAXPAYER_BY_ORG = { export const PRICING_TAXPAYER_DEFAULT = 'GENERAL' +/** 成本围栏 Tab key → 保存接口 org_type(1 一般 / 2 小规模 / 3 收据) */ +export const PRICING_TAXPAYER_ORG_TYPE = { + GENERAL: ORG_TAX_TYPE_GENERAL, + SMALL: ORG_TAX_TYPE_SMALL, + INDIVIDUAL: ORG_TAX_TYPE_RECEIPT, +} + +export function pricingTaxpayerTypeToOrgType(taxpayerType) { + const key = str(taxpayerType).toUpperCase() + return PRICING_TAXPAYER_ORG_TYPE[key] ?? null +} + const PRICING_TAXPAYER_KEYS = new Set(PRICING_TAXPAYER_TABS.map((t) => t.key)) /** 接口 data.list */ @@ -41,6 +58,81 @@ function unwrapPricingTableList(res) { return [] } +/** 成本价上限:0 或未设视为无勾选(后端默认 0) */ +export function normalizePricingTableCostPriceBound(value) { + if (value == null || value === '') return null + const n = Number(value) + if (!Number.isFinite(n) || n <= 0) return null + return n +} + +/** 纳税身份 Tab → 定价表 / RDC 成本价上限字段 */ +export const PRICING_COST_PRICE_BOUND_FIELDS = { + GENERAL: 'general_cost_price_bound', + SMALL: 'small_cost_price_bound', + INDIVIDUAL: 'individual_cost_price_bound', +} + +export function emptyPricingTableCostPriceBounds() { + return { + GENERAL: null, + SMALL: null, + INDIVIDUAL: null, + } +} + +function pricingTableCostPriceBoundSources(res, list = []) { + const envelope = res?.data ?? res + const payload = envelope?.data ?? envelope + const sources = [payload, envelope, res].filter((s) => s && typeof s === 'object' && !Array.isArray(s)) + for (const row of list) { + if (row && typeof row === 'object') sources.push(row) + } + return sources +} + +/** 定价表响应中的 RDC 物料成本价上限(三种纳税身份各一) */ +export function pickPricingTableCostPriceBounds(res, list = [], { taxpayer_type = '' } = {}) { + const bounds = emptyPricingTableCostPriceBounds() + const sources = pricingTableCostPriceBoundSources(res, list) + + for (const [key, field] of Object.entries(PRICING_COST_PRICE_BOUND_FIELDS)) { + for (const src of sources) { + const n = pickMoney(src, field) + if (n != null) { + bounds[key] = normalizePricingTableCostPriceBound(n) + break + } + } + } + + const legacyKey = str(taxpayer_type).toUpperCase() + if (legacyKey && PRICING_TAXPAYER_KEYS.has(legacyKey) && bounds[legacyKey] == null) { + for (const src of sources) { + const n = pickMoney(src, 'cost_price_bound') + if (n != null) { + bounds[legacyKey] = normalizePricingTableCostPriceBound(n) + break + } + } + } + + return bounds +} + +/** 指定纳税身份的成本价上限 */ +export function pickPricingTableCostPriceBoundForType(bounds, taxpayerType) { + const key = str(taxpayerType).toUpperCase() + if (!key || !PRICING_TAXPAYER_KEYS.has(key)) return null + return normalizePricingTableCostPriceBound(bounds?.[key]) +} + +/** @deprecated 请用 pickPricingTableCostPriceBounds + pickPricingTableCostPriceBoundForType */ +export function pickPricingTableCostPriceBound(res, list = [], taxpayerType = '') { + const bounds = pickPricingTableCostPriceBounds(res, list, { taxpayer_type: taxpayerType }) + return pickPricingTableCostPriceBoundForType(bounds, taxpayerType) +} + function pickText(raw, ...keys) { for (const k of keys) { const v = raw[k] @@ -92,6 +184,7 @@ export function normalizePricingTableRow(raw, idx = 0) { const supplier_org_type = pickRate(raw, 'supplier_org_type') const supplier_org_type_label = orgTaxTypeLabel(supplier_org_type) || null const goods_name = pickGoodsNameFromListedRow(raw) || pickText(raw, 'goods_name') + const pre_price = pickMoney(raw, 'pre_price') const bill_type = pickText(raw, 'bill_name', 'bill_type') const input_tax_rate = pickRate(raw, 'bill_tax', 'input_tax_rate') const source_company_name = pickText(raw, 'receive_company_name', 'source_company_name') @@ -121,11 +214,20 @@ export function normalizePricingTableRow(raw, idx = 0) { ) const fence_value = pickMoney(raw, 'fence_price', 'fence_value') const bloc = pickText(raw, 'supplier_bloc_code') - const supplier_company_code = pickText(raw, 'supplier_company_code', 'company_code') + const supplier_company_code = pickPricingTableRowSupplierCompanyCode(raw) const supply_collection_code = pickText(raw, 'supply_collection_code', 'collection_code') + const explicitKey = pickText(raw, 'key', 'id') + const rowKey = explicitKey ?? [ + bloc || 'bloc', + supplier_company_code || `sup-${idx}`, + receive_company_code || `rcv-${idx}`, + source_warehouse_code || '', + supply_collection_code || '', + ].filter(Boolean).join('-') + return { - key: pickText(raw, 'key', 'id') ?? `${bloc || 'bloc'}-${supplier_company_code || idx}`, + key: rowKey, supplier_bloc_name, supplier_company_name, supplier_company_display: formatCompanyNameWithOrgType(supplier_company_name, supplier_org_type_label), @@ -134,6 +236,7 @@ export function normalizePricingTableRow(raw, idx = 0) { supplier_company_code, supply_collection_code, goods_name, + pre_price, bill_type, input_tax_rate, source_company_name, @@ -150,9 +253,22 @@ export function normalizePricingTableRow(raw, idx = 0) { source_rdc_name: source_warehouse_name, source_rdc_code: source_warehouse_code, fence_value, + raw, } } +/** 定价表行 → 供货组织编码(围栏值 ? debug 请求用) */ +export function pickPricingTableRowSupplierCompanyCode(row) { + const raw = row?.raw && typeof row.raw === 'object' ? row.raw : row + if (!raw || typeof raw !== 'object') return '' + return pickText( + raw, + 'supplier_company_code', + 'supply_company_code', + 'supplier_org_code', + ) +} + /** * 组装 POST /api/pricing/table 请求体 * @param {object} body @@ -197,9 +313,18 @@ export function buildPricingTablePayload(body = {}, opts = {}) { export async function pricingTableQuery(body = {}) { const payload = buildPricingTablePayload(body, { debug: false }) const res = await request.post('/api/pricing/table', payload) - return unwrapPricingTableList(res) + const list = unwrapPricingTableList(res) + const rows = list .map((row, idx) => normalizePricingTableRow(row, idx)) .filter(Boolean) + const cost_price_bounds = pickPricingTableCostPriceBounds(res, list, { + taxpayer_type: payload.taxpayer_type, + }) + return { + rows, + cost_price_bounds, + cost_price_bound: pickPricingTableCostPriceBoundForType(cost_price_bounds, payload.taxpayer_type), + } } /** diff --git a/src/api/warehouseRdc.js b/src/api/warehouseRdc.js index 4c852b8..35eacab 100755 --- a/src/api/warehouseRdc.js +++ b/src/api/warehouseRdc.js @@ -388,6 +388,29 @@ export function warehouseRdcSetZone(body) { return request.post('/api/warehouse/rdc/set_zone', payload) } +/** POST /api/warehouse/rdc/set_cost_price_bound — body: { warehouse_code, goods_code, org_type, cost_price_bound } */ +export function warehouseRdcSetCostPriceBound(body) { + const warehouse_code = String(body?.warehouse_code ?? '').trim() + const goods_code = String(body?.goods_code ?? '').trim() + const org_type = Number(body?.org_type) + const cost_price_bound = Number(body?.cost_price_bound) + if (!warehouse_code || !goods_code) { + return Promise.reject(new Error('set_cost_price_bound 缺少 warehouse_code / goods_code')) + } + if (!Number.isFinite(org_type) || org_type < 1 || org_type > 3) { + return Promise.reject(new Error('set_cost_price_bound 缺少有效 org_type(1/2/3)')) + } + if (!Number.isFinite(cost_price_bound)) { + return Promise.reject(new Error('set_cost_price_bound 缺少有效 cost_price_bound')) + } + return request.post('/api/warehouse/rdc/set_cost_price_bound', { + warehouse_code, + goods_code, + org_type, + cost_price_bound, + }) +} + /** POST /api/warehouse/rdc/match_zone — body: { warehouse_code, goods_code } */ export async function warehouseRdcMatchZone(body) { const warehouse_code = String(body?.warehouse_code ?? '').trim() diff --git a/src/components/global-tab/GlobalTabCostPanel.vue b/src/components/global-tab/GlobalTabCostPanel.vue index d12b303..d81bf82 100644 --- a/src/components/global-tab/GlobalTabCostPanel.vue +++ b/src/components/global-tab/GlobalTabCostPanel.vue @@ -57,64 +57,96 @@
暂无围栏数据