!534 【代码优化】商城: 满减送活动

Merge pull request !534 from puhui999/dev-crm
pull/533/MERGE
芋道源码 2024-09-02 14:30:47 +00:00 committed by Gitee
commit a2b378b131
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 40 additions and 83 deletions

View File

@ -21,11 +21,10 @@ export interface RewardRule {
limit?: number
discountPrice?: number
freeDelivery?: boolean
givePoint?: boolean
point?: number
giveCoupon?: boolean
couponIds?: number[]
couponCounts?: number[]
point: number
giveCouponTemplateCounts?: {
[key: number]: number
}
}
// 新增满减送活动

View File

@ -33,32 +33,6 @@
/>
</el-select>
</el-form-item>
<el-form-item label="优惠券状态" prop="status">
<el-select
v-model="queryParams.status"
class="!w-240px"
clearable
placeholder="请选择优惠券状态"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
<el-date-picker
v-model="queryParams.createTime"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
end-placeholder="结束日期"
start-placeholder="开始日期"
type="daterange"
value-format="YYYY-MM-DD HH:mm:ss"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery">
<Icon class="mr-5px" icon="ep:search" />
@ -118,13 +92,6 @@
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column
:formatter="dateFormatter"
align="center"
label="创建时间"
prop="createTime"
width="180"
/>
</el-table>
<!-- 分页 -->
<Pagination
@ -148,13 +115,13 @@ import {
takeLimitCountFormat,
validityTypeFormat
} from '@/views/mall/promotion/coupon/formatter'
import { dateFormatter } from '@/utils/formatTime'
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
defineOptions({ name: 'CouponSelect' })
const props = defineProps<{
multipleSelection?: CouponTemplateApi.CouponTemplateVO[]
takeType: number //
}>()
const emit = defineEmits<{
(e: 'update:multipleSelection', v: CouponTemplateApi.CouponTemplateVO[]): void
@ -170,10 +137,8 @@ const queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: null,
status: null,
discountType: null,
type: null,
createTime: []
canTakeTypes: null
})
const queryFormRef = ref() //
const selectedCouponList = ref<CouponTemplateApi.CouponTemplateVO[]>([]) //
@ -183,6 +148,7 @@ const getList = async () => {
loading.value = true
try {
//
queryParams.canTakeTypes = [props.takeType] as any
const data = await CouponTemplateApi.getCouponTemplatePage(queryParams)
list.value = data.list
total.value = data.total

View File

@ -17,6 +17,7 @@
:start-placeholder="t('common.startTimeText')"
range-separator="-"
type="datetimerange"
value-format="x"
/>
</el-form-item>
<el-form-item label="条件类型" prop="conditionType">
@ -116,7 +117,7 @@ const open = async (type: string, id?: number) => {
//
data.startAndEndTime = [data.startTime, data.endTime]
//
data.rules.forEach((item: any) => {
data.rules?.forEach((item: any) => {
item.discountPrice = fenToYuan(item.discountPrice || 0)
})
formData.value = data
@ -146,6 +147,7 @@ const submitForm = async () => {
//
data.startTime = data.startAndEndTime![0]
data.endTime = data.startAndEndTime![1]
delete data.startAndEndTime
//
data.rules.forEach((item) => {
item.discountPrice = yuanToFen(item.discountPrice || 0)

View File

@ -47,13 +47,7 @@
</el-col>
<el-col :span="24">
<span>送积分</span>
<el-switch
v-model="rule.givePoint"
active-text="是"
inactive-text="否"
inline-prompt
/>
<el-form-item v-if="rule.givePoint">
<el-form-item>
<el-input
v-model="rule.point"
@ -66,17 +60,7 @@
</el-col>
<el-col :span="24">
<span>送优惠券</span>
<el-switch
v-model="rule.giveCoupon"
active-text="是"
inactive-text="否"
inline-prompt
/>
<RewardRuleCouponSelect
v-if="rule.giveCoupon"
ref="rewardRuleCouponSelectRef"
v-model="rule!"
/>
<RewardRuleCouponSelect ref="rewardRuleCouponSelectRef" v-model="rule!" />
</el-col>
</el-form-item>
</el-form>
@ -85,6 +69,9 @@
<el-col :span="24" class="mt-10px">
<el-button type="primary" @click="addRule"></el-button>
</el-col>
<el-col :span="24">
<el-tag type="warning"> 赠送积分为 0 时不赠送未选优惠券时不赠送</el-tag>
</el-col>
</el-row>
</template>
@ -116,15 +103,14 @@ const deleteRule = (ruleIndex: number) => {
/** 添加优惠规则 */
const addRule = () => {
if (isEmpty(formData.value.rules)) {
formData.value.rules = []
}
formData.value.rules.push({
limit: 0,
discountPrice: 0,
freeDelivery: false,
givePoint: false,
point: 0,
giveCoupon: false,
couponIds: [],
couponCounts: []
point: 0
})
}
@ -134,14 +120,6 @@ const setRuleCoupon = () => {
return
}
//
formData.value.rules.forEach((rule) => {
if (!rule.giveCoupon) {
rule.couponIds = []
rule.couponCounts = []
}
})
//
rewardRuleCouponSelectRef.value?.forEach((item) => item.setGiveCouponList())
}

View File

@ -27,7 +27,11 @@
</div>
<!-- 优惠券选择 -->
<CouponSelect ref="couponSelectRef" @change="handleCouponChange" />
<CouponSelect
ref="couponSelectRef"
:take-type="CouponTemplateTakeTypeEnum.ADMIN.type"
@change="handleCouponChange"
/>
</template>
<script lang="ts" setup>
@ -35,10 +39,10 @@ import { CouponSelect } from '@/views/mall/promotion/coupon/components'
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
import { RewardRule } from '@/api/mall/promotion/reward/rewardActivity'
import { DICT_TYPE } from '@/utils/dict'
import { CouponTemplateTakeTypeEnum } from '@/utils/constants'
import { discountFormat } from '@/views/mall/promotion/coupon/formatter'
import { isEmpty } from '@/utils/is'
import { useVModel } from '@vueuse/core'
import { findIndex } from '@/utils'
defineOptions({ name: 'RewardRuleCouponSelect' })
@ -81,19 +85,22 @@ const deleteCoupon = (index: number) => {
/** 初始化赠送的优惠券列表 */
const initGiveCouponList = async () => {
//
if (isEmpty(rewardRule.value) || isEmpty(rewardRule.value.couponIds)) {
//
if (isEmpty(rewardRule.value) || isEmpty(rewardRule.value.giveCouponTemplateCounts)) {
return
}
const data = await CouponTemplateApi.getCouponTemplateList(rewardRule.value.couponIds!)
const tempLateIds = Object.keys(rewardRule.value.giveCouponTemplateCounts!).map((item) =>
parseInt(item)
)
const data = await CouponTemplateApi.getCouponTemplateList(tempLateIds)
if (!data) {
return
}
//
data.forEach((coupon) => {
const index = findIndex(rewardRule.value.couponIds!, (couponId) => couponId === coupon.id)
list.value.push({
...coupon,
giveCount: rewardRule.value.couponCounts![index]
giveCount: rewardRule.value.giveCouponTemplateCounts![coupon.id]
})
})
}
@ -104,8 +111,13 @@ const setGiveCouponList = () => {
return
}
rewardRule.value.couponIds = list.value.map((rule) => rule.id)
rewardRule.value.couponCounts = list.value.map((rule) => rule.giveCount || 0)
//
list.value.forEach((rule) => {
if (!rewardRule.value.giveCouponTemplateCounts) {
rewardRule.value.giveCouponTemplateCounts = {}
}
rewardRule.value.giveCouponTemplateCounts[rule.id] = rule.giveCount!
})
}
defineExpose({ setGiveCouponList })