Skip to content

Commit a2b378b

Browse files
YunaiVgitee-org
authored andcommitted
!534 【代码优化】商城: 满减送活动
Merge pull request !534 from puhui999/dev-crm
2 parents a13e8b7 + dcc1a3e commit a2b378b

File tree

5 files changed

+40
-83
lines changed

5 files changed

+40
-83
lines changed

src/api/mall/promotion/reward/rewardActivity.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ export interface RewardRule {
2121
limit?: number
2222
discountPrice?: number
2323
freeDelivery?: boolean
24-
givePoint?: boolean
25-
point?: number
26-
giveCoupon?: boolean
27-
couponIds?: number[]
28-
couponCounts?: number[]
24+
point: number
25+
giveCouponTemplateCounts?: {
26+
[key: number]: number
27+
}
2928
}
3029

3130
// 新增满减送活动

src/views/mall/promotion/coupon/components/CouponSelect.vue

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,6 @@
3333
/>
3434
</el-select>
3535
</el-form-item>
36-
<el-form-item label="优惠券状态" prop="status">
37-
<el-select
38-
v-model="queryParams.status"
39-
class="!w-240px"
40-
clearable
41-
placeholder="请选择优惠券状态"
42-
>
43-
<el-option
44-
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
45-
:key="dict.value"
46-
:label="dict.label"
47-
:value="dict.value"
48-
/>
49-
</el-select>
50-
</el-form-item>
51-
<el-form-item label="创建时间" prop="createTime">
52-
<el-date-picker
53-
v-model="queryParams.createTime"
54-
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
55-
class="!w-240px"
56-
end-placeholder="结束日期"
57-
start-placeholder="开始日期"
58-
type="daterange"
59-
value-format="YYYY-MM-DD HH:mm:ss"
60-
/>
61-
</el-form-item>
6236
<el-form-item>
6337
<el-button @click="handleQuery">
6438
<Icon class="mr-5px" icon="ep:search" />
@@ -118,13 +92,6 @@
11892
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
11993
</template>
12094
</el-table-column>
121-
<el-table-column
122-
:formatter="dateFormatter"
123-
align="center"
124-
label="创建时间"
125-
prop="createTime"
126-
width="180"
127-
/>
12895
</el-table>
12996
<!-- 分页 -->
13097
<Pagination
@@ -148,13 +115,13 @@ import {
148115
takeLimitCountFormat,
149116
validityTypeFormat
150117
} from '@/views/mall/promotion/coupon/formatter'
151-
import { dateFormatter } from '@/utils/formatTime'
152118
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
153119
154120
defineOptions({ name: 'CouponSelect' })
155121
156122
const props = defineProps<{
157123
multipleSelection?: CouponTemplateApi.CouponTemplateVO[]
124+
takeType: number // 领取方式
158125
}>()
159126
const emit = defineEmits<{
160127
(e: 'update:multipleSelection', v: CouponTemplateApi.CouponTemplateVO[]): void
@@ -170,10 +137,8 @@ const queryParams = reactive({
170137
pageNo: 1,
171138
pageSize: 10,
172139
name: null,
173-
status: null,
174140
discountType: null,
175-
type: null,
176-
createTime: []
141+
canTakeTypes: null
177142
})
178143
const queryFormRef = ref() // 搜索的表单
179144
const selectedCouponList = ref<CouponTemplateApi.CouponTemplateVO[]>([]) // 选择的数据
@@ -183,6 +148,7 @@ const getList = async () => {
183148
loading.value = true
184149
try {
185150
// 执行查询
151+
queryParams.canTakeTypes = [props.takeType] as any
186152
const data = await CouponTemplateApi.getCouponTemplatePage(queryParams)
187153
list.value = data.list
188154
total.value = data.total

src/views/mall/promotion/rewardActivity/RewardForm.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
:start-placeholder="t('common.startTimeText')"
1818
range-separator="-"
1919
type="datetimerange"
20+
value-format="x"
2021
/>
2122
</el-form-item>
2223
<el-form-item label="条件类型" prop="conditionType">
@@ -116,7 +117,7 @@ const open = async (type: string, id?: number) => {
116117
// 转区段时间
117118
data.startAndEndTime = [data.startTime, data.endTime]
118119
// 规则分转元
119-
data.rules.forEach((item: any) => {
120+
data.rules?.forEach((item: any) => {
120121
item.discountPrice = fenToYuan(item.discountPrice || 0)
121122
})
122123
formData.value = data
@@ -146,6 +147,7 @@ const submitForm = async () => {
146147
// 时间段转换
147148
data.startTime = data.startAndEndTime![0]
148149
data.endTime = data.startAndEndTime![1]
150+
delete data.startAndEndTime
149151
// 规则元转分
150152
data.rules.forEach((item) => {
151153
item.discountPrice = yuanToFen(item.discountPrice || 0)

src/views/mall/promotion/rewardActivity/components/RewardRule.vue

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,7 @@
4747
</el-col>
4848
<el-col :span="24">
4949
<span>送积分:</span>
50-
<el-switch
51-
v-model="rule.givePoint"
52-
active-text=""
53-
inactive-text=""
54-
inline-prompt
55-
/>
56-
<el-form-item v-if="rule.givePoint">
50+
<el-form-item>
5751
5852
<el-input
5953
v-model="rule.point"
@@ -66,17 +60,7 @@
6660
</el-col>
6761
<el-col :span="24">
6862
<span>送优惠券:</span>
69-
<el-switch
70-
v-model="rule.giveCoupon"
71-
active-text=""
72-
inactive-text=""
73-
inline-prompt
74-
/>
75-
<RewardRuleCouponSelect
76-
v-if="rule.giveCoupon"
77-
ref="rewardRuleCouponSelectRef"
78-
v-model="rule!"
79-
/>
63+
<RewardRuleCouponSelect ref="rewardRuleCouponSelectRef" v-model="rule!" />
8064
</el-col>
8165
</el-form-item>
8266
</el-form>
@@ -85,6 +69,9 @@
8569
<el-col :span="24" class="mt-10px">
8670
<el-button type="primary" @click="addRule">添加优惠规则</el-button>
8771
</el-col>
72+
<el-col :span="24">
73+
<el-tag type="warning"> 赠送积分为 0 时不赠送。未选优惠券时不赠送。</el-tag>
74+
</el-col>
8875
</el-row>
8976
</template>
9077

@@ -116,15 +103,14 @@ const deleteRule = (ruleIndex: number) => {
116103
117104
/** 添加优惠规则 */
118105
const addRule = () => {
106+
if (isEmpty(formData.value.rules)) {
107+
formData.value.rules = []
108+
}
119109
formData.value.rules.push({
120110
limit: 0,
121111
discountPrice: 0,
122112
freeDelivery: false,
123-
givePoint: false,
124-
point: 0,
125-
giveCoupon: false,
126-
couponIds: [],
127-
couponCounts: []
113+
point: 0
128114
})
129115
}
130116
@@ -134,14 +120,6 @@ const setRuleCoupon = () => {
134120
return
135121
}
136122
137-
// 情况一:不赠送优惠券
138-
formData.value.rules.forEach((rule) => {
139-
if (!rule.giveCoupon) {
140-
rule.couponIds = []
141-
rule.couponCounts = []
142-
}
143-
})
144-
// 情况二:赠送优惠券
145123
rewardRuleCouponSelectRef.value?.forEach((item) => item.setGiveCouponList())
146124
}
147125

src/views/mall/promotion/rewardActivity/components/RewardRuleCouponSelect.vue

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,22 @@
2727
</div>
2828

2929
<!-- 优惠券选择 -->
30-
<CouponSelect ref="couponSelectRef" @change="handleCouponChange" />
30+
<CouponSelect
31+
ref="couponSelectRef"
32+
:take-type="CouponTemplateTakeTypeEnum.ADMIN.type"
33+
@change="handleCouponChange"
34+
/>
3135
</template>
3236

3337
<script lang="ts" setup>
3438
import { CouponSelect } from '@/views/mall/promotion/coupon/components'
3539
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
3640
import { RewardRule } from '@/api/mall/promotion/reward/rewardActivity'
3741
import { DICT_TYPE } from '@/utils/dict'
42+
import { CouponTemplateTakeTypeEnum } from '@/utils/constants'
3843
import { discountFormat } from '@/views/mall/promotion/coupon/formatter'
3944
import { isEmpty } from '@/utils/is'
4045
import { useVModel } from '@vueuse/core'
41-
import { findIndex } from '@/utils'
4246
4347
defineOptions({ name: 'RewardRuleCouponSelect' })
4448
@@ -81,19 +85,22 @@ const deleteCoupon = (index: number) => {
8185
8286
/** 初始化赠送的优惠券列表 */
8387
const initGiveCouponList = async () => {
84-
// 朝赵优惠劵
85-
if (isEmpty(rewardRule.value) || isEmpty(rewardRule.value.couponIds)) {
88+
// 校验优惠券存在
89+
if (isEmpty(rewardRule.value) || isEmpty(rewardRule.value.giveCouponTemplateCounts)) {
8690
return
8791
}
88-
const data = await CouponTemplateApi.getCouponTemplateList(rewardRule.value.couponIds!)
92+
const tempLateIds = Object.keys(rewardRule.value.giveCouponTemplateCounts!).map((item) =>
93+
parseInt(item)
94+
)
95+
const data = await CouponTemplateApi.getCouponTemplateList(tempLateIds)
8996
if (!data) {
9097
return
9198
}
99+
// 回显
92100
data.forEach((coupon) => {
93-
const index = findIndex(rewardRule.value.couponIds!, (couponId) => couponId === coupon.id)
94101
list.value.push({
95102
...coupon,
96-
giveCount: rewardRule.value.couponCounts![index]
103+
giveCount: rewardRule.value.giveCouponTemplateCounts![coupon.id]
97104
})
98105
})
99106
}
@@ -104,8 +111,13 @@ const setGiveCouponList = () => {
104111
return
105112
}
106113
107-
rewardRule.value.couponIds = list.value.map((rule) => rule.id)
108-
rewardRule.value.couponCounts = list.value.map((rule) => rule.giveCount || 0)
114+
// 设置优惠券和其数量的对应
115+
list.value.forEach((rule) => {
116+
if (!rewardRule.value.giveCouponTemplateCounts) {
117+
rewardRule.value.giveCouponTemplateCounts = {}
118+
}
119+
rewardRule.value.giveCouponTemplateCounts[rule.id] = rule.giveCount!
120+
})
109121
}
110122
defineExpose({ setGiveCouponList })
111123

0 commit comments

Comments
 (0)