|
@@ -22,7 +22,27 @@ const { userInfo } = storeToRefs(userStore)
|
|
const { alert } = useMessage()
|
|
const { alert } = useMessage()
|
|
// const show = ref(false)
|
|
// const show = ref(false)
|
|
const tab = ref(0)
|
|
const tab = ref(0)
|
|
-const request = ref()
|
|
|
|
|
|
+const query = ref<{ userId: number; available?: boolean }>({
|
|
|
|
+ userId: userInfo.value.userId,
|
|
|
|
+})
|
|
|
|
+const request = computed(() =>
|
|
|
|
+ props.type === 'points'
|
|
|
|
+ ? () =>
|
|
|
|
+ getPointsCoupons({
|
|
|
|
+ userId: userInfo.value.userId,
|
|
|
|
+ // productIds: props.products.map((it) => it.productId).join(','),
|
|
|
|
+ businessId: props.businessId,
|
|
|
|
+ isUse: 0,
|
|
|
|
+ ...query.value,
|
|
|
|
+ })
|
|
|
|
+ : () =>
|
|
|
|
+ getProductCoupons({
|
|
|
|
+ userId: userInfo.value.userId,
|
|
|
|
+ productIds: props.products.map((it) => it.productId).join(','),
|
|
|
|
+ isUse: 0,
|
|
|
|
+ ...query.value,
|
|
|
|
+ }),
|
|
|
|
+)
|
|
const { data: coupons, run: setCoupons } = useRequest(() => request.value(), { initialData: [] })
|
|
const { data: coupons, run: setCoupons } = useRequest(() => request.value(), { initialData: [] })
|
|
const handleSelect = (coupon: Coupon) => {
|
|
const handleSelect = (coupon: Coupon) => {
|
|
// if (modelValue.value.map(({ id }) => id).includes(coupon.id)) {
|
|
// if (modelValue.value.map(({ id }) => id).includes(coupon.id)) {
|
|
@@ -33,6 +53,11 @@ const handleSelect = (coupon: Coupon) => {
|
|
modelValue.value = [coupon]
|
|
modelValue.value = [coupon]
|
|
emits('close')
|
|
emits('close')
|
|
}
|
|
}
|
|
|
|
+const handleTabsChange = async ({ index, name }) => {
|
|
|
|
+ console.log(index)
|
|
|
|
+ query.value = { ...query.value, available: index === 0 }
|
|
|
|
+ await setCoupons()
|
|
|
|
+}
|
|
watch(
|
|
watch(
|
|
() => props.show,
|
|
() => props.show,
|
|
async (val) => {
|
|
async (val) => {
|
|
@@ -45,40 +70,21 @@ watch(
|
|
}
|
|
}
|
|
},
|
|
},
|
|
)
|
|
)
|
|
-onMounted(async () => {
|
|
|
|
- if (props.type === 'product') {
|
|
|
|
- request.value = () =>
|
|
|
|
- getProductCoupons({
|
|
|
|
- userId: userInfo.value.userId,
|
|
|
|
- productIds: props.products.map((it) => it.productId).join(','),
|
|
|
|
- isUse: 0,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- if (props.type === 'points') {
|
|
|
|
- request.value = () =>
|
|
|
|
- getPointsCoupons({
|
|
|
|
- userId: userInfo.value.userId,
|
|
|
|
- // productIds: props.products.map((it) => it.productId).join(','),
|
|
|
|
- businessId: props.businessId,
|
|
|
|
- isUse: 0,
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- // await setCoupons()
|
|
|
|
-})
|
|
|
|
|
|
+onMounted(async () => {})
|
|
</script>
|
|
</script>
|
|
<template>
|
|
<template>
|
|
<wd-action-sheet title="优惠券" :modelValue="show" @close="emits('close')">
|
|
<wd-action-sheet title="优惠券" :modelValue="show" @close="emits('close')">
|
|
<view class="">
|
|
<view class="">
|
|
- <wd-tabs v-model="tab">
|
|
|
|
|
|
+ <wd-tabs v-model="tab" @change="handleTabsChange">
|
|
<wd-tab title="可用优惠券"></wd-tab>
|
|
<wd-tab title="可用优惠券"></wd-tab>
|
|
- <!-- <wd-tab title="不可用优惠券"></wd-tab> -->
|
|
|
|
|
|
+ <wd-tab title="不可用优惠券"></wd-tab>
|
|
</wd-tabs>
|
|
</wd-tabs>
|
|
<div class="h-100 overflow-y-scroll">
|
|
<div class="h-100 overflow-y-scroll">
|
|
<div class="bg-[#f6f6f6] py-3.5 flex flex-col gap-4 min-h-full">
|
|
<div class="bg-[#f6f6f6] py-3.5 flex flex-col gap-4 min-h-full">
|
|
<template v-for="(it, i) in coupons" :key="i">
|
|
<template v-for="(it, i) in coupons" :key="i">
|
|
<CouponCard
|
|
<CouponCard
|
|
:options="{ couponType: 2, ...it }"
|
|
:options="{ couponType: 2, ...it }"
|
|
- canSelect
|
|
|
|
|
|
+ :canSelect="tab === 0"
|
|
:selected="modelValue?.map(({ id }) => id).includes(it.id)"
|
|
:selected="modelValue?.map(({ id }) => id).includes(it.id)"
|
|
@select="handleSelect"
|
|
@select="handleSelect"
|
|
@click-instruction="(e) => emits('clickInstruction', e)"
|
|
@click-instruction="(e) => emits('clickInstruction', e)"
|