<template>
	<view class="ayuu" v-if="info">
		<view class="hduuyr">
			<!-- 图片预留 -->
			<image :src="info.imglist[0]" mode="aspectFill" class="w-1 h-1"></image>
		</view>

		<view class="hdxqmmfr" style="position: relative;">
			<view class="flztoa hdlixmr">
				<text>{{info.title}}</text>
			</view>
			<view class="hdxiahuax"></view>
			 <!-- @click="show = true" -->
			<view class="flztoa hdlixmr" @click="openLoaction">
				<text>{{info.city+info.address}}</text>
				<image src="/static/user/hda1.png" style="width: 48rpx;min-width: 48rpx;height: 48rpx;" mode=""></image>
			</view>
			<view class="hdxiahuax"></view>

			<view class="flztoa hdlixmr">
				<text>{{$u.timeFormat(info.date, 'yyyy-mm-dd hh:MM')}}</text>
			</view>
			<view class="hdxiahuax"></view>

			<view class="flztoa hdlixmr">
				<view class="fzctob">
					<text class="wdjga">¥</text>
				<!-- 	<text class="wdjgb">00</text>
					<text class="wdjgc">.00</text> -->
					<text class="wdjgb">{{info.price.split('.')[0]}}</text>
					<text class="wdjgc">.{{info.price.split('.')[1]}}</text>
				</view>
			</view>
			<view class="hdxiahuax"></view>

			<view class="" style="padding: 20rpx 24rpx;">
				<view class="indhuyr">
					<view class="indjbrr"></view>
					<text>活动详情</text>
				</view>

				<view class="hdxqtxtye">
					<rich-text :nodes="info.content"></rich-text>
				</view>

			</view>

		</view>

		<view class="fzddrew fknbee">
			<view class="fzddrew fkdibr" @click="showa = true">
				<text>立刻报名</text>
			</view>
		</view>

		<u-popup v-model="show" mode="bottom" border-radius="20" :safe-area-inset-bottom="true">
			<view class="dituopa1 fzddrew">
				<view class="dituopa2">
					<text>腾讯地图</text>
				</view>
				<view style="background: #F4F4F4;width: 100%;height: 2rpx;"></view>
				<view class="dituopa2">
					<text>百度地图</text>
				</view>
			</view>
		</u-popup>

		<u-popup v-model="showa" mode="bottom" border-radius="20" :safe-area-inset-bottom="true">
			<view class="baominga1">
				<view class="fzjtod baominga2">
					<text>立刻报名</text>
				</view>
				<view style="background: #F4F4F4;width: 100%;height: 2rpx;"></view>
			
				<scroll-view style="max-height: 400rpx;" scroll-y>
					<view v-for="(item,index) in plist" :key="index">
						<view class="flztoa baominga3">
							<view class="">
								<text>姓名</text>
							</view>
							<view class="fyctoc" style="text-align: right;color: #999999;">
								<input type="text" v-model="item.name" placeholder-style="color: #999999;font-size: 28rpx; text-align: right;"
								placeholder="请输入姓名" />
							</view>
						</view>
						<view style="background: #F4F4F4;width: 100%;height: 2rpx;"></view>
						<view class="flztoa baominga3">
							<view class="">
								<text>电话</text>
							</view>
							<view class="fyctoc" style="text-align: right;color: #999999;">
								<input type="number" v-model="item.phone" placeholder-style="color: #999999; font-size: 28rpx; text-align: right;"
								placeholder="请输入电话" />
							</view>
						</view>
						<view style="background: #F4F4F4;width: 100%;height: 2rpx;"></view>
					</view>
				</scroll-view>
				<view class="flztoa baominga3">
					<view class="">
						<text>数量</text>
					</view>
					<view class="fyctoc" style="text-align: right;color: #999999;">
						 <view class="fyctoc">
							<image @click="lessItem" src="/static/user/bma1.png" style="width: 32rpx;height: 32rpx;" mode=""></image>
							<view  style="margin: 0 20rpx;">{{plist.length}}</view>
							<image  @click="addItem"  src="/static/user/bma2.png" style="width: 32rpx;height: 32rpx;" mode=""></image>
						 </view>
					</view>
				</view>
				<view style="background: #F4F4F4;width: 100%;height: 2rpx;"></view>
				<view class="flztoa baominga3">
					<view class="">
						<text>金额</text>
					</view>
					<view class="fzctob">
						<text class="wdjga">¥</text>
						<text class="wdjgb">{{account.split('.')[0]}}</text>
						<text class="wdjgc">.{{account.split('.')[1]}}</text>
					</view>
				</view>
				<view class="fzjtod" style="margin-top: 420rpx;">
					<!-- <navigator class="fzddrew fkdibr" url="../lecturer/my" hover-class="none">
						<text>提交订单</text>
					</navigator> -->
					<view class="fzddrew fkdibr" @click="subInfo">
						<text>提交订单</text>
					</view>
				</view>
				 
			</view>
		</u-popup>









	</view>
</template>
<style>
	page {
		background: #FAFAFA;
	}
</style>
<script>
	export default {
		data() {
			return {
				show: false,
				showa: false,
				showc: 1,
				id:0,   // 活动id
				info:null,
				plist:[
					{
						name:'',
						phone:''
					}
				],   // 报名人数组
				deviceType:'wxapp'
			}
		},
		onLoad(e) {
			// #ifdef APP-PLUS
				this.deviceType = 'wxh5'
			// #endif
			// #ifdef MP-WEIXIN
				this.deviceType = 'wxapp'
			// #endif
			this.id = e.id || 0
			this.getDetail()
		},
		computed:{
			account(){
				if(this.info){
					return (this.info.price*this.plist.length).toFixed(2)
				}else{
					return 0
				}
			}
		},
		methods:{
			openLoaction(){
				uni.openLocation({
					latitude: this.info.lotx/1,   	// 纬度
					longitude:  this.info.loty/1,		// 经度
					name:this.info.address,
					success: res=> {
						console.log(res,'success');
					}
				});
			},
			// 加一条
			addItem(){
				console.log('+++++')
				this.plist.push({
					name:'',
					phone:''
				})
			},
			// 减一条
			lessItem(){
				if(this.plist.length>1){
					this.plist.pop()
				}
			},
			getDetail(){
				this.$post({
					data:{
						do:'GoodInfo',
						data:{
							id:this.id,
							user_id:uni.getStorageSync('id'),
							pw:375
						}
					}
				}).then(res=>{
					this.info = res.data
				})
			},
			// 提交报名信息
			subInfo(){
				let flag = this.plist.every(item=>item.name&&item.phone)
				if(!flag){
					uni.showToast({
						title:'请完善报名人员信息',
						icon:'none'
					})
					return
				}
				this.$post({
					data:{
						do:'Good',
						data:{
							good_id:this.id,
							is_luck:"",
							luck_id:"",
							user_id:uni.getStorageSync('id'),
							pw:"375",
							app_content:this.plist
						},
						deviceType:this.deviceType
					}
				}).then(res=>{
					let pay = res.data
					// #ifdef APP-PLUS
					uni.requestPayment({
						provider: 'wxpay',
						orderInfo: pay.orderinfo, //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
						success() {
							uni.showToast({
								title: '支付成功'
							})
							setTimeout(()=>{
								uni.navigateTo({
									url:'/pages/lecturer/wdhd'
								})
							},1500)
						},
						fail(res) {
							console.log(res)
							uni.showToast({
								title: '支付失败',
								icon: 'error'
							})
						}
					})
					// #endif
					// #ifdef MP-WEIXIN
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: pay.timeStamp,
						nonceStr: pay.nonceStr,
						package: pay.package,
						signType: 'MD5',
						paySign: pay.paySign,
						success() {
							uni.showToast({
								title: '支付成功'
							})
							setTimeout(()=>{
								uni.navigateTo({
									url:'/pages/lecturer/wdhd'
								})
							},1500)
						},
						fail(res) {
							console.log(res)
							uni.showToast({
								title: '支付失败',
								icon: 'error'
							})
						}
					})
					// #endif
					
				})
			}
		}


	}
</script>

<style lang="scss" scoped>
	.dituopa2 {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		padding: 20rpx 0;
	}

	.baominga2 {
		font-size: 14px;
		font-family: Alibaba PuHuiTi-Medium, Alibaba PuHuiTi;
		font-weight: 500;
		color: #373737;
		padding: 30rpx 0;
	}
	.baominga3{
		padding: 20rpx  22rpx;
		font-size: 14px;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}
	.w-1{
		width: 100%;
	}
	.h-1{
		height: 100%;
	}
</style>
