Files
xdd-uniapp-new/pkg_user/views/gift/components/GiftCard.vue
T

340 lines
8.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="dialog-conent" v-show="isLogin">
<view class="gift-card-modal" >
<image class="bg-image" :src="!card.isBlind ? card.cover : card.blindBoxImage" mode="aspectFit|aspectFill|widthFix" lazy-load="false"></image>
<view v-if="card.isBlind !== 1" class="image-wrap" :style="{
top: card.productImageY + 'px',
left: card.productImageX + 'px'
}">
<image class="pro-image" :src="card.giftProducts[0].productImage" mode="aspectFit|aspectFill|widthFix" lazy-load="false" @error="" @load="">
</image>
</view>
<view class="wrap-box">
</view>
<view class="auto-text-color">
<!-- {{ card.message || '礼笺轻启,礼藏心意' }} -->
</view>
</view>
<view class="blind-box" v-if="card.isBlind">
<u-icon :name="webUrl + '/orderIcon/礼物.png'" size="30" ></u-icon>
<text class="v12-font-30 v12-dark-text v12-font-bold v12-ml-2">您收到一份来自朋友的神秘礼物</text>
</view>
<view class="btn-wrap">
<button v-if="!isReceive && myGift.isCurrentUser !== 1" class="share-btn v12-white-text v12-primary" @click="setAddress(0)">
填写地址并收下
</button>
<button v-if="card.canTransfer !== 0 && !isReceive && myGift.isCurrentUser !== 1" open-type="share" class="share-btn v12-white v12-primary-text v12-d-flex" >
点击转赠给好友
<u-icon :name="webUrl + '/icon/share.png'" ></u-icon>
</button>
</view>
<view v-if="myGift.isCurrentUser === 1 && !card.isBlind" @click="toOrder" style="z-index: 10; display: flex;flex-direction: column;align-items: center;">
<view class="address-btn v12-white-text v12-primary">
您已领取礼包
</view>
<view class="info-btn v12-text-center v12-font-32 v12-mt-3">查看礼包详情>></view>
</view>
<view v-if="myGift.isCurrentUser === 1 && card.isBlind" style="z-index: 10; display: flex;flex-direction: column;align-items: center;">
<view style="width: fit-content;" class="address-btn v12-white-text v12-primary" @click="toOrder">
您已领取礼包去看看>>
</view>
<view class="info-btn v12-text-center v12-font-32 v12-mt-3" @click.stop="searchGift">我也要送礼</view>
</view>
<view v-if="isReceive && myGift.isCurrentUser !== 1" @click="toHome" style="z-index: 10; display: flex;flex-direction: column;align-items: center;">
<view class="address-btn v12-white-text v12-primary">
礼包已被领取
</view>
<view class="info-btn v12-text-center v12-font-32 v12-mt-3" style="z-index: 10">去商城看看>></view>
</view>
<view class="tips">
<view class="tip-text v12-mr-1" @click="showTips">
未领取礼包将于24小时后自动退回
<u-icon name="error-circle" color="#666" size="24rpx"></u-icon>
</view>
</view>
<giftTips ref="giftTips" :richText="giftNotice"></giftTips>
<AddressDialog ref="addressDialog" @save="getReceive"></AddressDialog>
<AddressList ref="AddressList" :addressList="address" @save="getReceive"></AddressList>
</view>
</template>
<script>
import { getGiftCardSendNotice, getGiftCardReceive } from '@/api/gift'
import cookie from "@/utils/store/cookie";
import { getAddressList } from '@/api/user'
import giftTips from './giftTips.vue'
import AddressDialog from './AddressDialog.vue'
import AddressList from './AddressList.vue'
export default {
name: 'GiftCard',
components: {
giftTips,
AddressDialog,
AddressList
},
props: {
// 组件属性
card: {
type: Object,
default: () => {}
},
addr: {
type: Object,
default: () => {}
}
},
data() {
return {
webUrl: this.$VUE_APP_RESOURCES_URL,
// 组件数据
giftNotice: '',
address: [],
order: ''
}
},
computed: {
isReceive() {
const gitfNum = this.card.giftProducts && this.card.giftProducts.length
const isReceiveNum = this.card.giftProducts && this.card.giftProducts.filter(e => e.isReceive === 1).length
return gitfNum === isReceiveNum
},
isLogin() {
return !!cookie.get('login_status');
},
myGift() {
return this.card.giftProducts && this.card.giftProducts.filter(item => item.isCurrentUser === 1).length > 0 && this.card.giftProducts.filter(item => item.isCurrentUser === 1)[0] || this.card.giftProduct && this.card.giftProducts[0]
}
},
watch: {
addr: {
handler(newVal, oldVal) {
if (newVal && newVal.id) {
// this.address = newVal
this.setAddress(1)
}
},
deep: true
},
// 修改后的监听器
myGift: {
handler(newVal) {
this.order = newVal && newVal.orderId
},
deep: true,
immediate: true
}
},
methods: {
searchGift() {
this.$yrouter.push('/pages/shop/GoodsList/index?s=' +'送礼' )
},
// 分享到微信好友
toShare() {
// 分享到微信好友
},
toOrder() {
this.$yrouter.push({
path: "/pages/order/OrderDetails/index",
query: {
id: this.order
}
});
},
toHome() {
uni.switchTab({
url: '/pages/home/index'
})
},
getReceive(e) {
uni.showLoading({
title: '领取中...',
mask: true
})
// 领取礼包
getGiftCardReceive({
code: this.card.code,
recipientsNum : 1,
addressId: e
}).then(res => {
this.$refs.addressDialog.close()
this.$refs.AddressList.close()
this.order = res.data.orderId
this.$emit('receive', this.card.code)
uni.hideLoading()
}).finally(() => {
})
},
setAddress(flag) {
getAddressList().then(res => {
if (res.data.length === 0) {
this.$refs.addressDialog.open()
} else {
this.address = res.data
if(flag) return
this.$refs.AddressList.open()
}
})
},
async showTips() {
// 获取发礼提示
getGiftCardSendNotice().then(res => {
this.$refs.giftTips.showTips = true
this.giftNotice = res.data
})
},
}
}
</script>
<style scoped>
.blind-box{
width: 578rpx;
height: 90rpx;
background: rgba(255,255,255,0.39);
box-shadow: 0rpx 2rpx 20rpx rgba(0,0,0,0.05);
border-radius: 16rpx;
line-height: 90rpx;
display: flex;
padding-left: 35rpx;
align-items: center;
}
.info-btn{
border: 1px solid #C52733;
color: #C52733;
width: 240rpx;
border-radius: 100rpx;
padding: 5rpx 40rpx;
line-height: 60rpx;
height: 60rpx;
font-weight: 600;
font-size: 32rpx;
white-space: nowrap;
}
.dialog-conent{
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: center
}
.btn-wrap{
position: relative;
display: flex;
justify-content: center;
align-content: center;
}
.bg-image{
width: 340rpx;
height: 560rpx;
position: absolute;
border-radius: 16rpx;
top: 0;
}
.tips{
display: flex;
align-items: center;
margin-top: 40rpx;
position: absolute;
bottom: 50rpx;
width: 100%;
}
.tip-text{
font-family: Source Han Sans SC;
font-weight: 500;
font-size: 24rpx;
color: #666;
opacity: 0.6;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
line-height: 36rpx;
}
.wrap-box{
width: 296rpx;
height: 296rpx;
}
.image-wrap{
width: 160rpx;
height: 160rpx;
/*border: 10rpx solid #FDF0D3;*/
border-radius: 30rpx;
position: absolute;
overflow: hidden;
top: -140rpx;
right: 0;
margin: auto;
}
.pro-image{
width: 160rpx;
height: 160rpx;
/* border-radius: 30rpx; */
}
.auto-text-color {
color: #fff;
font-size: 32rpx;
opacity: 0.8;
margin-top: 150rpx;
width: 400rpx;
text-align: center;
}
.share-btn{
width: fit-content;
border-radius: 100rpx;
font-size: 32rpx;
margin-top: 40rpx;
z-index: 999;
align-items: center;
border: 1rpx solid #C52733 ;
margin-left: 10rpx;
font-weight: bold;
height: 80rpx;
line-height: 80rpx;
}
.share-btn::before{
border: none;
}
.share-btn::after{
border: none ;
}
.address-btn{
width: fit-content;
padding: 5rpx 40rpx;
border-radius: 100rpx;
font-size: 32rpx;
font-weight: bold;
height: 60rpx;
line-height: 60rpx;
width: 240rpx;
/* margin-top: 40rpx; */
z-index: 999;
text-align: center;
}
.gift-card-modal {
height: 560rpx;
width: 340rpx;
justify-content: center;
z-index: 999;
margin-top: 100rpx;
border-radius: 16rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: start;
position: relative;
}
.gift-card-content {
background-color: #fff;
padding: 20px;
border-radius: 10px;
width: 80%;
max-width: 300px;
}
</style>