Skip to content

Commit 7db6c12

Browse files
author
puhui999
committed
完善 code review 提到的问题
1 parent 55772cb commit 7db6c12

File tree

16 files changed

+184
-189
lines changed

16 files changed

+184
-189
lines changed

src/api/mall/product/spu.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ export interface Property {
99

1010
export interface Sku {
1111
id?: number // 商品 SKU 编号
12+
name?: string // 商品 SKU 名称
1213
spuId?: number // SPU 编号
1314
properties?: Property[] // 属性数组
14-
price?: number // 商品价格
15-
marketPrice?: number // 市场价
16-
costPrice?: number // 成本价
15+
price?: number | string // 商品价格
16+
marketPrice?: number | string // 市场价
17+
costPrice?: number | string // 成本价
1718
barCode?: string // 商品条码
1819
picUrl?: string // 图片地址
1920
stock?: number // 库存
2021
weight?: number // 商品重量,单位:kg 千克
2122
volume?: number // 商品体积,单位:m^3 平米
22-
subCommissionFirstPrice?: number // 一级分销的佣金
23-
subCommissionSecondPrice?: number // 二级分销的佣金
23+
subCommissionFirstPrice?: number | string // 一级分销的佣金
24+
subCommissionSecondPrice?: number | string // 二级分销的佣金
2425
salesCount?: number // 商品销量
2526
}
2627

src/api/mall/trade/order/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@ export interface DeliveryVO {
102102

103103
// 订单发货
104104
export const delivery = async (data: DeliveryVO) => {
105-
return await request.post({ url: `/trade/order/delivery`, data })
105+
return await request.put({ url: `/trade/order/delivery`, data })
106106
}
107107

108108
// 订单备注
109-
export const remark = async (data) => {
110-
return await request.post({ url: `/trade/order/remark`, data })
109+
export const updateRemark = async (data: any) => {
110+
return await request.put({ url: `/trade/order/update-remark`, data })
111111
}
112112

113113
// 订单调价
114-
export const adjustPrice = async (data) => {
115-
return await request.post({ url: `/trade/order/adjust-price`, data })
114+
export const updatePrice = async (data: any) => {
115+
return await request.put({ url: `/trade/order/update-price`, data })
116116
}
117117

118118
// 修改订单地址
119-
export const adjustAddress = async (data) => {
120-
return await request.post({ url: `/trade/order/adjust-address`, data })
119+
export const updateAddress = async (data: any) => {
120+
return await request.put({ url: `/trade/order/update-address`, data })
121121
}

src/router/modules/remaining.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
347347
]
348348
},
349349
{
350-
path: '/property', // TODO @puhui999:这里的 path 有问题,应该是 /product/property
350+
path: '/product/property',
351351
component: Layout,
352352
name: 'Property',
353353
meta: {
@@ -421,7 +421,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
421421
children: [
422422
{
423423
path: 'detail/:orderId(\\d+)',
424-
component: () => import('@/views/mall/trade/order/components/OrderDetailForm.vue'),
424+
component: () => import('@/views/mall/trade/order/detail/index.vue'),
425425
name: 'TradeOrderDetailForm',
426426
meta: { title: '订单详情', icon: '', activeMenu: '/trade/trade/order' }
427427
}

src/utils/dict.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export enum DICT_TYPE {
131131
BPM_OA_LEAVE_TYPE = 'bpm_oa_leave_type',
132132

133133
// ========== PAY 模块 ==========
134-
PAY_CHANNEL_CODE = 'pay_channel_code', // 支付渠道编码类型
134+
PAY_CHANNEL_CODE = 'pay_channel_code_type', // 支付渠道编码类型
135135
PAY_ORDER_STATUS = 'pay_order_status', // 商户支付订单状态
136136
PAY_REFUND_STATUS = 'pay_refund_status', // 退款订单状态
137137
PAY_NOTIFY_STATUS = 'pay_notify_status', // 商户支付回调状态
@@ -156,7 +156,7 @@ export enum DICT_TYPE {
156156
TRADE_ORDER_TYPE = 'trade_order_type', // 订单 - 类型
157157
TRADE_ORDER_STATUS = 'trade_order_status', // 订单 - 状态
158158
TRADE_ORDER_ITEM_AFTER_SALE_STATUS = 'trade_order_item_after_sale_status', // 订单项 - 售后状态
159-
TRADE_DELIVERY_TYPE = 'trade_delivery_type', // 配送方式
159+
TRADE_DELIVERY_TYPE = 'delivery_type', // 配送方式
160160

161161
// ========== MALL - 营销模块 ==========
162162
PROMOTION_DISCOUNT_TYPE = 'promotion_discount_type', // 优惠类型

src/utils/index.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ export const copyValueToTarget = (target, source) => {
174174
Object.assign(target, newObj)
175175
}
176176

177-
// TODO @puhui999:返回要带上 .00 哈.例如说 1.00
178177
/**
179178
* 将一个整数转换为分数保留两位小数
180179
* @param num
@@ -185,6 +184,31 @@ export const formatToFraction = (num: number | string | undefined): number => {
185184
return parseFloat((parsedNumber / 100).toFixed(2))
186185
}
187186

187+
/**
188+
* 将一个数转换为 1.00 这样
189+
* 数据呈现的时候使用
190+
*
191+
* @param num 整数
192+
*/
193+
export const floatToFixed2 = (num: number | string | undefined): string => {
194+
let str = '0.00'
195+
if (typeof num === 'undefined') {
196+
return str
197+
}
198+
const f = formatToFraction(num)
199+
const decimalPart = f.toString().split('.')[1]
200+
const len = decimalPart ? decimalPart.length : 0
201+
switch (len) {
202+
case 0:
203+
str = f.toString() + '.00'
204+
break
205+
case 1:
206+
str = f.toString() + '0'
207+
break
208+
}
209+
return str
210+
}
211+
188212
/**
189213
* 将一个分数转换为整数
190214
* @param num

src/views/mall/product/property/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
import { dateFormatter } from '@/utils/formatTime'
102102
import * as PropertyApi from '@/api/mall/product/property'
103103
import PropertyForm from './PropertyForm.vue'
104+
104105
const { push } = useRouter()
105106
106107
defineOptions({ name: 'ProductProperty' })
@@ -164,7 +165,7 @@ const handleDelete = async (id: number) => {
164165
165166
/** 跳转商品属性列表 */
166167
const goValueList = (id: number) => {
167-
push({ path: '/property/value/' + id })
168+
push({ path: '/product/property/value/' + id })
168169
}
169170
170171
/** 初始化 **/

src/views/mall/product/spu/addForm.vue

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { useTagsViewStore } from '@/store/modules/tagsView'
4242
import { BasicInfoForm, DescriptionForm, OtherSettingsForm } from './components'
4343
// 业务api
4444
import * as ProductSpuApi from '@/api/mall/product/spu'
45-
import { convertToInteger, formatToFraction } from '@/utils'
45+
import { convertToInteger, floatToFixed2, formatToFraction } from '@/utils'
4646
4747
defineOptions({ name: 'ProductSpuForm' })
4848
@@ -107,12 +107,20 @@ const getDetail = async () => {
107107
try {
108108
const res = (await ProductSpuApi.getSpu(id)) as ProductSpuApi.Spu
109109
res.skus?.forEach((item) => {
110-
// 回显价格分转元
111-
item.price = formatToFraction(item.price)
112-
item.marketPrice = formatToFraction(item.marketPrice)
113-
item.costPrice = formatToFraction(item.costPrice)
114-
item.subCommissionFirstPrice = formatToFraction(item.subCommissionFirstPrice)
115-
item.subCommissionSecondPrice = formatToFraction(item.subCommissionSecondPrice)
110+
if (isDetail.value === true) {
111+
item.price = floatToFixed2(item.price)
112+
item.marketPrice = floatToFixed2(item.marketPrice)
113+
item.costPrice = floatToFixed2(item.costPrice)
114+
item.subCommissionFirstPrice = floatToFixed2(item.subCommissionFirstPrice)
115+
item.subCommissionSecondPrice = floatToFixed2(item.subCommissionSecondPrice)
116+
} else {
117+
// 回显价格分转元
118+
item.price = formatToFraction(item.price)
119+
item.marketPrice = formatToFraction(item.marketPrice)
120+
item.costPrice = formatToFraction(item.costPrice)
121+
item.subCommissionFirstPrice = formatToFraction(item.subCommissionFirstPrice)
122+
item.subCommissionSecondPrice = formatToFraction(item.subCommissionSecondPrice)
123+
}
116124
})
117125
formData.value = res
118126
} finally {
@@ -132,19 +140,19 @@ const submitForm = async () => {
132140
await unref(descriptionRef)?.validate()
133141
await unref(otherSettingsRef)?.validate()
134142
// 深拷贝一份, 这样最终 server 端不满足,不需要恢复,
135-
const deepCopyFormData = cloneDeep(unref(formData.value))
143+
const deepCopyFormData = cloneDeep(unref(formData.value)) as ProductSpuApi.Spu
136144
// 兜底处理 sku 空数据
137145
formData.value.skus!.forEach((sku) => {
138146
// 因为是空数据这里判断一下商品条码是否为空就行
139147
if (sku.barCode === '') {
140-
const index = deepCopyFormData.skus.findIndex(
148+
const index = deepCopyFormData.skus!.findIndex(
141149
(item) => JSON.stringify(item.properties) === JSON.stringify(sku.properties)
142150
)
143151
// 删除这条 sku
144-
deepCopyFormData.skus.splice(index, 1)
152+
deepCopyFormData.skus!.splice(index, 1)
145153
}
146154
})
147-
deepCopyFormData.skus.forEach((item) => {
155+
deepCopyFormData.skus!.forEach((item) => {
148156
// 给sku name赋值
149157
item.name = deepCopyFormData.name
150158
// sku相关价格元转分
@@ -156,7 +164,7 @@ const submitForm = async () => {
156164
})
157165
// 处理轮播图列表
158166
const newSliderPicUrls: any[] = []
159-
deepCopyFormData.sliderPicUrls.forEach((item: any) => {
167+
deepCopyFormData.sliderPicUrls!.forEach((item: any) => {
160168
// 如果是前端选的图
161169
typeof item === 'object' ? newSliderPicUrls.push(item.url) : newSliderPicUrls.push(item)
162170
})

src/views/mall/product/spu/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import SkuList from './SkuList.vue'
77

88
import { Spu } from '@/api/mall/product/spu'
99

10-
// TODO @puhui999:Properties 改成 Property 更合适?Property 在 Spu 中已存在避免冲突 PropertyAndValues
1110
interface PropertyAndValues {
1211
id: number
1312
name: string

src/views/mall/product/spu/index.vue

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<el-table v-loading="loading" :data="list">
8181
<el-table-column type="expand" width="30">
8282
<template #default="{ row }">
83-
<el-form class="demo-table-expand" label-position="left">
83+
<el-form class="spu-table-expand" label-position="left">
8484
<el-row>
8585
<el-col :span="24">
8686
<el-row>
@@ -91,12 +91,12 @@
9191
</el-col>
9292
<el-col :span="8">
9393
<el-form-item label="市场价:">
94-
<span>{{ formatToFraction(row.marketPrice) }}</span>
94+
<span>{{ floatToFixed2(row.marketPrice) }}</span>
9595
</el-form-item>
9696
</el-col>
9797
<el-col :span="8">
9898
<el-form-item label="成本价:">
99-
<span>{{ formatToFraction(row.costPrice) }}</span>
99+
<span>{{ floatToFixed2(row.costPrice) }}</span>
100100
</el-form-item>
101101
</el-col>
102102
</el-row>
@@ -130,9 +130,7 @@
130130
</el-table-column>
131131
<el-table-column :show-overflow-tooltip="true" label="商品名称" min-width="300" prop="name" />
132132
<el-table-column align="center" label="商品售价" min-width="90" prop="price">
133-
<template #default="{ row }">
134-
{{ formatToFraction(row.price) }}
135-
</template>
133+
<template #default="{ row }"> {{ floatToFixed2(row.price) }}元</template>
136134
</el-table-column>
137135
<el-table-column align="center" label="销量" min-width="90" prop="salesCount" />
138136
<el-table-column align="center" label="库存" min-width="90" prop="stock" />
@@ -229,7 +227,7 @@ import { createImageViewer } from '@/components/ImageViewer'
229227
import { dateFormatter } from '@/utils/formatTime'
230228
import { checkSelectedNode, defaultProps, handleTree, treeToString } from '@/utils/tree'
231229
import { ProductSpuStatusEnum } from '@/utils/constants'
232-
import { formatToFraction } from '@/utils'
230+
import { floatToFixed2 } from '@/utils'
233231
import download from '@/utils/download'
234232
import * as ProductSpuApi from '@/api/mall/product/spu'
235233
import * as ProductCategoryApi from '@/api/mall/product/category'
@@ -392,7 +390,7 @@ const resetQuery = () => {
392390
const openForm = (id?: number) => {
393391
// 修改
394392
if (typeof id === 'number') {
395-
push('/product/spu/edit/' + id)
393+
push({ name: 'ProductSpuEdit', params: { spuId: id } })
396394
return
397395
}
398396
// 新增
@@ -402,8 +400,8 @@ const openForm = (id?: number) => {
402400
/**
403401
* 查看商品详情
404402
*/
405-
const openDetail = (id?: number) => {
406-
push('/product/spu/detail/' + id)
403+
const openDetail = (id: number) => {
404+
push({ name: 'ProductSpuDetail', params: { spuId: id } })
407405
}
408406
409407
/** 导出按钮操作 */
@@ -458,7 +456,7 @@ onMounted(async () => {
458456
})
459457
</script>
460458
<style lang="scss" scoped>
461-
.demo-table-expand {
459+
.spu-table-expand {
462460
padding-left: 42px;
463461
464462
:deep(.el-form-item__label) {

src/views/mall/promotion/seckill/activity/SeckillActivityForm.vue

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,4 @@ const resetForm = async () => {
193193
await nextTick()
194194
formRef.value.getElFormRef().resetFields()
195195
}
196-
// TODO @puhui999:下面的 css 名字,是不是可以改下;demo-table-expand
197196
</script>
198-
<style lang="scss" scoped>
199-
.demo-table-expand {
200-
padding-left: 42px;
201-
202-
:deep(.el-form-item__label) {
203-
width: 82px;
204-
font-weight: bold;
205-
color: #99a9bf;
206-
}
207-
}
208-
</style>

0 commit comments

Comments
 (0)