From 7db6c121bb6e788bf4b05a0772a510cdcb3d9ed1 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 23 Aug 2023 15:04:46 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=AE=8C=E5=96=84=20code=20review=20?= =?UTF-8?q?=E6=8F=90=E5=88=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/mall/product/spu.ts | 11 +- src/api/mall/trade/order/index.ts | 14 +-- src/router/modules/remaining.ts | 4 +- src/utils/dict.ts | 4 +- src/utils/index.ts | 26 ++++- src/views/mall/product/property/index.vue | 3 +- src/views/mall/product/spu/addForm.vue | 32 ++++-- .../mall/product/spu/components/index.ts | 1 - src/views/mall/product/spu/index.vue | 20 ++-- .../seckill/activity/SeckillActivityForm.vue | 12 -- ...eryOrderForm.vue => OrderDeliveryForm.vue} | 24 ++-- ...essForm.vue => OrderUpdateAddressForm.vue} | 40 +++++-- ...PriceForm.vue => OrderUpdatePriceForm.vue} | 6 +- ...arksForm.vue => OrderUpdateRemarkForm.vue} | 14 ++- .../OrderDetailForm.vue => detail/index.vue} | 108 ++++++------------ src/views/mall/trade/order/index.vue | 54 +++++---- 16 files changed, 184 insertions(+), 189 deletions(-) rename src/views/mall/trade/order/components/{DeliveryOrderForm.vue => OrderDeliveryForm.vue} (77%) rename src/views/mall/trade/order/components/{OrderAdjustAddressForm.vue => OrderUpdateAddressForm.vue} (67%) rename src/views/mall/trade/order/components/{OrderAdjustPriceForm.vue => OrderUpdatePriceForm.vue} (93%) rename src/views/mall/trade/order/components/{OrderRemarksForm.vue => OrderUpdateRemarkForm.vue} (84%) rename src/views/mall/trade/order/{components/OrderDetailForm.vue => detail/index.vue} (79%) diff --git a/src/api/mall/product/spu.ts b/src/api/mall/product/spu.ts index 0ea324b8..2ad9bc60 100644 --- a/src/api/mall/product/spu.ts +++ b/src/api/mall/product/spu.ts @@ -9,18 +9,19 @@ export interface Property { export interface Sku { id?: number // 商品 SKU 编号 + name?: string // 商品 SKU 名称 spuId?: number // SPU 编号 properties?: Property[] // 属性数组 - price?: number // 商品价格 - marketPrice?: number // 市场价 - costPrice?: number // 成本价 + price?: number | string // 商品价格 + marketPrice?: number | string // 市场价 + costPrice?: number | string // 成本价 barCode?: string // 商品条码 picUrl?: string // 图片地址 stock?: number // 库存 weight?: number // 商品重量,单位:kg 千克 volume?: number // 商品体积,单位:m^3 平米 - subCommissionFirstPrice?: number // 一级分销的佣金 - subCommissionSecondPrice?: number // 二级分销的佣金 + subCommissionFirstPrice?: number | string // 一级分销的佣金 + subCommissionSecondPrice?: number | string // 二级分销的佣金 salesCount?: number // 商品销量 } diff --git a/src/api/mall/trade/order/index.ts b/src/api/mall/trade/order/index.ts index e99b1338..9413b73c 100644 --- a/src/api/mall/trade/order/index.ts +++ b/src/api/mall/trade/order/index.ts @@ -102,20 +102,20 @@ export interface DeliveryVO { // 订单发货 export const delivery = async (data: DeliveryVO) => { - return await request.post({ url: `/trade/order/delivery`, data }) + return await request.put({ url: `/trade/order/delivery`, data }) } // 订单备注 -export const remark = async (data) => { - return await request.post({ url: `/trade/order/remark`, data }) +export const updateRemark = async (data: any) => { + return await request.put({ url: `/trade/order/update-remark`, data }) } // 订单调价 -export const adjustPrice = async (data) => { - return await request.post({ url: `/trade/order/adjust-price`, data }) +export const updatePrice = async (data: any) => { + return await request.put({ url: `/trade/order/update-price`, data }) } // 修改订单地址 -export const adjustAddress = async (data) => { - return await request.post({ url: `/trade/order/adjust-address`, data }) +export const updateAddress = async (data: any) => { + return await request.put({ url: `/trade/order/update-address`, data }) } diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts index 2d8e2b44..6f31a882 100644 --- a/src/router/modules/remaining.ts +++ b/src/router/modules/remaining.ts @@ -347,7 +347,7 @@ const remainingRouter: AppRouteRecordRaw[] = [ ] }, { - path: '/property', // TODO @puhui999:这里的 path 有问题,应该是 /product/property + path: '/product/property', component: Layout, name: 'Property', meta: { @@ -421,7 +421,7 @@ const remainingRouter: AppRouteRecordRaw[] = [ children: [ { path: 'detail/:orderId(\\d+)', - component: () => import('@/views/mall/trade/order/components/OrderDetailForm.vue'), + component: () => import('@/views/mall/trade/order/detail/index.vue'), name: 'TradeOrderDetailForm', meta: { title: '订单详情', icon: '', activeMenu: '/trade/trade/order' } } diff --git a/src/utils/dict.ts b/src/utils/dict.ts index 9ec2e994..04d29c96 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -131,7 +131,7 @@ export enum DICT_TYPE { BPM_OA_LEAVE_TYPE = 'bpm_oa_leave_type', // ========== PAY 模块 ========== - PAY_CHANNEL_CODE = 'pay_channel_code', // 支付渠道编码类型 + PAY_CHANNEL_CODE = 'pay_channel_code_type', // 支付渠道编码类型 PAY_ORDER_STATUS = 'pay_order_status', // 商户支付订单状态 PAY_REFUND_STATUS = 'pay_refund_status', // 退款订单状态 PAY_NOTIFY_STATUS = 'pay_notify_status', // 商户支付回调状态 @@ -156,7 +156,7 @@ export enum DICT_TYPE { TRADE_ORDER_TYPE = 'trade_order_type', // 订单 - 类型 TRADE_ORDER_STATUS = 'trade_order_status', // 订单 - 状态 TRADE_ORDER_ITEM_AFTER_SALE_STATUS = 'trade_order_item_after_sale_status', // 订单项 - 售后状态 - TRADE_DELIVERY_TYPE = 'trade_delivery_type', // 配送方式 + TRADE_DELIVERY_TYPE = 'delivery_type', // 配送方式 // ========== MALL - 营销模块 ========== PROMOTION_DISCOUNT_TYPE = 'promotion_discount_type', // 优惠类型 diff --git a/src/utils/index.ts b/src/utils/index.ts index 3d596a36..c73b8d2f 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -174,7 +174,6 @@ export const copyValueToTarget = (target, source) => { Object.assign(target, newObj) } -// TODO @puhui999:返回要带上 .00 哈.例如说 1.00 /** * 将一个整数转换为分数保留两位小数 * @param num @@ -185,6 +184,31 @@ export const formatToFraction = (num: number | string | undefined): number => { return parseFloat((parsedNumber / 100).toFixed(2)) } +/** + * 将一个数转换为 1.00 这样 + * 数据呈现的时候使用 + * + * @param num 整数 + */ +export const floatToFixed2 = (num: number | string | undefined): string => { + let str = '0.00' + if (typeof num === 'undefined') { + return str + } + const f = formatToFraction(num) + const decimalPart = f.toString().split('.')[1] + const len = decimalPart ? decimalPart.length : 0 + switch (len) { + case 0: + str = f.toString() + '.00' + break + case 1: + str = f.toString() + '0' + break + } + return str +} + /** * 将一个分数转换为整数 * @param num diff --git a/src/views/mall/product/property/index.vue b/src/views/mall/product/property/index.vue index dc79450b..042bc980 100644 --- a/src/views/mall/product/property/index.vue +++ b/src/views/mall/product/property/index.vue @@ -101,6 +101,7 @@ import { dateFormatter } from '@/utils/formatTime' import * as PropertyApi from '@/api/mall/product/property' import PropertyForm from './PropertyForm.vue' + const { push } = useRouter() defineOptions({ name: 'ProductProperty' }) @@ -164,7 +165,7 @@ const handleDelete = async (id: number) => { /** 跳转商品属性列表 */ const goValueList = (id: number) => { - push({ path: '/property/value/' + id }) + push({ path: '/product/property/value/' + id }) } /** 初始化 **/ diff --git a/src/views/mall/product/spu/addForm.vue b/src/views/mall/product/spu/addForm.vue index b577ece9..b1c50929 100644 --- a/src/views/mall/product/spu/addForm.vue +++ b/src/views/mall/product/spu/addForm.vue @@ -42,7 +42,7 @@ import { useTagsViewStore } from '@/store/modules/tagsView' import { BasicInfoForm, DescriptionForm, OtherSettingsForm } from './components' // 业务api import * as ProductSpuApi from '@/api/mall/product/spu' -import { convertToInteger, formatToFraction } from '@/utils' +import { convertToInteger, floatToFixed2, formatToFraction } from '@/utils' defineOptions({ name: 'ProductSpuForm' }) @@ -107,12 +107,20 @@ const getDetail = async () => { try { const res = (await ProductSpuApi.getSpu(id)) as ProductSpuApi.Spu res.skus?.forEach((item) => { - // 回显价格分转元 - item.price = formatToFraction(item.price) - item.marketPrice = formatToFraction(item.marketPrice) - item.costPrice = formatToFraction(item.costPrice) - item.subCommissionFirstPrice = formatToFraction(item.subCommissionFirstPrice) - item.subCommissionSecondPrice = formatToFraction(item.subCommissionSecondPrice) + if (isDetail.value === true) { + item.price = floatToFixed2(item.price) + item.marketPrice = floatToFixed2(item.marketPrice) + item.costPrice = floatToFixed2(item.costPrice) + item.subCommissionFirstPrice = floatToFixed2(item.subCommissionFirstPrice) + item.subCommissionSecondPrice = floatToFixed2(item.subCommissionSecondPrice) + } else { + // 回显价格分转元 + item.price = formatToFraction(item.price) + item.marketPrice = formatToFraction(item.marketPrice) + item.costPrice = formatToFraction(item.costPrice) + item.subCommissionFirstPrice = formatToFraction(item.subCommissionFirstPrice) + item.subCommissionSecondPrice = formatToFraction(item.subCommissionSecondPrice) + } }) formData.value = res } finally { @@ -132,19 +140,19 @@ const submitForm = async () => { await unref(descriptionRef)?.validate() await unref(otherSettingsRef)?.validate() // 深拷贝一份, 这样最终 server 端不满足,不需要恢复, - const deepCopyFormData = cloneDeep(unref(formData.value)) + const deepCopyFormData = cloneDeep(unref(formData.value)) as ProductSpuApi.Spu // 兜底处理 sku 空数据 formData.value.skus!.forEach((sku) => { // 因为是空数据这里判断一下商品条码是否为空就行 if (sku.barCode === '') { - const index = deepCopyFormData.skus.findIndex( + const index = deepCopyFormData.skus!.findIndex( (item) => JSON.stringify(item.properties) === JSON.stringify(sku.properties) ) // 删除这条 sku - deepCopyFormData.skus.splice(index, 1) + deepCopyFormData.skus!.splice(index, 1) } }) - deepCopyFormData.skus.forEach((item) => { + deepCopyFormData.skus!.forEach((item) => { // 给sku name赋值 item.name = deepCopyFormData.name // sku相关价格元转分 @@ -156,7 +164,7 @@ const submitForm = async () => { }) // 处理轮播图列表 const newSliderPicUrls: any[] = [] - deepCopyFormData.sliderPicUrls.forEach((item: any) => { + deepCopyFormData.sliderPicUrls!.forEach((item: any) => { // 如果是前端选的图 typeof item === 'object' ? newSliderPicUrls.push(item.url) : newSliderPicUrls.push(item) }) diff --git a/src/views/mall/product/spu/components/index.ts b/src/views/mall/product/spu/components/index.ts index 1160dbd1..405dfde5 100644 --- a/src/views/mall/product/spu/components/index.ts +++ b/src/views/mall/product/spu/components/index.ts @@ -7,7 +7,6 @@ import SkuList from './SkuList.vue' import { Spu } from '@/api/mall/product/spu' -// TODO @puhui999:Properties 改成 Property 更合适?Property 在 Spu 中已存在避免冲突 PropertyAndValues interface PropertyAndValues { id: number name: string diff --git a/src/views/mall/product/spu/index.vue b/src/views/mall/product/spu/index.vue index 75bd02e0..9ea06cd5 100644 --- a/src/views/mall/product/spu/index.vue +++ b/src/views/mall/product/spu/index.vue @@ -80,7 +80,7 @@