<template>
	<view v-if="isShow">
		<view class="top">
			<view v-if="detail.imageList.length>0">
				<swiper autoplay="true"
					circular="true" duration="1000" class="act-img">
					<block v-for="(item, index) in detail.imageList" :key="index">
						<swiper-item autoplay="true">
							<image class="act-img" lazy-load="true" :src="item.url"
								mode="aspectFill"></image>
						</swiper-item>
					</block>
				</swiper>
			</view>
			<image :src="detail.pic" mode="aspectFill" class="act-img" v-else></image>
			<view class="title">{{detail.title}}</view>
			<view class="datas">浏览 {{detail.popularity}}  收藏  {{detail.collect}}</view>
			
			<view class="baoming-box">
				<view class="ddflex">
					<image src="../static/images/bmsj.png"></image>
					<text>报名时间</text>
				</view>
				<view class="baoming-time">{{formData(detail.enlistStartTime)}} 至 {{formData(detail.enlistEndTime)}}</view>
				<view class="ddflex" style="margin-top: 25rpx;">
					<image src="../static/images/bmfy.png" style="visibility: hidden;"></image>
					<text>活动时间</text>
				</view>
				<view class="baoming-time">
					{{formData(detail.startTime)}} 至 {{formData(detail.endTime)}}
				</view>
			</view>
			
			<view class="hddz-box" style="margin-top: 26rpx;" v-if="detail.address">
				<view class="ddflex">
					<image src="../static/images/hddz.png"></image>
					<text>活动地点</text>
				</view>
				<!-- v-if="detail.address" -->
				<view class="ddflex hddz-area" @click="openMap()">
					<view class="fflex tover">{{detail.address}}</view>
					<image src="../static/images/crico2.png" class="rico"></image>
				</view>
			</view>
		</view>
		
		<view class="date">
			<view class="datass ddflex" style="justify-content: space-between;" v-if="detail.card" @click="jumpUrl('/card/index/index?id='+detail.card.id)">
				<view class="ddflex">
					<image :src="detail.card.avatar?detail.card.avatar:'../../static/pages/images/userimg.png'" style="width:66rpx ;height: 66rpx;border-radius: 100%;" mode="aspectFill" class="dimg"></image>
					<view>
						<view style="font-size: 28rpx;font-weight: bold;color: #333333;line-height: 40rpx;">{{detail.card.realName}}</view>
						<view style="margin-top: 3rpx;" class="ddflex">
							<view class="user-tag">{{detail.card.companyName}}</view>
							<view class="user-tag">{{detail.card.jobName}}</view>
							<view class="user-tag">入司{{detail.card.inDate?monthDayDiff(detail.card.inDate):'1年'}}</view>
						</view>
					</view>
				</view>
				<image src="../static/images/crico2.png" class="rico"></image>
			</view>
		</view>
		<view class="det">
			<view class="tit ddflex">活动介绍<!-- <image src="../../static/pages/images/crico1.png" class="rico"></image> --></view>
			<view class="content" style="padding: 0 30rpx;">
				<mp-html :content="detail.text" :lazy-load="true" @imgtap="choose"></mp-html>
			</view>
		</view>
		<view class="savepadding"></view>
		<view class="bot fixed bgfff">
			<view class="savepadding ddflex" style="justify-content: space-between;">
				<view class="btnfot ddflex">
					<navigator class="botbtn" open-type="switchTab" url="" hover-class="none">
						<image src="/static/pages/images/sy.png"></image>主页
					</navigator>
					<view class="botbtn">
						<image src="/static/pages/images/shoucang_h.png" v-if="detail.isCollect"></image>
						<image src="/static/pages/images/shoucang.png" v-else></image>收藏
					</view>
					<view class="botbtn"><image src="../static/images/fxico1_1.png"></image>分享</view>
					<!-- <button open-type="share" class="botbtn">
						<image src="../../static/pages/images/fxico1_1.png"></image>分享
					</button> -->
				</view>
				<view class="btns ddflex">
					<view class="btn" v-if="detail.isEnlist">查看报名</view>
					<block v-else>
						<view class="btn" v-if="detail.state == 2">立即报名</view>
						<view class="btn" v-if="detail.state == 3">报名结束</view>
						<view class="btn" v-if="detail.state == 4">活动中</view>
						<view class="btn end" v-if="detail.state == 5">活动结束</view>
					</block>
				</view>
			</view>
		</view>
		<view class="ceng" v-if="popShow" @click="hidePop()"></view>
		<view class="popup" v-if="popShow">
			<image src="../../static/pages/images/clear.png" class="close" @click="hidePop()"></image>
			<view class="p-title">{{detail.title}}</view>
			<view class="p-bri tovers">{{detail.brief}}</view>
			<view class="money free"><text>￥</text>{{price}}</view>
			<view class="pop-tit">报名项目</view>
			<view class="pop-con">
				<view class="p-list ddflex">
					<view :class="'li' + (priceIndex == index ? ' active' : '')" v-for="(item,index) in priceList" :key="index" @click="selProject(item,index)">{{item.title}}</view>
				</view>
			</view>
			<view class="pop-btn" 马上报名</view>
		</view>
			
	</view>
</template>

<script>
const req = require('../../utils/request.js');
const util = require('../../utils/util.js');
const app = getApp();
import mpHtml from "../../components/mp-html/components/mp-html/mp-html";
export default {
	components: {
		mpHtml,
	},
	data() {
		return {
			isShow: false,
			options: {},
			detail: {},
			isLogin: false,
			userinfovip: {},
			isIos: false,
			priceIndex: 0,
			priceList: [],
			popShow: false,
			priceId: '',
			price: 0,
			hideShare: true,
			codeUrl: '',
			
			isShowUpdate: false, //是否显示更新信息弹窗
			isUpdateInfo: false,//更新用户信息
			isUpdateMobile: false,//绑定手机号
			
			enterTime : '',//进入页面时间
			outTime : '',//页面卸载时间
			stayTime : 0//页面停留时间
		};
	},
	async onLoad(options) {
		this.options = options;
	},
	async onShow() {
		await this.getConfig();
		await this.getData(true);
	},
	onReachBottom: function() {
	},
	methods: {
		getConfig() {
			var _this = this;
			return new Promise((resolve, reject) => {
				req.getRequest('/api/other/config', {}, function(res) {
					_this.about = res;
					_this.getSystem();
					resolve();
				});
			});
		},
		getSystem(){
			if(uni.getSystemInfoSync().platform == 'ios'){
				if(this.about.is_open_iosPay == 1){
					this.isIos = false;
				}else{
					this.isIos = true;
				}
			}else{
				this.isIos = false;
			}
		},
		getData(isShow){
			return new Promise((resolve, reject) => {
				req.getRequest('/api/match/detail',{id: this.options.id},async　res => {
					this.detail = res;
					
					// 外链活动
					if(this.detail.type==2 && this.detail.text){
						let url = this.detail.text
						url = url + '?salesno=' +　req.getStorage('userInfo').saleNo
						// 如果打开的分享的销售员微页
						// if(req.getStorage('shareId')){
						// 	url = url + '?salesno=' + req.getStorage('shareId')
						// }else{
						// 	// 如果自己是销售员
						// 	if(req.getStorage('userInfo').saleNo){
						// 		url = url + '?salesno=' +　req.getStorage('userInfo').saleNo
						// 	}else{
						// 		//当前绑定的微页或推荐的微页
						// 		let salesno = await new Promise((r,j)=>{
						// 			req.getLocation(res => {
						// 				const to = {
						// 					latitude: res.latitude,
						// 					longitude: res.longitude
						// 				};
						// 				req.getRequest('/api/visiting/card/recommendCardInfo', to, res => {
						// 					r(res.jobNumber?res.jobNumber:'')
						// 				})
						// 			});
						// 		})
						// 		url = url + '?salesno=' +　salesno
						// 	}
						// }
						uni.redirectTo({
							url: '/pages/web/web?url='+encodeURIComponent(url)
						});
						
						return false
					}
					
					this.isShow = true;
					resolve();
				},isShow);
			})
		},
		getPrice(){
			return new Promise((resolve, reject) => {
				req.getRequest('/api/match/price',{id: this.options.id},res=>{
					this.priceList = res;
					this.priceId = res[0].id;
					let price = 0;
					if(this.userinfovip.levelGrade>0&& !this.userinfovip.end){
						price = res[0].vipMoney;
					}else{
						price = res[0].money;
					}
					this.price = price;
					req.setStorage('actPrice',price)
					resolve();
				})
			})
		},
		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();
			})
		},
		formatTimeCommStr(dataStr) {
			return util.formatTimeCommStr(dataStr, 'M/D 00:00');
		},
		formData(validDate){
			let time = new Date(validDate.replace(/-/g, '/'));
			return util.formatTime(time).t2
		},
		formDataObj(validDate){
			let time = new Date(validDate.replace(/-/g, '/'));
			return util.formatTime(time)
		},
		formDatahd(){
			if(this.detail.startTime&&this.detail.endTime){}
			else return false
			return this.formDataObj(this.detail.startTime).t2==this.formDataObj(this.detail.endTime).t2?
			(this.formDataObj(this.detail.startTime).t2+' '+this.formDataObj(this.detail.startTime).t6+' - '+this.formDataObj(this.detail.endTime).t6)
			:(this.formDataObj(this.detail.startTime).t5+' - '+this.formDataObj(this.detail.endTime).t5)
		},
		getBrowse(){
			let params={
				bindId: this.options.id,
				type: 10
			}
			req.postRequest('/api/browse', params, data => {});
		},
		toActivity(item){
			uni.navigateTo({
				url: '/match/activityDetail/activityDetail?id=' + item.id
			})
		},
		choose: function () {
		  let freshen = false;
		  this.$emit('freshen', {
		    detail: freshen
		  });
		},
		// clickCollect(){
		// 	req.isLogin().then(success => {
		// 		if(success){
		// 			req.postRequest('/api/collect',{
		// 				bindId: this.detail.id,
		// 				type: 2
		// 			},res=>{
		// 				this.detail.isCollect = !this.detail.isCollect;
		// 			})
		// 		}
		// 	})
		// },
		// 用户行为
		userBehavior(type) {
			var dataP = {};
			dataP.type =2 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
			dataP.behavior = type; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
			dataP.bindId = this.detail.id;
			req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
				if (type == 2) {
					this.detail.isCollect = !this.detail.isCollect;
					if(this.detail.isCollect){
						req.saveBehaviorNew(this.detail.id,2,2)
					}else{
						req.saveBehaviorNew(this.detail.id,2,16)
					}
				}
				if (type == 3) {
					this.cardInfo.follow = !this.cardInfo.follow
				}
				if(type == 4) {
					// req.saveBehaviorNew(this.detail.id,2,4)
				}
			});
		},
		showPop(){
			let that = this;
			that.jumpUrl('/match/sign/sign?id=' + that.detail.id);
		},
		hidePop(){
			this.popShow = false;
		},
		selProject(it,idx){
			if(this.priceIndex == idx) return false;
			this.priceIndex = idx;
			this.priceId = it.id;
			console.log('priceId==' + this.priceId)
			let price = 0;
			if(this.userinfovip.levelGrade>0&& !this.userinfovip.end){
				price = it.vipMoney;
			}else{
				price = it.money;
			}
			this.price = price;
			req.setStorage('actPrice',price)
		},
		jumpUrl(url){
			req.isLogin().then(success => {
				if(success){
					uni.navigateTo({
						url: url
					})
				}
			})
			this.hidePop();
		},
		showShare() {
			// console.log(11111,this.hideShare)
			// #ifdef H5 
			this.setData({
				hideShare: false
			});
		
			// #endif
			// #ifndef H5
			req.isLogin().then(success => {
				// console.log(success)
				if (success) {
					this.getCodeUrl()
					this.setData({
						hideShare: false
					});
					// console.log(this.hideShare)
				}
			});
			// #endif
		},
		getCodeUrl() {
			let that = this;
			let scene = that.detail.id;
			// console.log(scene); //获取小程序码
			const params = {
				page: 'match/activityDetail/activityDetail',
				scene: scene
			};
			req.getRequest('/api/program/codev', params, url => {
				that.setData({
					codeUrl: url
				});
			});
		},
		click(e) {
			// console.log(e,"7899")
			this.hideShare = e
		},
		loadCodeParams() {
			let _ts = this;
			return new Promise((resolve, reject) => {
				let form = {
					scene: _ts.options.scene
				};
				if (!_ts.options.scene) {
					resolve();
					return false;
				}
				req.getRequest('/api/code/params', form, data => {
					let res = data.scene.split('_');
					this.options.id = res[0];
					req.setStorage('pidCode', data.userId);
					resolve();
				});
			});
		},
		monthDayDiff(date){
			return util.monthDayDiff(date)
		},
		
		closeUpdate(){
			this.isShowUpdate = false
		},
		updateInfo(e){
			this.isUpdateInfo = e;
		},
		updateMobile(e){
			this.isUpdateMobile = e;
		},
		getUpdate() {
			console.log('getUpdate')
			let userInfos = req.getStorage('userInfo')
			// if ((!userInfos.avatar || userInfos.avatar.indexOf('thirdwx.qlogo') > -1 || !userInfos.nickName || userInfos.nickName.indexOf('用户') > -1) ) {
			// 	console.log('没有昵称')
			// 	this.isShowUpdate = true;
			// 	this.isUpdateInfo = true;
			// 	return false;
			// }
			if(!userInfos.mobile){
				console.log('没有手机号')
				this.isShowUpdate = true
				this.isUpdateMobile = true
				return false;
			}
			return true;
		},
	}
};
</script>

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