Skip to content

Commit f07c74d

Browse files
committed
Merge remote-tracking branch 'origin/dev' into dev
2 parents e5ec820 + 1bd853b commit f07c74d

File tree

3 files changed

+85
-47
lines changed

3 files changed

+85
-47
lines changed

src/views/mall/product/spu/components/SkuList.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,17 @@
180180
</el-table-column>
181181
<el-table-column align="center" label="销售价(元)" min-width="80">
182182
<template #default="{ row }">
183-
{{ formatToFraction(row.price) }}
183+
{{ row.price }}
184184
</template>
185185
</el-table-column>
186186
<el-table-column align="center" label="市场价(元)" min-width="80">
187187
<template #default="{ row }">
188-
{{ formatToFraction(row.marketPrice) }}
188+
{{ row.marketPrice }}
189189
</template>
190190
</el-table-column>
191191
<el-table-column align="center" label="成本价(元)" min-width="80">
192192
<template #default="{ row }">
193-
{{ formatToFraction(row.costPrice) }}
193+
{{ row.costPrice }}
194194
</template>
195195
</el-table-column>
196196
<el-table-column align="center" label="库存" min-width="80">
@@ -211,12 +211,12 @@
211211
<template v-if="formData!.subCommissionType">
212212
<el-table-column align="center" label="一级返佣(元)" min-width="80">
213213
<template #default="{ row }">
214-
{{ formatToFraction(row.firstBrokeragePrice) }}
214+
{{ row.firstBrokeragePrice }}
215215
</template>
216216
</el-table-column>
217217
<el-table-column align="center" label="二级返佣(元)" min-width="80">
218218
<template #default="{ row }">
219-
{{ formatToFraction(row.secondBrokeragePrice) }}
219+
{{ row.secondBrokeragePrice }}
220220
</template>
221221
</el-table-column>
222222
</template>

src/views/mall/promotion/components/SpuAndSkuList.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
<el-table-column align="center" label="销量" min-width="90" prop="salesCount" />
3131
<el-table-column align="center" label="库存" min-width="90" prop="stock" />
3232
<el-table-column
33-
v-if="spuData.length > 1 && isDelete"
33+
v-if="spuData.length > 1 && deletable"
3434
align="center"
3535
label="操作"
3636
min-width="90"
3737
>
3838
<template #default="scope">
39-
<el-button type="primary" link @click="deleteSpu(scope.row.id)"> 删除 </el-button>
39+
<el-button link type="primary" @click="deleteSpu(scope.row.id)"> 删除</el-button>
4040
</template>
4141
</el-table-column>
4242
</el-table>
@@ -56,13 +56,13 @@ const props = defineProps<{
5656
spuList: T[]
5757
ruleConfig: RuleConfig[]
5858
spuPropertyListP: SpuProperty<T>[]
59-
isDelete?: boolean // SPU 是否可删除;TODO deletable 换成这个名字好点。
59+
deletable?: boolean // SPU 是否可删除;
6060
}>()
6161
6262
const spuData = ref<Spu[]>([]) // spu 详情数据列表
6363
const skuListRef = ref() // 商品属性列表Ref
6464
const spuPropertyList = ref<SpuProperty<T>[]>([]) // spuId 对应的 sku 的属性列表
65-
const expandRowKeys = ref<number[]>() // 控制展开行需要设置 row-key 属性才能使用,该属性为展开行的 keys 数组。
65+
const expandRowKeys = ref<string[]>([]) // 控制展开行需要设置 row-key 属性才能使用,该属性为展开行的 keys 数组。
6666
6767
/**
6868
* 获取所有 sku 活动配置
@@ -71,10 +71,10 @@ const expandRowKeys = ref<number[]>() // 控制展开行需要设置 row-key 属
7171
*/
7272
const getSkuConfigs = (extendedAttribute: string) => {
7373
skuListRef.value.validateSku()
74-
const seckillProducts = []
74+
const seckillProducts: any[] = []
7575
spuPropertyList.value.forEach((item) => {
76-
item.spuDetail.skus.forEach((sku) => {
77-
seckillProducts.push(sku[extendedAttribute])
76+
item.spuDetail.skus?.forEach((sku: any) => {
77+
seckillProducts.push(sku[extendedAttribute] as any)
7878
})
7979
})
8080
return seckillProducts
@@ -124,10 +124,10 @@ watch(
124124
() => props.spuPropertyListP,
125125
(data) => {
126126
if (!data) return
127-
spuPropertyList.value = data as SpuProperty<T>[]
127+
spuPropertyList.value = data as SpuProperty<T>[] as any
128128
// 解决如果之前选择的是单规格 spu 的话后面选择多规格 sku 多规格属性信息不展示的问题。解决方法:让 SkuList 组件重新渲染(行折叠会干掉包含的组件展开时会重新加载)
129129
setTimeout(() => {
130-
expandRowKeys.value = data.map((item) => item.spuId)
130+
expandRowKeys.value = data.map((item) => item.spuId + '')
131131
}, 200)
132132
},
133133
{

src/views/mall/promotion/discountActivity/DiscountActivityForm.vue

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,40 @@
88
:schema="allSchemas.formSchema"
99
>
1010
<!-- 先选择 -->
11-
<!-- TODO @zhangshuai:商品允许选择多个 -->
12-
<!-- TODO @zhangshuai:选择后的 SKU,需要后面加个【删除】按钮 -->
13-
<!-- TODO @zhangshuai:展示的金额,貌似不对,大了 100 倍,需要看下 -->
14-
<!-- TODO @zhangshuai:“优惠类型”,是每个 SKU 可以自定义已设置哈。因为每个商品 SKU 的折扣和减少价格,可能不同。具体交互,可以注册一个 youzan.com 看看;它的交互方式是,如果设置了“优惠金额”,则算“减价”;如果再次设置了“折扣百分比”,就算“打折”;这样形成一个互斥的优惠类型 -->
1511
<template #spuId>
1612
<el-button @click="spuSelectRef.open()">选择商品</el-button>
1713
<SpuAndSkuList
1814
ref="spuAndSkuListRef"
15+
:deletable="true"
1916
:rule-config="ruleConfig"
2017
:spu-list="spuList"
2118
:spu-property-list-p="spuPropertyList"
22-
:isDelete="true"
2319
@delete="deleteSpu"
2420
>
2521
<el-table-column align="center" label="优惠金额" min-width="168">
26-
<template #default="{ row: sku }">
27-
<el-input-number v-model="sku.productConfig.discountPrice" :min="0" class="w-100%" />
22+
<template #default="{ row }">
23+
<el-input-number
24+
v-model="row.productConfig.discountPrice"
25+
:max="parseFloat(fenToYuan(row.price))"
26+
:min="0"
27+
:precision="2"
28+
:step="0.1"
29+
class="w-100%"
30+
@change="handleSkuDiscountPriceChange(row)"
31+
/>
2832
</template>
2933
</el-table-column>
3034
<el-table-column align="center" label="折扣百分比(%)" min-width="168">
31-
<template #default="{ row: sku }">
32-
<el-input-number v-model="sku.productConfig.discountPercent" class="w-100%" />
35+
<template #default="{ row }">
36+
<el-input-number
37+
v-model="row.productConfig.discountPercent"
38+
:max="100"
39+
:min="0"
40+
:precision="2"
41+
:step="0.1"
42+
class="w-100%"
43+
@change="handleSkuDiscountPercentChange(row)"
44+
/>
3345
</template>
3446
</el-table-column>
3547
</SpuAndSkuList>
@@ -45,11 +57,12 @@
4557
<script lang="ts" setup>
4658
import { SpuAndSkuList, SpuProperty, SpuSelect } from '../components'
4759
import { allSchemas, rules } from './discountActivity.data'
48-
import { cloneDeep } from 'lodash-es'
60+
import { cloneDeep, debounce } from 'lodash-es'
4961
import * as DiscountActivityApi from '@/api/mall/promotion/discount/discountActivity'
5062
import * as ProductSpuApi from '@/api/mall/product/spu'
5163
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
52-
import { formatToFraction } from '@/utils'
64+
import { convertToInteger, erpCalculatePercentage, fenToYuan, yuanToFen } from '@/utils'
65+
import { PromotionDiscountTypeEnum } from '@/utils/constants'
5366
5467
defineOptions({ name: 'PromotionDiscountActivityForm' })
5568
@@ -65,11 +78,19 @@ const formRef = ref() // 表单 Ref
6578
6679
const spuSelectRef = ref() // 商品和属性选择 Ref
6780
const spuAndSkuListRef = ref() // sku 限时折扣 配置组件Ref
68-
const ruleConfig: RuleConfig[] = []
81+
const ruleConfig: RuleConfig[] = [
82+
{
83+
name: 'productConfig.discountPrice',
84+
rule: (arg) => arg > 0,
85+
message: '商品优惠金额不能为 0 !!!'
86+
}
87+
]
6988
const spuList = ref<DiscountActivityApi.SpuExtension[]>([]) // 选择的 spu
7089
const spuPropertyList = ref<SpuProperty<DiscountActivityApi.SpuExtension>[]>([])
7190
const spuIds = ref<number[]>([])
7291
const selectSpu = (spuId: number, skuIds: number[]) => {
92+
// TODO puhui999: 艿艿现在限时折扣活动可以选择多个 spu ,那么 spuId 是不是得改成 spuIds 来存放多个?🤣
93+
formRef.value.setValues({ spuId })
7394
getSpuDetails(spuId, skuIds)
7495
}
7596
/**
@@ -101,21 +122,20 @@ const getSpuDetails = async (
101122
selectSkus?.forEach((sku) => {
102123
let config: DiscountActivityApi.DiscountProductVO = {
103124
skuId: sku.id!,
104-
spuId: spu.id,
125+
spuId: spu.id!,
105126
discountType: 1,
106127
discountPercent: 0,
107128
discountPrice: 0
108129
}
109130
if (typeof products !== 'undefined') {
110131
const product = products.find((item) => item.skuId === sku.id)
132+
if (product) {
133+
product.discountPercent = fenToYuan(product.discountPercent) as any
134+
product.discountPrice = fenToYuan(product.discountPrice) as any
135+
}
111136
config = product || config
112137
}
113138
sku.productConfig = config
114-
sku.price = formatToFraction(sku.price)
115-
sku.marketPrice = formatToFraction(sku.marketPrice)
116-
sku.costPrice = formatToFraction(sku.costPrice)
117-
sku.firstBrokeragePrice = formatToFraction(sku.firstBrokeragePrice)
118-
sku.secondBrokeragePrice = formatToFraction(sku.secondBrokeragePrice)
119139
})
120140
spu.skus = selectSkus as DiscountActivityApi.SkuExtension[]
121141
spuPropertyList.value.push({
@@ -168,25 +188,13 @@ const submitForm = async () => {
168188
// 提交请求
169189
formLoading.value = true
170190
try {
171-
const data = formRef.value.formModel as DiscountActivityApi.DiscountActivityVO
172191
// 获取折扣商品配置
173192
const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig'))
174-
// 校验优惠金额、折扣百分比,是否正确
175-
// TODO @puhui999:这个交互,可以参考下 youzan 的
176-
let discountInvalid = false
177193
products.forEach((item: DiscountActivityApi.DiscountProductVO) => {
178-
if (item.discountPrice != null && item.discountPrice > 0) {
179-
item.discountType = 1
180-
} else if (item.discountPercent != null && item.discountPercent > 0) {
181-
item.discountType = 2
182-
} else {
183-
discountInvalid = true
184-
}
194+
item.discountPercent = convertToInteger(item.discountPercent)
195+
item.discountPrice = convertToInteger(item.discountPrice)
185196
})
186-
if (discountInvalid) {
187-
message.error('优惠金额和折扣百分比需要填写一个')
188-
return
189-
}
197+
const data = cloneDeep(formRef.value.formModel) as DiscountActivityApi.DiscountActivityVO
190198
data.products = products
191199
// 真正提交
192200
if (formType.value === 'create') {
@@ -204,6 +212,36 @@ const submitForm = async () => {
204212
}
205213
}
206214
215+
/** 处理 sku 优惠金额变动 */
216+
const handleSkuDiscountPriceChange = debounce((row: any) => {
217+
// 校验边界
218+
if (row.productConfig.discountPrice <= 0) {
219+
return
220+
}
221+
222+
// 设置优惠类型:满减
223+
row.productConfig.discountType = PromotionDiscountTypeEnum.PRICE.type
224+
// 设置折扣
225+
row.productConfig.discountPercent = erpCalculatePercentage(
226+
row.price - yuanToFen(row.productConfig.discountPrice),
227+
row.price
228+
)
229+
}, 200)
230+
/** 处理 sku 优惠折扣变动 */
231+
const handleSkuDiscountPercentChange = debounce((row: any) => {
232+
// 校验边界
233+
if (row.productConfig.discountPercent <= 0 || row.productConfig.discountPercent >= 100) {
234+
return
235+
}
236+
237+
// 设置优惠类型:折扣
238+
row.productConfig.discountType = PromotionDiscountTypeEnum.PERCENT.type
239+
// 设置满减金额
240+
row.productConfig.discountPrice = fenToYuan(
241+
row.price - row.price * (row.productConfig.discountPercent / 100.0 || 0)
242+
)
243+
}, 200)
244+
207245
/** 重置表单 */
208246
const resetForm = async () => {
209247
spuList.value = []

0 commit comments

Comments
 (0)