Commit dce56f71 authored by 前端-钟卫鹏's avatar 前端-钟卫鹏

fix:处理采购新建订单来自于商城下单商品数据显示异常

parent 8e6d9c5d
...@@ -8,6 +8,7 @@ import { useUpdate } from '@umijs/hooks'; ...@@ -8,6 +8,7 @@ import { useUpdate } from '@umijs/hooks';
import { PublicApi } from '@/services/api'; import { PublicApi } from '@/services/api';
import { filterProductDataById } from '../components/productModalTable' import { filterProductDataById } from '../components/productModalTable'
import { getUnitPriceTotal } from '../model/useProductTable'; import { getUnitPriceTotal } from '../model/useProductTable';
import { toPercent } from '@/utils/type';
// 异步填充表格字段 // 异步填充表格字段
const asyncPadDataForProduct = async (ctx: ISchemaFormActions | ISchemaFormAsyncActions, productValue: any) => { const asyncPadDataForProduct = async (ctx: ISchemaFormActions | ISchemaFormAsyncActions, productValue: any) => {
...@@ -176,6 +177,8 @@ export const useOrderFormInitEffect = (ctx: ISchemaFormActions | ISchemaFormAsyn ...@@ -176,6 +177,8 @@ export const useOrderFormInitEffect = (ctx: ISchemaFormActions | ISchemaFormAsyn
money: v.count * v.unitPrice, money: v.count * v.unitPrice,
productId: v.id, productId: v.id,
memberId: initValue.supplyMembersId, // 添加 memberId 字段 memberId: initValue.supplyMembersId, // 添加 memberId 字段
commodityId: v.id, // 添加commodityId用于判断是商品价格是使用price字段还是unitPrice字段(也可判断是报价订单还是其他)
memberPrice: v.memberDiscount !== 1 ? toPercent(v.memberDiscount) : 1, // 添加会员折扣
} }
}))) })))
} }
......
...@@ -7,14 +7,26 @@ import { useModalTable } from './useModalTable'; ...@@ -7,14 +7,26 @@ import { useModalTable } from './useModalTable';
import { usePageStatus, PageStatus } from '@/hooks/usePageStatus'; import { usePageStatus, PageStatus } from '@/hooks/usePageStatus';
import { toPoint } from '@/utils/type'; import { toPoint } from '@/utils/type';
// 对象按key排序(运用于商城传过来的阶梯价格排序)
export const sortByKey = (params) => {
let keys = Object.keys(params).sort((x,y)=> parseInt(x) - parseInt(y));
let newParams = {};
keys.forEach((key) => {
newParams[key] = params[key];
});
return newParams;
}
export const getUnitPriceTotal = (record) => { export const getUnitPriceTotal = (record) => {
const purchaseCount = Number(record['purchaseCount']) || 0 const purchaseCount = Number(record['purchaseCount']) || 0
console.log(record,purchaseCount,'rrr')
// fix 当没有传递unitPrice字段时 自动容错, 单价显示为0 // fix 当没有传递unitPrice字段时 自动容错, 单价显示为0
record.unitPrice = record.unitPrice || record.price || 0 record.unitPrice = record.unitPrice || record.price || 0
if (typeof record.unitPrice === 'number') { if (typeof record.unitPrice === 'number') {
return record.unitPrice * purchaseCount return record.unitPrice * purchaseCount
} }
if(record.unitPrice) {
record.unitPrice = sortByKey(record.unitPrice)
}
let unitPrice = 0 let unitPrice = 0
Object.entries(record.unitPrice).forEach(([key, value]) => { Object.entries(record.unitPrice).forEach(([key, value]) => {
const [min, max] = key.split('-').map(v => Number(v)) const [min, max] = key.split('-').map(v => Number(v))
...@@ -29,7 +41,6 @@ export const getUnitPriceTotal = (record) => { ...@@ -29,7 +41,6 @@ export const getUnitPriceTotal = (record) => {
} }
}) })
// 考虑会员折扣 // 考虑会员折扣
console.log('算价格', record.memberPrice)
let memberPrice = record.memberPrice !== 1 ? toPoint(record.memberPrice) : 1 let memberPrice = record.memberPrice !== 1 ? toPoint(record.memberPrice) : 1
return unitPrice * purchaseCount * memberPrice return unitPrice * purchaseCount * memberPrice
} }
......
...@@ -11,7 +11,8 @@ export const toPoint = (percent: string) => { ...@@ -11,7 +11,8 @@ export const toPoint = (percent: string) => {
// 小数转分数 // 小数转分数
export const toPercent = (point: number) => { export const toPercent = (point: number) => {
let str = Number(point * 100).toFixed(1); // let str = Number(point * 100).toFixed(1);
let str = Number(point * 100);
str += "%"; str += "%";
return str; return str;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment