Files

194 lines
3.9 KiB
Vue
Raw Normal View History

2023-11-14 17:21:03 +08:00
<template>
<Popup
ref="popupRef"
:showCloseable="false"
@close="emit('close')"
2023-11-15 19:59:37 +08:00
@maskClick="clickMask"
2023-11-14 17:21:03 +08:00
>
<template v-if="couponList.length>0">
<view
class="coupon-box"
>
<uv-radio-group
v-model="couponItem"
class="pay-box__inner flex flex-ai__center flex-jc__center flex-wrap"
shape="circle"
activeColor="#ec6e47"
@change="groupChange"
>
<template v-for="item in couponList">
<view class="select-box">
<uv-radio
:name="item.detailId"
@change="radioChage"
>
<CouponItem
2023-11-15 19:59:37 +08:00
class="select-coupon"
2023-11-14 17:21:03 +08:00
:coupons="item"
:type="'noType'"
/>
</uv-radio>
</view>
</template>
</uv-radio-group>
</view>
</template>
<Empty
v-else
padding="120rpx 0"
2023-11-17 20:55:32 +08:00
:icon-src="emptyCouponIcon"
2023-11-14 17:21:03 +08:00
>
暂无可用的优惠券
</Empty>
2023-11-15 19:59:37 +08:00
<view class="action-height"></view>
2023-11-14 17:21:03 +08:00
<view class="button-action">
<view
class="animation-button"
:class="{disabled:couponList.length<=0}"
@click="handleSubmit"
>
确定
</view>
</view>
</Popup>
</template>
<script setup>
import { ref } from 'vue';
2023-11-14 17:21:03 +08:00
import Empty from "@/components/Empty/index.vue"
import { useInterface } from "@/hooks/useInterface";
import { getCartCoupon } from "@/api/coupon";
import CouponItem from "@/pages/discountCoupon/components/CouponItem.vue";
import Popup from '@/components/Popup/index.vue';
import UvRadio from "@/uni_modules/uv-radio/components/uv-radio/uv-radio.vue";
import UvRadioGroup from "@/uni_modules/uv-radio/components/uv-radio-group/uv-radio-group.vue";
2023-11-17 20:55:32 +08:00
import { emptyCouponIcon } from "@/utils/images";
2023-11-14 17:21:03 +08:00
const props = defineProps(["id", 'currentCouponId'])
const emit = defineEmits(['submitCoupon', 'close'])
const couponList = ref([])
const popupRef = ref(false)
const currentCoupon = ref({})
const visible = ref(false)
const couponItem = ref(props.currentCouponId ? props.currentCouponId : -1)
2023-11-15 19:59:37 +08:00
const oldCoupon = ref(props.currentCouponId ? props.currentCouponId : -1)
2023-11-14 17:21:03 +08:00
const num = ref(0)
const radioValue = ref('')
const selectCouponPanel = ref(false)
const handleGetDetail = async (id) => {
const list = await getCartCoupon(id)
if (list) {
couponList.value = list
}
}
const handleSubmit = () => {
if (couponList.value.length <= 0) {
close()
return
}
2023-11-15 19:59:37 +08:00
oldCoupon.value = couponItem.value
2023-11-14 17:21:03 +08:00
emit('submitCoupon', {
couponId: couponItem.value
})
}
const groupChange = (n) => {
if (n == radioValue.value && num.value == 0) {
num.value++
} else {
couponItem.value = -1
num.value = 0
}
}
2023-11-15 19:59:37 +08:00
const clickMask = () => {
if (oldCoupon.value !== couponItem.value) {
couponItem.value = oldCoupon.value
}
}
2023-11-14 17:21:03 +08:00
const radioChage = (n) => {
radioValue.value = n
num.value = 0
}
const {toast} = useInterface()
/**
* 用户手动输入改变数量
* @param e
* @param item
* @returns {*}
*/
const selectCurrentCoupon = (item) => {
currentCoupon.value = item
}
const open = () => {
handleGetDetail(props.id)
popupRef.value.show()
}
const close = () => {
popupRef.value.close()
emit('close')
}
defineExpose({
open,
close
})
</script>
<style lang="scss">
.coupon-box {
padding: 24rpx 24rpx 68rpx 24rpx;
box-sizing: border-box;
width: 100%;
.select-box {
width: 100%;
2023-11-15 19:59:37 +08:00
margin-bottom: 30rpx;
2023-11-14 17:21:03 +08:00
.select-icon {
width: 20rpx;
height: 20rpx;
}
.coupon-item {
margin-bottom: 0 !important;
padding: 0 60rpx;
}
2023-11-15 19:59:37 +08:00
.select-coupon {
flex: 1;
}
2023-11-14 17:21:03 +08:00
}
}
.action-height {
2023-11-15 19:59:37 +08:00
width: 100%;
height: 80rpx;
}
2023-11-14 17:21:03 +08:00
.button-action {
2023-11-15 19:59:37 +08:00
position: fixed;
bottom: 0;
width: 100%;
left: 0;
2023-11-14 17:21:03 +08:00
.animation-button {
width: 100%;
height: 80rpx;
line-height: 80rpx;
text-align: center;
}
}
</style>