<template>
	<!-- 购买成功弹窗 -->
	<view>
		<up-popup :show="showBuy" :customStyle="customStyle" closeable @close="close" catchtouchmove="preventD" :close-on-click-overlay="false" mode="center">
			<view class="buy">
				<up-icon name="checkmark-circle-fill" size="60" :color="Color" />
				<view class="title">恭喜购买成功</view>
				<view class="user">
					<image :src="avatar"></image>
					<text>{{nickname}}</text>
				</view>
				<view class="text">转发到群聊,通知团长你已下单,尽快发货</view>
				<view class="label">
					<button @click="shareOrder" class="btn">分享到群聊</button>
					<text v-if="score_on && role && !from" class="text1">积分再+{{score_trade_share}}</text>
				</view>
				<view class="box" v-if="score_on && role && !from && !link_id">
					<view class="left">
						<image src="../../static/image/gift.png" mode="widthFix" class="img"></image>
						<view class="">
							<view class="tit">积分商城&nbsp;<text class="text1">+{{score_trade * pay_price}}</text></view>
							<view class="tit">累计积分兑换奖品</view>
						</view>
					</view>
					<view class="to" @click="toScoreShop">去兑换</view>
				</view>
				
			</view>
		</up-popup>
	</view>
</template>

<script>
import { ref, reactive, toRefs, watch } from 'vue'
export default {
	props: {
		showBuy: {
			type: Boolean,
			default: false
		},
		payPrice: {
			type: String
		},
		from: {
			type: Number
		}
	},
	setup(props, context) {
		const data = reactive({
			nickname: uni.getStorageSync('nickname'),
			avatar: uni.getStorageSync('avatar'),
			role: Number(uni.getStorageSync('role')) !== 1,
			score_trade_share: Number(uni.getStorageSync('score_trade_share')),
			score_on: Number(uni.getStorageSync('score_on')) === 1,
			score_trade: Number(uni.getStorageSync('score_trade')),
			pay_price: 0,
			from: 0,
			link_id: 0,
			customStyle: {
				width: '86%',
				'border-radius': '10px'
			},
			Color: uni.getStorageSync('theme_color')
		})
		
		function close() {
			context.emit('close')
		}
		
		function preventD() {
			return
		}
		
		function toScoreShop() {
			uni.navigateTo({
				url: '/pages/mine/scoreShop/index'
			})
		}
		
		function shareOrder() {
			context.emit('share')
			close()
		}
		
		watch(props, (newProps) => {
			if(newProps.showBuy) {
				data.nickname = uni.getStorageSync('nickname')
				data.avatar = uni.getStorageSync('avatar')
				data.pay_price = newProps.payPrice * 1
				data.from = newProps.from
				data.link_id = (newProps.link_id || 0) * 1
			}
		})
		return {
			...toRefs(data),
			close,
			preventD,
			toScoreShop,
			shareOrder
		}
	}
}
</script>

<style lang="scss" scoped>
.buy {
	text-align: center;
	padding: 60rpx 0;
	.title {
		font-size: 34rpx;
		color: v-bind('Color');
		margin-top: 30rpx;
		font-weight: 600;
	}
	.user {
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 40rpx;
		image {
			width: 70rpx;
			height: 70rpx;
			background: #98989f;
			border-radius: 50%;
			margin-right: 15rpx;
		}
	}
	.text {
		color: #666666;
		font-size: 26rpx;
		margin-top: 30rpx;
	}
	.label{
		position: relative;
		margin: 36rpx auto 0;
		width: 88%;
		.text1{
			border-radius: 20rpx 20rpx 20rpx 0;
			border: 1px solid #fff;
			background-color: v-bind('Color');
			font-size: 22rpx;
			color: #fff;
			padding: 6rpx 10rpx;
			position: absolute;
			top: -26rpx;
			left: 64%;
		}
		.btn {
			width: 100%;
			height: 86rpx;
			line-height: 86rpx;
			background: v-bind('Color');
			border-radius: 10rpx;
			color: #fff;
			font-size: 30rpx;
			text-align: center;
		}
	}
	
	.box{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx;
		width: 88%;
		margin: 30rpx auto 0;
		background: #F9F6E5;
		border-radius: 10rpx;
		box-sizing: border-box;
		.left{
			width: calc(100% - 160rpx);
			display: flex;
			.img{
				width: 90rpx;
			}
			.tit{
				font-size: 28rpx;
				color: #744928;
				padding-left: 10rpx;
				text-align: left;
				.text1{
					color: v-bind('Color');
					font-weight: 600;
				}
			}
		}
		.to{
			display: flex;
			align-items: center;
			justify-content: center;
			height: 50rpx;
			width: 140rpx;
			border-radius: 50rpx;
			background: v-bind('Color');
			font-size: 26rpx;
			color: #fff;
		}
	}
}
</style>
