!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 limit?: number
discountPrice?: number discountPrice?: number
freeDelivery?: boolean freeDelivery?: boolean
givePoint?: boolean point: number
point?: number giveCouponTemplateCounts?: {
giveCoupon?: boolean [key: number]: number
couponIds?: number[] }
couponCounts?: number[]
} }
// 新增满减送活动 // 新增满减送活动

View File

@ -33,32 +33,6 @@
/> />
</el-select> </el-select>
</el-form-item> </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-form-item>
<el-button @click="handleQuery"> <el-button @click="handleQuery">
<Icon class="mr-5px" icon="ep:search" /> <Icon class="mr-5px" icon="ep:search" />
@ -118,13 +92,6 @@
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" /> <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column
:formatter="dateFormatter"
align="center"
label="创建时间"
prop="createTime"
width="180"
/>
</el-table> </el-table>
<!-- 分页 --> <!-- 分页 -->
<Pagination <Pagination
@ -148,13 +115,13 @@ import {
takeLimitCountFormat, takeLimitCountFormat,
validityTypeFormat validityTypeFormat
} from '@/views/mall/promotion/coupon/formatter' } from '@/views/mall/promotion/coupon/formatter'
import { dateFormatter } from '@/utils/formatTime'
import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate' import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
defineOptions({ name: 'CouponSelect' }) defineOptions({ name: 'CouponSelect' })
const props = defineProps<{ const props = defineProps<{
multipleSelection?: CouponTemplateApi.CouponTemplateVO[] multipleSelection?: CouponTemplateApi.CouponTemplateVO[]
takeType: number //
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'update:multipleSelection', v: CouponTemplateApi.CouponTemplateVO[]): void (e: 'update:multipleSelection', v: CouponTemplateApi.CouponTemplateVO[]): void
@ -170,10 +137,8 @@ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
name: null, name: null,
status: null,
discountType: null, discountType: null,
type: null, canTakeTypes: null
createTime: []
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const selectedCouponList = ref<CouponTemplateApi.CouponTemplateVO[]>([]) // const selectedCouponList = ref<CouponTemplateApi.CouponTemplateVO[]>([]) //
@ -183,6 +148,7 @@ const getList = async () => {
loading.value = true loading.value = true
try { try {
// //
queryParams.canTakeTypes = [props.takeType] as any
const data = await CouponTemplateApi.getCouponTemplatePage(queryParams) const data = await CouponTemplateApi.getCouponTemplatePage(queryParams)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total

View File

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

View File

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

View File

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