<template>
		<view class="buy-popup">
			<view class="header-info">
				<image v-if="previewData.coverResource" :src="previewData.coverResource.url" mode="aspectFit"
					class="info-img"></image>
				<view class="info-right">
					<view class="right-name">{{previewData.name}}</view>
					<view class="right-price">原价 ¥{{Number(previewData.amount.sale)}}</view>
					<view class="item">
						<image src="@/static/home/d-x.png" mode="" class="d-x"></image>
						<view class="label">实付金额</view>
						<view class="value">¥ {{previewData.amount.settlement || 0}}</view>
					</view>
				</view>
				<image src="@/static/home/c-x.png" mode="" class="c-x"></image>
			</view>
			
			<view class="mains" v-if="payList.length > 0">
				<view class="pay" v-for="(item,index) in payList" :key="index" @click="payChange(index,item)">
					<view class="left">
						<image :src="item.img" mode="aspectFit" class="pay-icon"></image>
						{{item.label}}
					</view>
					<image src="@/static/home/yes.png" mode="" class="select-icon" v-if="item.visible"></image>
					<image src="@/static/home/no.png" mode="" class="select-icon" v-else></image>
				</view>
			</view>
			<view class="popup-buy" @click="pay">立即开盒 ¥{{previewData.amount.settlement || 0}}</view>
		</view>
</template>

<script>
	import {
		boxOrderReviewApi,
		boxOrderApi,
		boxOrderPaidApi,
		activityReviewApi,
		activityBuyApi,
		activityOrderApi,
		activityReviewSourceApi,
		activitySourceBuyApi
	} from '@/API/index.js'
	import { coinPaidApi,payMethodApi,userInfo } from '@/API/user.js'
	import reportClickFn from '@/utils/report.js'
	export default {
		data() {
			return {
				type: '',
				typeIndex:0,
				previewData: {
					amount:{}
				}, //预览订单
				timer: null, //盲盒购买
				rookieTimer:null,//新手盲盒购买
				payList:[],//支付方式
				payType:'',
				boxOrderNo:'',
				isTopUp:false,
				infoDetail:{},
				payLink:'',
				orderSn:'',
				payinfoUrl:'',
				timeSec:0,
				userInfo:{},
				isTip:true
			}
		},
		props: {
			visible: {
				type: Boolean,
				default: false
			},
			isCard: {
				type: Boolean,
				default: true
			},//是否显示使用提示卡
			detailData: {
				type: Object,
				default: () => {
					coverResource: {}
				}
			},
			boxType:{
				type: String,
				default: ''
			},//buy 为不同购买   ROOKIE 新手盲盒   PREFERENTIAL_DAY 每日优惠  SPECIAL_PRICE 薅羊毛
			isDetail:{
				type: Boolean,
				default: false
			},//是否详情进入
			isActivityClick:{
				type: Boolean,
				default: false
			},//是否点击打开新人福利
			payNum:{
				type: Number,
				default: 0
			}
		},
		
		watch:{
			  timeSec(){
				  if(this.timeSec == 30){
					  clearInterval(this.rookieTimer)
					  this.rookieTimer = null
					  this.$api.msg('未查询到支付结果')
				  }
			  },
			  payNum(){
				  this.pay()
			  },
		},
		mounted() {
			this.payLink = ''
			if(this.boxType === 'buy'){
				// 普通盲盒
				this.type = this.detailData.price[0].type
				this.typeIndex = 0
				this.getDetail()
				// 盲盒购买预览
				reportClickFn('box_buy_review_clk')
				if(this.isDetail){
					// 指定盲盒详情购买预览
					reportClickFn(`boxId_detail_review_${this.detailData.id}`)
				}else{
					// 指定盲盒购买预览
					reportClickFn(`boxId_review_${this.detailData.id}`)
				}
			}
			if(this.boxType === 'ROOKIE'){
				// 活动购买预览
				reportClickFn('box_activity_review_clk')
				// 新手盲盒
				this.getActivityReview()
				// this.getPayMethod()
			}
			if(this.boxType === 'PREFERENTIAL_DAY'){
				// 活动购买预览
				reportClickFn('box_activity_review_clk')
				// 每日优惠
				this.getActivityReview()
			}
			if(this.boxType === 'SPECIAL_PRICE'){
				// 活动购买预览
				// reportClickFn('box_activity_review_clk')
				// 每日优惠
				this.getActivityReview()
			}
			
		},
		methods: {
			// 获取用户信息
			getUserInfo() {
				userInfo().then(res => {
					if (res.code === 200) {
						this.infoDetail = res.data
						if(this.boxType === 'PREFERENTIAL_DAY'){
							this.payTypeClick()
						}
						if(this.boxType === 'buy'){
							this.payTypeClick()
						}
					} else {
						this.$api.msg(res.message)
					}
				})
			},
			payTypeClick(){
				if (this.boxType === 'PREFERENTIAL_DAY') {
					 //每日优惠
					let data = {
						method: this.payType
					}
					uni.showLoading()
					activityOrderApi(data).then(result => {
						console.log("result.data:",result.data)
						// debugger
						// window.location.href = result.data.payParams.payinfo
						if(result.data.payParams.method !=="NONE"){
							window.location.href = result.data.payParams.payinfo
						}
							let clearTime = 0
						// 活动调起支付埋点
						reportClickFn('box_activity_review_pay_clk')
						if (result.code === 200) {
							this.timer = setInterval(() => {
								this.getBoxOrderPaid(result.data.no)
								clearTime += 3
								if(clearTime == 30){
									uni.hideLoading()
									clearInterval(this.timer)
									this.timer = null
									this.$api.msg("未查询到支付结果")
								}
							}, 3000);
						} else {
							this.$api.msg(result.message)
						}
					})
				} else if(this.boxType === 'buy') {
					// 普通盲盒购买
					let data = {
						boxId: this.detailData.id,
						type: this.type,
						method: this.payType
					}
					if (this.previewData.couponId) {
						data['couponId'] = this.previewData.couponId
					}
				
					uni.showLoading()
					boxOrderApi(data).then(result => {
						// 盲盒调起支付埋点
						reportClickFn('box_buy_review_pay_clk')
						if(this.isDetail){
							// 指定盲盒详情订单预览调起支付
							reportClickFn(`boxId_detail_review_pay_${this.detailData.id}`)
						}else{
							// 指定盲盒订单预览调起支付
							reportClickFn(`boxId_review_pay_${this.detailData.id}`)
						}
						
						if (result.code === 200) {
							
							// console.log("result.data:",result.data)
							// debugger
							if(result.data.payParams.method !=="NONE"){
								window.location.href = result.data.payParams.payinfo
							}
							
							let clearTime = 0
							this.getBoxOrderPaid(result.data.no)
							this.timer = setInterval(() => {
								this.getBoxOrderPaid(result.data.no)
								clearTime += 3
								if(clearTime == 30){
									uni.hideLoading()
									clearInterval(this.timer)
									this.timer = null
									this.$api.msg("未查询到支付结果")
								}
							}, 3000);
						} else {
							this.$api.msg(result.message)
						}
					}).catch(err => {
						uni.hideLoading()
					})
				}
			},
			// 使用提示卡
			card(){
				this.$emit('isOk')
				uni.navigateTo({
					url:`/pages/index/card?boxId=${this.previewData.boxId}&type=${this.type}&couponId=${this.previewData.couponId}`
				})
			},
			// 获取支付方式
			getPayMethod(){
				payMethodApi({type:'COIN_RECHARGE'}).then(res => {
					console.log(res)
					if(res.code === 200){
						this.payList = []
						res.data.forEach(item => {
						            let objToAdd = null;
						
						            if (item === 'ALIPAY') {
						                objToAdd = {
						                    label: '支付宝支付',
						                    type: 'ALIPAY',
						                    visible: false,
						                    height: '30rpx',
						                    width: '30rpx',
						                    img: '../../static/home/zfb.png',
						                };
						            } else if (item === 'WECHAT') {
						                objToAdd = {
						                    label: '微信支付',
						                    type: 'WECHAT',
						                    visible: false,
						                    width: '34rpx',
						                    height: '29rpx',
						                    img: '../../static/home/wx.png',
						                };
						            } else if (item === 'POINTS') {
						                objToAdd = {
						                    label: "积分支付",
						                    type: 'POINTS',
						                    visible: false,
						                    img: '../../static/an/point.gif',
						                    width: '30rpx',
						                    height: '31rpx'
						                };
						            } else if (item === 'NONE') {
						                objToAdd = {
						                    label: "无需支付",
						                    type: 'NONE',
						                    visible: false,
						                    img: '../../static/home/wxzf.png',
						                    width: '32rpx',
						                    height: '34rpx'
						                };
						            } else if (item === 'COIN') {
						                objToAdd = {
						                    label: "代币支付",
						                    type: 'COIN',
						                    visible: false,
						                    img: '../../static/an/point.gif',
						                    width: '32rpx',
						                    height: '34rpx'
						                };
						            }
						
						            // 只有在objToAdd被赋值的情况下才添加到payList
						            if (objToAdd) {
						                if (objToAdd.type === 'WECHAT') {
						                    // 如果是WECHAT类型，则先添加到数组第一位
						                    this.payList.unshift(objToAdd);
						                } else {
						                    // 其他类型添加到数组末尾
						                    this.payList.push(objToAdd);
						                }
						            }
						        });
						this.payList[0].visible = true
						this.payType = this.payList[0].type
					}
				})
			},
			// 切换支付方式
			payChange(index, item) {
				this.payList.forEach((v, i) => {
					v.visible = false;
				})
				this.payType = item.type
				this.payList[index].visible = !this.payList[index].visible
				this.payinfoUrl = ''
			},
			// 活动盲盒订单预览
			getActivityReview(){
				activityReviewSourceApi({source:this.boxType}).then(res => {
					console.log("activityReviewSourceApi",res)
					if (res.code === 200) {
						if(this.isActivityClick){
							if(this.boxType === 'SPECIAL_PRICE'){
								// 点击打开薅羊毛订单预览数
								reportClickFn('box_special_price_clk_activity_review');
							}
							if(this.boxType === 'ROOKIE'){
								// 点击打开新人福利订单预览数
								reportClickFn('box_clk_activity_review');
							}
						}else{
							if(this.boxType === 'SPECIAL_PRICE'){
								// 首次弹出薅羊毛订单预览数
								reportClickFn('box_special_price_activity_review');
							}
							if(this.boxType === 'ROOKIE'){
								// 首次弹出新人福利订单预览数
								reportClickFn('box_activity_review');
							}
							
						}
						
						userInfo().then(result => {
							if (result.code === 200) {
								this.previewData = res.data
								this.userInfo = result.data
								
								
								this.payList = []
								this.previewData.methods.forEach(item => {
								            let objToAdd = null;
								            if (item === 'ALIPAY') {
								                objToAdd = {
								                    label: '支付宝支付',
								                    type: 'ALIPAY',
								                    visible: false,
								                    height: '30rpx',
								                    width: '30rpx',
								                    img: '../../static/home/zfb.png',
								                };
								            } else if (item === 'WECHAT') {
								                objToAdd = {
								                    label: '微信支付',
								                    type: 'WECHAT',
								                    visible: false,
								                    width: '34rpx',
								                    height: '29rpx',
								                    img: '../../static/home/wx.png',
								                };
								            } else if (item === 'POINTS') {
								                objToAdd = {
								                    label: "积分支付",
								                    type: 'POINTS',
								                    visible: false,
								                    img: '../../static/an/point.gif',
								                    width: '30rpx',
								                    height: '31rpx'
								                };
								            } else if (item === 'NONE') {
								                objToAdd = {
								                    label: "无需支付",
								                    type: 'NONE',
								                    visible: false,
								                    img: '../../static/home/wxzf.png',
								                    width: '32rpx',
								                    height: '34rpx'
								                };
								            } else if (item === 'COIN') {
								                objToAdd = {
								                    label: "代币支付",
								                    type: 'COIN',
								                    visible: false,
								                    img: '../../static/an/point.gif',
								                    width: '32rpx',
								                    height: '34rpx'
								                };
								            }
								
								            // 只有在objToAdd被赋值的情况下才添加到payList
								            if (objToAdd) {
								                if (objToAdd.type === 'WECHAT') {
								                    // 如果是WECHAT类型，则先添加到数组第一位
								                    this.payList.unshift(objToAdd);
								                } else {
								                    // 其他类型添加到数组末尾
								                    this.payList.push(objToAdd);
								                }
								            }
								        });
								this.payList[0].visible = true
								console.log("this.payList[0].type:",this.payList)
								this.payType = this.payList[0].type
								
								
							} else {
								this.$api.msg(result.message)
							}
						})
						// this.boxId = res.data.boxId
					}else{
						this.$api.msg(res.message)
					}
				})
			},
			// 订单预览
			getDetail() {
				boxOrderReviewApi({
					boxId: this.detailData.id,
					type: this.type
				}).then(res => {
					console.log(res.data)
					if (res.code === 200) {
						userInfo().then(result => {
							if (result.code === 200) {
								this.previewData = res.data
								this.userInfo = result.data
								this.payList = []
								this.previewData.methods.forEach(item => {
								            let objToAdd = null;
								            if (item === 'ALIPAY') {
								                objToAdd = {
								                    label: '支付宝支付',
								                    type: 'ALIPAY',
								                    visible: false,
								                    height: '30rpx',
								                    width: '30rpx',
								                    img: '../../static/home/zfb.png',
								                };
								            } else if (item === 'WECHAT') {
								                objToAdd = {
								                    label: '微信支付',
								                    type: 'WECHAT',
								                    visible: false,
								                    width: '34rpx',
								                    height: '29rpx',
								                    img: '../../static/home/wx.png',
								                };
								            } else if (item === 'POINTS') {
								                objToAdd = {
								                    label: "积分支付",
								                    type: 'POINTS',
								                    visible: false,
								                    img: '../../static/an/point.gif',
								                    width: '30rpx',
								                    height: '31rpx'
								                };
								            } else if (item === 'NONE') {
								                objToAdd = {
								                    label: "无需支付",
								                    type: 'NONE',
								                    visible: false,
								                    img: '../../static/home/wxzf.png',
								                    width: '32rpx',
								                    height: '34rpx'
								                };
								            } else if (item === 'COIN') {
								                objToAdd = {
								                    label: "代币支付",
								                    type: 'COIN',
								                    visible: false,
								                    img: '../../static/an/point.gif',
								                    width: '32rpx',
								                    height: '34rpx'
								                };
								            }
								
								            // 只有在objToAdd被赋值的情况下才添加到payList
								            if (objToAdd) {
								                if (objToAdd.type === 'WECHAT') {
								                    // 如果是WECHAT类型，则先添加到数组第一位
								                    this.payList.unshift(objToAdd);
								                } else {
								                    // 其他类型添加到数组末尾
								                    this.payList.push(objToAdd);
								                }
								            }
								        });
								this.payList[0].visible = true
								console.log("this.payList[0].type:",this.payList)
								this.payType = this.payList[0].type
								
								
							} else {
								this.$api.msg(result.message)
							}
						})
					} else {
						this.$api.msg(res.message)
					}
				})
			},
			// 切换购买类型
			goBuy(type,index) {
				this.typeIndex = index
				this.type = type
				this.getDetail()
			},
			// 立即支付
			pay() {
				clearInterval(this.timer)
				this.timer = null
				uni.hideLoading()
				clearInterval(this.rookieTimer)
				this.rookieTimer = null
				if(this.boxType === 'buy'){
					// 普通盲盒购买
					let data = {
						boxId: this.detailData.id,
						type: this.type,
						method: this.payType
					}
					if (this.previewData.couponId) {
						data['couponId'] = this.previewData.couponId
					}
									
					uni.showLoading({
						mask:true
					})
					boxOrderApi(data).then(result => {
						// 盲盒调起支付埋点
						reportClickFn('box_buy_review_pay_clk')
						if(this.isDetail){
							// 指定盲盒详情订单预览调起支付
							reportClickFn(`boxId_detail_review_pay_${this.detailData.id}`)
						}else{
							// 指定盲盒订单预览调起支付
							reportClickFn(`boxId_review_pay_${this.detailData.id}`)
						}
						
						if (result.code === 200) {
							
							// console.log("result.data:",result.data)
							// debugger
							if(result.data.payParams.method !=="NONE"){
								window.location.href = result.data.payParams.payinfo
							}
							
							let clearTime = 0
							this.getBoxOrderPaid(result.data.no)
							this.timer = setInterval(() => {
								this.getBoxOrderPaid(result.data.no)
								clearTime += 3
								if(clearTime == 30){
									uni.hideLoading()
									clearInterval(this.timer)
									this.timer = null
									this.$api.msg("未查询到支付结果")
								}
							}, 3000);
						} else {
							this.$api.msg(result.message)
						}
					}).catch(err => {
						uni.hideLoading()
					})
				}else{
					let data = {
						method: this.payType,
						source:this.boxType
					}
					// uni.showLoading({
					// 	mask:true
					// })
					this.timeSec = 0
					activitySourceBuyApi(data).then(res => {
						if (res.code === 200) {
							if (res.data.payParams.payinfo) {
								// 活动调起支付埋点
								reportClickFn('box_activity_review_pay_clk')
								if(this.isActivityClick){
									
									if(this.boxType === 'SPECIAL_PRICE'){
										// 首次弹出薅羊毛订单预览调起支付数
										reportClickFn('box_clk_special_price_activity_review_pay');
									}
									if(this.boxType === 'ROOKIE'){
										// 点击打开新人福利订单预览调起支付数
										reportClickFn('box_clk_activity_review_pay');
									}
								}else{
									
									
									
									
									if(this.boxType === 'SPECIAL_PRICE'){
										// 首次弹出薅羊毛订单预览调起支付数
										reportClickFn('box_special_price_activity_review_pay');
									}
									if(this.boxType === 'ROOKIE'){
										// 首次弹出新人福利订单预览调起支付数
										reportClickFn('box_activity_review_pay');
									}
								}
								// uni.hideLoading()
								// this.boxOrderNo = res.data.boxOrderNo
								window.location.href = res.data.payParams.payinfo
								console.log("aaa:",res)
								// this.boxOrderNo = res.data.boxOrderNo
								// this.getCoinPaid(res.data.no)
								// this.rookieTimer = setInterval(() => {
								// 	this.timeSec += 3
								// 	this.getCoinPaid(res.data.no)
								// }, 3000);
								
								// 新增支付弹框
								let listLength = 1
								if(this.previewData.type === 'SINGLE'){
									listLength = 1
								}else if(this.previewData.type === 'TRIPLE'){
									listLength = 3
								}else{
									listLength = 5
								}
								// uni.navigateTo({
								// 	url: `/pages/index/draw?no=${no}&boxId=${this.previewData.boxId}&type=${listLength}`
								// })
								this.$emit('payStatus',{no:res.data.no,type:listLength,boxId:this.previewData.boxId})
								// 新增支付弹框
								
								
								
								let clearTime = 0
								this.getBoxOrderPaid(res.data.no)
								this.rookieTimer = setInterval(() => {
									console.log("result.data.no:",res.data.no)
									this.getBoxOrderPaid(res.data.no)
									clearTime += 3
									if(clearTime == 30){
										uni.hideLoading()
										clearInterval(this.rookieTimer)
										this.rookieTimer = null
										// this.$api.msg("未查询到支付结果")
									}
								}, 3000);
							}else{
								// this.boxOrderNo = res.data.boxOrderNo
								let clearTime = 0
								this.getBoxOrderPaid(res.data.no)
								this.rookieTimer = setInterval(() => {
									this.getBoxOrderPaid(res.data.no)
									clearTime += 3
									if(clearTime == 30){
										uni.hideLoading()
										clearInterval(this.rookieTimer)
										this.rookieTimer = null
										this.$api.msg("未查询到支付结果")
									}
								}, 3000);
								// this.getCoinPaid(res.data.no)
								// this.rookieTimer = setInterval(() => {
								// 	this.getCoinPaid(res.data.no)
								// }, 3000);
							}
						} else {
							uni.hideLoading()
							this.$api.msg(res.message)
						}
					}).catch(err => {
						uni.hideLoading()
					})
				}
				// if (this.boxType === 'ROOKIE') {
				// 		// 新手盲盒购买
				// 		let data = {
				// 			method: this.payType
				// 		}
				// 		uni.showLoading()
				// 		this.timeSec = 0
				// 		activityBuyApi(data).then(res => {
				// 			if (res.code === 200) {
				// 				if (res.data.payParams.payinfo) {
				// 					// 活动调起支付埋点
				// 					reportClickFn('box_activity_review_pay_clk')
				// 					if(this.isActivityClick){
				// 						// 点击打开新人福利订单预览调起支付数
				// 						reportClickFn('box_clk_activity_review_pay');
				// 					}else{
				// 						// 首次弹出新人福利订单预览调起支付数
				// 						reportClickFn('box_activity_review_pay');
				// 					}
				// 					uni.hideLoading()
				// 					this.boxOrderNo = res.data.boxOrderNo
				// 					window.location.href = res.data.payParams.payinfo
				// 					this.boxOrderNo = res.data.boxOrderNo
				// 					this.getCoinPaid(res.data.no)
				// 					this.rookieTimer = setInterval(() => {
				// 						this.timeSec += 3
				// 						this.getCoinPaid(res.data.no)
				// 					}, 3000);
				// 				}else{
				// 					this.boxOrderNo = res.data.boxOrderNo
				// 					this.getCoinPaid(res.data.no)
				// 					this.rookieTimer = setInterval(() => {
				// 						this.getCoinPaid(res.data.no)
				// 					}, 3000);
				// 				}
				// 			} else {
				// 			}
				// 		}).catch(err => {
				// 			uni.hideLoading()
				// 		})
				// } else{
				// 	this.getUserInfo()
				// }
			},
			// 盲盒购买订单回调
			getBoxOrderPaid(no) {
				boxOrderPaidApi({
					no
				}).then(payResult => {
					console.log("payResult")
					if (payResult.data) {
						// 活动实际支付埋点
						if (this.boxType === 'PREFERENTIAL_DAY') {
							reportClickFn('box_activity_review_pay_accomplish_clk')
						}
						// 盲盒实际支付埋点
						if (this.boxType === 'buy') {
							reportClickFn('box_buy_review_pay_accomplish_clk')
							
							if(this.isDetail){
								// 指定盲盒详情订单预览支付成功
								reportClickFn(`boxId_detail_review_pay_accomplish_${this.detailData.id}`)
							}else{
								// 指定盲盒订单预览支付成功
								reportClickFn(`boxId_review_pay_accomplish_${this.detailData.id}`)
							}
							
						}
						
						if(this.isActivityClick){
							
							if(this.boxType === 'SPECIAL_PRICE'){
								// 点击打开薅羊毛订单预览支付成功数
								reportClickFn('box_special_price_clk_activity_review_pay_accomplish');
							}
							if(this.boxType === 'ROOKIE'){
								// 点击打开新人福利订单预览支付成功数
								reportClickFn('box_clk_activity_review_pay_accomplish');
							}
							if(this.boxType === 'NINE'){
								// 点击打开九连抽订单预览支付成功数
								reportClickFn('box_clk_nine_review_pay_accomplish');
							}
						}else{
							if(this.boxType === 'SPECIAL_PRICE'){
								// 首次弹出薅羊毛订单预览支付成功数
								reportClickFn('box_special_price_activity_review_pay_accomplish');
							}
							if(this.boxType === 'ROOKIE'){
								// 首次弹出新人福利订单预览支付成功数
								reportClickFn('box_activity_review_pay_accomplish');
							}
							if(this.boxType === 'NINE'){
								// 首次弹出九连抽订单预览支付成功数
								reportClickFn('box_nine_review_pay_accomplish');
							}
						}
						
						
						
						
						clearInterval(this.timer); // 清除定时器
						this.timer = null;
						clearInterval(this.rookieTimer); // 清除定时器
						this.rookieTimer = null;
						this.$emit('isOk')
						this.$api.msg('支付成功')
						let listLength = 1
						if(this.previewData.type === 'SINGLE'){
							listLength = 1
						}else if(this.previewData.type === 'TRIPLE'){
							listLength = 3
						}else{
							listLength = 5
						}
						console.log(`/pages/index/draw?no=${no}&boxId=${this.previewData.boxId}&type=${listLength}`)
						uni.navigateTo({
							url: `/pages/index/draw?no=${no}&boxId=${this.previewData.boxId}&type=${listLength}`
						})
						// uni.redirectTo({
						// 	url: `/pages/index/boxPaySuccess?no=${no}&boxId=${this.previewData.boxId}&name=${this.previewData.name}&type=${this.previewData.type}&sale=${this.previewData.total}`
						// })
						uni.hideLoading()
					}
				}).catch(err => {
					clearInterval(this.timer); // 清除定时器
					this.timer = null;
					uni.hideLoading()
				})
			},
			// 查询新手盲盒支付订单
			getCoinPaid(no) {
				coinPaidApi({
					no
				}).then(payResult => {
					if (payResult.data) {
						// 活动实际支付埋点
						reportClickFn('box_activity_review_pay_accomplish_clk')
						if(this.isActivityClick){
							// 点击打开新人福利订单预览支付成功数
							reportClickFn('box_clk_activity_review_pay_accomplish');
						}else{
							// 首次弹出新人福利订单预览支付成功数
							reportClickFn('box_activity_review_pay_accomplish');
						}
						clearInterval(this.rookieTimer); // 清除定时器
						this.rookieTimer = null;
						this.$emit('isOk')
						this.$api.msg('支付成功')
						uni.navigateTo({
							url: `/pages/index/draw?no=${this.boxOrderNo}&boxId=${this.previewData.boxId}&type=1`
						})
						// uni.redirectTo({
						// 	url: `/pages/index/boxPaySuccess?no=${this.boxOrderNo}&boxId=${this.previewData.boxId}&name=${this.previewData.name}&type=${this.previewData.type}&sale=${this.previewData.amount.sale}`
						// })
						uni.hideLoading()
					}
				}).catch(err => {
					clearInterval(this.timer); // 清除定时器
					this.timer = null;
					uni.hideLoading()
				})
			},
		},
		onUnload() {
			// 在页面离开时清除定时器
			clearInterval(this.timer);
			clearInterval(this.rookieTimer)
		}
	}
</script>

<style lang="scss" scoped>
	.buy-popup {
		width: 750rpx;
		height: 713rpx;
		background: linear-gradient(to bottom, #91E6FF 0%, #FFFFFF 100%);
		border-radius: 20rpx 20rpx 0px 0px;
		padding: 17rpx 34rpx 30rpx 35rpx;

		.header-info{
			position: relative;
			display: flex;
			.info-img{
				width: 247rpx;
				height: 237rpx;
			}
			.info-right{
				margin-left: 57rpx;
				width: 368rpx;
				padding-top: 29rpx;
				.right-name{
					width: 368rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-weight: 600;
					font-size: 44rpx;
					color: #000000;
				}
				.right-price{
					font-weight: 500;
					font-size: 26rpx;
					color: #000000;
					margin-top: 14rpx;
				}
				.item{
					position: relative;
					margin-top: 42rpx;
					width: 368rpx;
					height: 65rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.label{
						font-weight: 600;
						font-size: 20rpx;
						color: #000000;
					}
					.value{
						font-weight: 600;
						font-size: 20rpx;
						color: #000000;
					}
					.d-x{
						position: absolute;
						top: 0;
						left: 0;
						width: 368rpx;
						height: 2rpx;
					}
				}
			}
			.c-x{
				position: absolute;
				bottom: 0;
				left: 0;
				height: 2rpx;
				width: 682rpx;
			}
		}
		.mains{
			padding-top: 34rpx;
			.pay{
				margin-bottom: 52rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.left{
					display: flex;
					align-items: center;
					font-weight: 500;
					font-size: 26rpx;
					color: #000000;
					.pay-icon{
						width: 49rpx;
						height: 49rpx;
						margin-right: 15rpx;
					}
				}
				.select-icon{
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
		.popup-buy{
			width: 700rpx;
			height: 85rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background-image: url('@/static/home/a-btn.png');
			background-repeat: no-repeat;
			background-size: 100%;
			font-family: YouSheBiaoTiHei;
			font-size: 46rpx;
			color: #FFFFFF;
		}
	}
</style>