Skip to content

Commit 2434911

Browse files
YunaiVgitee-org
authored andcommitted
!529 【修改】修改限时折扣的一些问题
Merge pull request !529 from 痴货/dev
2 parents 1911ed9 + a06a509 commit 2434911

File tree

4 files changed

+84
-31
lines changed

4 files changed

+84
-31
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
</el-table-column>
3030
<el-table-column align="center" label="销量" min-width="90" prop="salesCount" />
3131
<el-table-column align="center" label="库存" min-width="90" prop="stock" />
32+
<el-table-column v-if="spuData.length > 1 && isDelete" align="center" label="操作" min-width="90" >
33+
<template #default="scope">
34+
<el-button
35+
type="primary"
36+
link
37+
@click="deleteSpu(scope.row.id)"
38+
>
39+
删除
40+
</el-button>
41+
</template>
42+
</el-table-column>
3243
</el-table>
3344
</template>
3445
<script generic="T extends Spu" lang="ts" setup>
@@ -40,10 +51,13 @@ import { SpuProperty } from '@/views/mall/promotion/components/index'
4051
4152
defineOptions({ name: 'PromotionSpuAndSkuList' })
4253
54+
const message = useMessage() // 消息弹窗
55+
4356
const props = defineProps<{
4457
spuList: T[]
4558
ruleConfig: RuleConfig[]
4659
spuPropertyListP: SpuProperty<T>[]
60+
isDelete?: boolean //spu是否可以多选
4761
}>()
4862
4963
const spuData = ref<Spu[]>([]) // spu 详情数据列表
@@ -77,6 +91,19 @@ const imagePreview = (imgUrl: string) => {
7791
})
7892
}
7993
94+
// 删除时的触发事件
95+
const emits = defineEmits<{
96+
(e: 'delete', spuId: number): void
97+
}>()
98+
99+
/** 多选时可以删除spu **/
100+
const deleteSpu = async (spuId: number) => {
101+
await message.confirm('是否删除商品编号为' + spuId + '的数据?')
102+
let index = spuData.value.findIndex((item) => item.id == spuId)
103+
spuData.value.splice(index,1);
104+
emits('delete',spuId)
105+
}
106+
80107
/**
81108
* 将传进来的值赋值给 skuList
82109
*/

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

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
:rule-config="ruleConfig"
2020
:spu-list="spuList"
2121
:spu-property-list-p="spuPropertyList"
22+
:isDelete="true"
23+
@delete="deleteSpu"
2224
>
2325
<el-table-column align="center" label="优惠金额" min-width="168">
2426
<template #default="{ row: sku }">
@@ -47,6 +49,7 @@ import { cloneDeep } from 'lodash-es'
4749
import * as DiscountActivityApi from '@/api/mall/promotion/discount/discountActivity'
4850
import * as ProductSpuApi from '@/api/mall/product/spu'
4951
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
52+
import {formatToFraction} from "@/utils";
5053
5154
defineOptions({ name: 'PromotionDiscountActivityForm' })
5255
@@ -65,8 +68,8 @@ const spuAndSkuListRef = ref() // sku 限时折扣 配置组件Ref
6568
const ruleConfig: RuleConfig[] = []
6669
const spuList = ref<DiscountActivityApi.SpuExtension[]>([]) // 选择的 spu
6770
const spuPropertyList = ref<SpuProperty<DiscountActivityApi.SpuExtension>[]>([])
71+
const spuIds = ref<number[]>([]);
6872
const selectSpu = (spuId: number, skuIds: number[]) => {
69-
formRef.value.setValues({ spuId })
7073
getSpuDetails(spuId, skuIds)
7174
}
7275
/**
@@ -75,14 +78,22 @@ const selectSpu = (spuId: number, skuIds: number[]) => {
7578
const getSpuDetails = async (
7679
spuId: number,
7780
skuIds: number[] | undefined,
78-
products?: DiscountActivityApi.DiscountProductVO[]
81+
products?: DiscountActivityApi.DiscountProductVO[],
82+
type?: string
7983
) => {
80-
const spuProperties: SpuProperty<DiscountActivityApi.SpuExtension>[] = []
84+
//如果已经包含spu则跳过
85+
if(spuIds.value.includes(spuId)){
86+
if(type !== "load"){
87+
message.error("数据重复选择!")
88+
}
89+
return;
90+
}
91+
spuIds.value.push(spuId)
8192
const res = (await ProductSpuApi.getSpuDetailList([spuId])) as DiscountActivityApi.SpuExtension[]
8293
if (res.length == 0) {
8394
return
8495
}
85-
spuList.value = []
96+
//spuList.value = []
8697
// 因为只能选择一个
8798
const spu = res[0]
8899
const selectSkus =
@@ -100,15 +111,19 @@ const getSpuDetails = async (
100111
config = product || config
101112
}
102113
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)
103119
})
104120
spu.skus = selectSkus as DiscountActivityApi.SkuExtension[]
105-
spuProperties.push({
121+
spuPropertyList.value.push({
106122
spuId: spu.id!,
107123
spuDetail: spu,
108124
propertyList: getPropertyList(spu)
109125
})
110126
spuList.value.push(spu)
111-
spuPropertyList.value = spuProperties
112127
}
113128
114129
// ================= end =================
@@ -126,8 +141,10 @@ const open = async (type: string, id?: number) => {
126141
const data = (await DiscountActivityApi.getDiscountActivity(
127142
id
128143
)) as DiscountActivityApi.DiscountActivityVO
129-
const supId = data.products[0].spuId
130-
await getSpuDetails(supId!, data.products?.map((sku) => sku.skuId), data.products)
144+
for (let productsKey in data.products) {
145+
const supId = data.products[productsKey].spuId
146+
await getSpuDetails(supId!, data.products?.map((sku) => sku.skuId), data.products,"load")
147+
}
131148
formRef.value.setValues(data)
132149
} finally {
133150
formLoading.value = false
@@ -149,9 +166,20 @@ const submitForm = async () => {
149166
const data = formRef.value.formModel as DiscountActivityApi.DiscountActivityVO
150167
// 获取 折扣商品配置
151168
const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig'))
169+
let timp = false;
152170
products.forEach((item: DiscountActivityApi.DiscountProductVO) => {
153-
item.discountType = data['discountType']
171+
if(item.discountPrice != null && item.discountPrice > 0){
172+
item.discountType = 1
173+
}else if(item.discountPercent != null && item.discountPercent > 0){
174+
item.discountType = 2
175+
}else{
176+
timp = true
177+
}
154178
})
179+
if(timp){
180+
message.error("优惠金额和折扣百分比需要填写一个");
181+
return;
182+
}
155183
data.products = products
156184
// 真正提交
157185
if (formType.value === 'create') {
@@ -173,7 +201,16 @@ const submitForm = async () => {
173201
const resetForm = async () => {
174202
spuList.value = []
175203
spuPropertyList.value = []
204+
spuIds.value = []
176205
await nextTick()
177206
formRef.value.getElFormRef().resetFields()
178207
}
208+
209+
/**
210+
* 删除spu
211+
*/
212+
const deleteSpu = (spuId: number) => {
213+
spuIds.value.splice(spuIds.value.findIndex((item) => item == spuId), 1)
214+
spuPropertyList.value.splice(spuPropertyList.value.findIndex((item) => item.spuId == spuId), 1)
215+
}
179216
</script>

src/views/mall/promotion/discountActivity/discountActivity.data.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ const crudSchemas = reactive<CrudSchema[]>([
7272
width: 120
7373
}
7474
},
75-
{
76-
label: '优惠类型',
77-
field: 'discountType',
78-
dictType: DICT_TYPE.PROMOTION_DISCOUNT_TYPE,
79-
dictClass: 'number',
80-
isSearch: true,
81-
form: {
82-
component: 'Radio',
83-
value: 1
84-
}
85-
},
8675
{
8776
label: '活动商品',
8877
field: 'spuId',

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@
7070
~ {{ formatDate(scope.row.endTime, 'YYYY-MM-DD') }}
7171
</template>
7272
</el-table-column>
73-
<el-table-column label="商品图片" prop="spuName" min-width="80">
74-
<template #default="scope">
75-
<el-image
76-
:src="scope.row.picUrl"
77-
class="h-40px w-40px"
78-
:preview-src-list="[scope.row.picUrl]"
79-
preview-teleported
80-
/>
81-
</template>
82-
</el-table-column>
83-
<el-table-column label="商品标题" prop="spuName" min-width="300" />
73+
<!-- <el-table-column label="商品图片" prop="spuName" min-width="80">-->
74+
<!-- <template #default="scope">-->
75+
<!-- <el-image-->
76+
<!-- :src="scope.row.picUrl"-->
77+
<!-- class="h-40px w-40px"-->
78+
<!-- :preview-src-list="[scope.row.picUrl]"-->
79+
<!-- preview-teleported-->
80+
<!-- />-->
81+
<!-- </template>-->
82+
<!-- </el-table-column>-->
83+
<!-- <el-table-column label="商品标题" prop="spuName" min-width="300" />-->
8484
<el-table-column label="活动状态" align="center" prop="status" min-width="100">
8585
<template #default="scope">
8686
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />

0 commit comments

Comments
 (0)