<template>
	<view>
		<view class="top">
			<view class="ddflex">
				<image :src="detail.pic" mode="aspectFill" class="act-img"></image>
				<view class="fflex">
					<view class="title tovers">{{detail.title}}</view>
					<view class="sta ddflex">
						<view class="area fflex ddflex" v-if="detail.address">
							<image src="../static/images/dzico1.png"></image>
							<view class="tover fflex">{{detail.address}}</view>
						</view>
						<!-- <view class="money" v-if="userinfovip.levelGrade>0&& !userinfovip.end">￥{{detail.vipMoney}}</view> -->
						<view class="money">￥{{price}}</view>
					</view>
				</view>
			</view>
			<view class="date">
				<view class="time ddflex"><!-- <image src="../static/images/sjico.png"></image> -->报名时间：{{ detail.enlistStartTime }}-{{ detail.enlistEndTime }}</view>
				<view class="time ddflex"><!-- <image src="../static/images/sjico.png"></image> -->活动时间：{{ detail.startTime }}-{{ detail.endTime }}</view>
			</view>
			<view class="piao ddflex" v-if="money > 0">
				<view class="fflex">收费票</view>
				<view class="num">x{{personList.length}}</view>
				<view class="price"><text>￥</text>{{money}}</view>
			</view>
		</view>
		<view class="list">
			<view class="li ddflex" v-for="(item,index) in personList" :key="index">
				<view class="fflex">{{item.name}}</view>
				<text>{{item.phone}}</text>
			</view>
		</view>
		<view class="ming">
			<view class="tits">活动说明</view>
			<view class="tips">
				<view>1、本活动由主办方处理退款事宜</view>
				<view>2、如需退款，请联系客服</view>
			</view>
		</view>
		<view class="bot ddflex">
			<view class="heji">合计：<text class="yuan">￥</text><text>{{money}}</text></view>
			<view class="btn" @click="pay()">确认支付</view>
		</view>
	</view>
</template>

<script>
const req = require('../../utils/request.js');
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');
const requsetmessage = require('../../utils/requestmessage.js');
const app = getApp();
export default {
	components: {
	},
	data() {
		return {
			isShow: false,
			options: {},
			detail: {},
			isAdd: false,
			personList: [],
			money: 0,
			userinfovip: {},
			price: 0
		};
	},
	onLoad(options) {
		this.options = options;
		if(req.getStorage('personList')){
			this.personList = req.getStorage('personList')
		}
	},
	onShow() {
		this.price = req.getStorage('actPrice');
		this.getuserVip();
		this.getData(true);
		this.money = this.personList.length * this.price;
	},
	methods: {
		getData(isShow){
			let that = this;
			return new Promise((resolve,reject)=>{
				req.getRequest('/api/match/detail',{id: this.options.id},res => {
					that.detail = res;
					that.isShow = true;
					// if(that.userinfovip.levelGrade>0&& !that.userinfovip.end){
					// 	that.money = that.personList.length * res.vipMoney;
					// }else{
					// 	that.money = that.personList.length * res.money;
					// }
					resolve();
				},isShow);
			})
		},
		formatTimeCommStr(dataStr) {
			return util.formatTimeCommStr(dataStr, 'M/D');
		},
		getuserVip() {
			return new Promise((resolve,reject)=>{
				req.getRequest('/api/user/levelDetails', {}, data => {
					let expireTime = Array;
					if (data.expireTime) {
						expireTime = data.expireTime.split(" ");
						data.expireTime = data.expireTime.replace(/-/g, '/');
					} // 解决苹果不兼容---日期
					let nowTime = new Date().getTime();
					let endTime = new Date(data.expireTime).getTime();
					let times = parseInt((endTime - nowTime) / 1000); // var expireTime= new Date(data.expireTime)
					// console.log(times, nowTime, endTime, data.expireTime);
					this.userinfovip = data;
					if (times <= 0) {
						this.userinfovip.end = true;
					} else {
						this.userinfovip.end = false;
					}
					resolve();
				});
			})
		},
		toActivity(item){
			uni.navigateTo({
				url: '/match/activityDetail/activityDetail?id=' + item.id
			})
		},
		choose: function () {
		  let freshen = false;
		  this.$emit('freshen', {
		    detail: freshen
		  });
		},
		clickCollect(){
			req.postRequest('/api/collect',{
				bindId: this.detail.id,
				type: 2
			},res=>{
				this.detail.isCollect = !this.detail.isCollect;
			})
		},
		jumpUrl(url){
			uni.navigateTo({
				url: url
			})
		},
		async pay(){
			let param = {
				// matchId: this.detail.id,
				money: this.money,
				matchPriceId: this.options.priceId,
				scene: req.getStorage('scene'),
				list: JSON.stringify(this.personList)
			}
			await requsetmessage.remindActivity().then(res => {});
			req.postRequest('/api/myMatch/order',param,async res=>{
				req.removeStorage('personList');
				await this.payOrder(res)
			})
		},
		payOrder(id){
			req.payOrders(id,success =>{
				this.jumpUrl('/match/success/success?id=' + this.detail.id)
			})
		}
	}
};
</script>

<style>
	@import "./signConfirm.css";
</style>
