commit
a2b378b131
|
@ -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[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增满减送活动
|
// 新增满减送活动
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 })
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue