<template>
	<view class="all">
		<u-mask :show="show" @click="show = false">
			<u-image width="100%" height="500px" :mode="'widthFix'" src="@/assets/static/img/guide_point2.png"></u-image>

		</u-mask>

		<ujp-navbar title="凭话费领年卡活动" :startGz="false" :isBack="back"></ujp-navbar>
		<view class="InviteFriends" :class="{
			opacityClass:show
		}">
			<view class="text imgHead">
				<view class="imgHead1">
					<img  v-if="branchParameterBl('ud')"  style="width: 125px; height: 40px;" src="@/assets/logo/logo4Ud.png" alt="">
					
					<img v-else   style="width: 125px;" src="@/assets/logo/logo1.png"></img>


				</view>
				<view class="imgHead2">
					<img style="width: 252px;height: 40px;" src="@/assets/img/piccShare/5.png"></img>
				</view>
			</view>
			<view class="main">

				<view class="suited">
					<p class="title">活动对象 :</p>
					<view class="content">
						不限

					</view>


					<p class="title">活动说明 :</p>
					<view class="content">


						庆元旦，迎新年，用户凭手机号，免费领取<span
							style="color: rgb(12 11 11);font-weight: bold;">{{projectName}}年卡</span>一张，最低可享<span
							style="color: #ec4f27;font-weight: bold;">两年免充电服务费</span>，最高可享万元礼包，老带新还能有额外红包大礼！

					</view>
					<view class="bottomView" v-if="false">
						<u-button class="button" shape="circle" @click="show=true">分享活动
							<u-icon name="share"></u-icon>
						</u-button>
					</view>
				</view>

				<view class="application-form ">
					<view class="title">
						线上预约:
					</view>
					<view class="tel">
						<p><span style="color: red;">*</span>填写手机号</p>
						<u-input v-model="subForm.phone" :customStyle="placeholderStyle"
							:placeholderStyle="placeholderStyle" placeholder="请填写手机号"></u-input>
					</view>


					<view class="bottomView">

						<u-button class="button" type="warning" @click="submit">我要预约</u-button>
					</view>
					<view style="margin-top: 24rpx;margin-bottom: 44rpx;">
						<u-icon name="info-circle"></u-icon>
						预约成功后，会有工作人员跟您联系，请保持电话畅通。
					</view>
					<view class="title">
						线下办理:
					</view>
					<view class="tel" style="margin-top: 24rpx;margin-bottom: 24rpx;">
						携带本人<span  class="titlespan">身份证</span>、<span  class="titlespan">车辆行驶证</span>前往江津东路附155号荆鹏软件园一楼柜台办理。
					</view>
					<view class="telImg" @click="navigate">
						<img src="@/assets/img/piccShare/map.png" style="width: 100%;"></img>
					</view>
				</view>
				
				<view class="application-table  table">
					<view style="text-align: center;color: red;font-size: 36rpx;margin-bottom: 8px;font-weight:bold;">
						年卡礼包
					</view>
					<table >
						<tr class="th">
						
							<td >年卡</td>
							<td>说明</td>
							<td>价值</td>
						</tr>
						<tr v-for="(item,i) in tableList" :key="i">
							<td class="td1">{{item.name}}</td>
							<td class="td2">{{item.value}}</td>
							<td class="td3">{{item.createBy}}</td>
						 
						</tr>
					</table>
					</view>
			</view>
		</view>
		<u-modal v-model="show1" @confirm="gotoGz" cancel-text="暂不关注" confirm-text="前往关注" :show-cancel-button="false"
			confirm-color="#53b56b" ref="uModal2" :asyncClose="true">
			<view style="padding: 15px;">请先关注<span style=" color:  #53b56b;">{{projectName}}</span>公众号，然后进行填报</view>
		</u-modal>

		<u-mask :show="carTempBl">
			<ucarkeyboard v-if="carTempBl" :tips="subForm.carNum" style="z-index: 9999;position: fixed !important;"
				ref="uKeyboard" mode="car" @confirm="carTempBl=false" @cancel="carTempBl=false" :showTips="true"
				:mask-close-able="false" @change="valChange" @backspace="backspace"></ucarkeyboard>

		</u-mask>

	</view>
</template>

<script>
	import wx from 'weixin-js-sdk'

	import {
		convertCanvasToImage,
		substrMb
	} from '@/utils'
	import {
		checkPhone
	} from '@/utils'

	import * as API from '@/apis/friends.js'
	import * as WxJsApi from '@/utils/wxJsApi.js'
	import * as API_weixin from '@/apis/weixin.js'

	import ucarkeyboard from '@/components/Ucarkeyboard.vue'


	export default {
		components: {
			ucarkeyboard
		},
		data() {
			return {
				tableList:[],
				isLogin: false,
				carAuthImg: "",
				id: "",
				carTempBl: false,
				code: "",
				show: false,

				uid: "",

				show1: false,
				show2: false,
				projectName: "",
				name: "",

				back: false,

				subForm: {
					realName: "",
					phone: "",
					carNum: "",
					licenseFileUrl: "",
					openId: "",
					shareUserId: ""
				},


				placeholderStyle: {
					'font-size': '16px',

					'padding': '4px 8px',
				},
				shareUserId: "",
				userInfo: null,
				carNum: '',
				carLicense: false,

			}
		},
		onLoad(op) {
			if (op.back) {
				this.back = false
			}
			this.projectName = process.car.ProjectName;

			if (op.sid) {

				this.shareUserId = op.sid
				this.carhelp.set("picc_shareUserId_1230", {
					sid: op.sid,
					time: new Date().getTime()
				});
			} else {
				var obj = this.carhelp.get("picc_shareUserId_1230")
				if (obj) {
					var time1 = new Date().getTime()
					var time2 = obj.time;
					if (time1 - time2 < 1000 * 60 * 5) {
						this.shareUserId = obj.sid;
					}

				}
			}
			//console.log(this.shareUserId )
			if (this.shareUserId) {
				uni.showToast({
					title: "来自好友的分享"
				})
			}

			this.get_wx_config();
			this.getList("凭话费送年卡")
		},
		onReady() {
			
			
			var info = this.carhelp.getPersonInfo();

			if (info.id && info.phone) {
				//this.isLogin=true
				this.userInfo = info;
				this.subForm.phone = info.phone;

			}
		},
		onShow() {

			this.checkSubscribe()

		},
		methods: {
			navigate() {
				// x
				// : 
				// "112.276527"
				// y
				// : 
				// "30.306427"
				//console.log(item)
				uni.showLoading({
			
				})
				WxJsApi.openLocation({
					latitude: parseFloat(30.306427), //目的地latitude
					longitude: parseFloat(112.276527), //目的地longitude
					name: "江津东路附155号荆鹏软件园",
					address: "携带本人身份证、车辆行驶证前往江津东路附155号荆鹏软件园一楼柜台办理",
					scale: 15, //地图缩放大小，可根据情况具体调整
					success(res) {
						uni.hideLoading()
					},
					complete() {
						//	uni.hideLoading()
					}
				});
				// //('station'+JSON.stringify(_self.stationDetail.station))
				// window.location.href = "https://uri.amap.com/marker?position=" + _self.stationDetail.station.longitude +
				// 	"," + _self.stationDetail.station.latitude + "&name=" + _self.stationDetail.station.name;
			
			},
			
			getList(key) {
				API.findByCatalogName({
					catalogName:key
				}).then((res) => {

					this.tableList=res.data.dataDictionaryList

					//setGzDate
				}).catch(error => {
					uni.showToast({
						title: error
					})
				})

			},

			checkSubscribe() {
				API_weixin.checkSubscribe({
					openId: this.carhelp.getOpenId()
				}).then((res) => {

					if (res.data == "0") {
						this.show1 = true

					} else {
						//this.init();
						this.show1 = false;
						this.show2 = true;


						//this.carhelp.setGzDate() 

					}

					//setGzDate
				}).catch(error => {
					uni.showToast({
						title: error
					})
				})

			},
			gotoGz() {
				this.carhelp.setGzDate()
				//	this.gotoGzShow = false;
				var url = process.car.gzUrl;
				window.location.href = url

			},
			submit() {
				this.subForm.openId = this.carhelp.getOpenId();
				this.subForm.shareUserId = this.shareUserId;
				this.subForm.event = 1;

				if (!this.subForm.phone) {
					uni.showToast({
						title: "请填写手机号"
					})
					return
				}
				var checkPhoneResult = checkPhone(this.subForm.phone);

				if (checkPhoneResult !== true) {
					uni.showToast({
						title: checkPhoneResult,
					})
					return;
				}


				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API.submitEventRegistration(this.subForm).then((res) => {
					uni.hideLoading()

					if (res.result) {

						uni.showModal({
							//showCancel:false,

							title: "提示",
							content: "预约成功！",
							cancelText: "继续填写",
							confirmText: "前往主页",

							success: (me) => {
								this.carAuthImg = "";
								this.subForm = {
									phone: "",
								}
								if (me.confirm) {
									uni.reLaunch({
										url: "/"
									})
								}

							}
						})
					}

				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},


			//获取微信jssdk配置信息
			get_wx_config() {
				//("get_wx_configget_wx_configget_wx_configget_wx_config")
				var _this = this
				API_weixin.getConfig().then(response => {
					var wxconfig = response.data.wxConfig;

					wx.config({
						debug: false, // 开启调试模式,
						appId: wxconfig.appId, // 必填，企业号的唯一标识，此处填写企业号corpid
						timestamp: wxconfig.timestamp, // 必填，生成签名的时间戳
						nonceStr: wxconfig.nonceStr, // 必填，生成签名的随机串
						signature: wxconfig.signature, // 必填，签名，见附录1
						jsApiList: ['updateAppMessageShareData',
							'updateTimelineShareData', 'onMenuShareTimeline', 'onMenuShareAppMessage',
							'onMenuShareQQ', 'onMenuShareQZone',
							 'openLocation'
							
						], // 必填，需要使用的JS接口列表，所有JS接口列表见附录2

					});
					_this.wxShare()
					wx.error(function(res) {
						//('微信api配置出错');
					});
				}).catch(error => {

					//(error);
				})

			},
			//微信分享自定义
			wxShare() {
				var img =
					"http://oss.xiaoxinda.com/charging/chargingconfigure/2022/6/6/ec228c56-487a-4ae1-ac6f-37284060fbba/hongbao.jpg"
				// img="https://yktwechat.xiaoxinda.com/config/xxd2021.jpg"		
				// if (indexLogo) {
				// 	this.indexLogo = indexLogo;
				// }
				var info = this.carhelp.getPersonInfo()
				//var img=require("@/static/img/aboutus.png")
				////(this.nowItem);
				var ProjectName = process.car.ProjectName; //info.nickName+
				var nickName = info.nickName ? info.nickName : '好友';
				var title = nickName + "邀请你参加'凭话费领年卡活动'"
				//"["+ProjectName+"]"+'和好友一起领5元红包'
				var desc = ProjectName
				let joinUrl = window.location.href.split("/team51/")[0] + "/team51/#/pages/user/newYear2024?back=1"
				//this.joinUrl=joinUrl;
				if (info.id) {
					joinUrl += "&sid=" + info.id;
				}
				var _this = this;
				wx.ready(function() {

					wx.onMenuShareAppMessage({
						title: title,
						desc: desc,
						link: joinUrl,
						imgUrl: img,
						success: function() {
							// 设置成功
							_this.$emit("wxShare", null);
						}
					})
					wx.onMenuShareTimeline({
						title: title,
						desc: desc,
						link: joinUrl,
						imgUrl: img,
						success: function() {
							// 设置成功
							_this.$emit("wxShare", null);
						}
					})
					wx.updateAppMessageShareData({
						title: title,
						desc: desc,
						link: joinUrl,
						imgUrl: img,
						success: function() {
							//("updateAppMessageShareData")
							// 设置成功
							_this.$emit("wxShare", null);
						}
					})
					wx.updateTimelineShareData({
						title: title,
						desc: desc,
						link: joinUrl,
						imgUrl: img,
						success: function() {
							//("updateTimelineShareData")
							// 设置成功
							_this.$emit("wxShare", null);
						}
					})
					console.log("readyreadyreadyreadyready")
				});
			}
		}
	}
</script>
<style>
	page {
		background: #c9382c;
	}
</style>
<style lang="scss" scoped>
	@import "@/_theme.scss";

	.all {
		@include themeify {
			font-size: themed('font-size1');
		}
	}

	.imgHead {
		padding-top: 72rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		.imgHead1 {
			img {
				height: 24px;
			}

			display: flex;
			justify-content: center;
		}

		.imgHead2 {

			display: flex;

			img {
				width: 100%;
				height: 40px;
			}

			margin-top: 16px;
		}
	}

	.main {

		padding: 22rpx 56rpx 170rpx;

		.text {
			color: rgba(255, 255, 255, 100);

			@include themeify {
				font-size: themed('font-size4');
			}

			/*		   font-size: 18px;*/
			text-align: justify;
			text-indent: 36px;


		}

		.suited {
			background-color: #fff;
			//background: linear-gradient(180deg, rgba(189,255,224,1) 0%,rgba(255,255,255,1) 14%);
			background: linear-gradient(180deg, rgba(255, 224, 223, 1) 0%, rgba(255, 255, 255, 1) 14%);
			margin-top: 24px;
			padding: 24px;
			border-radius: 16px;

			.title {
				/*height: 18px;*/
				color: rgba(16, 16, 16, 100);



				font-size: 18px;
				font-weight: 600;
			}

			.content {
				margin: 16rpx 0;
				//font-weight: 550;
				color: rgba(102, 102, 102, 1);
				line-height: 20px;
				font-size: 14px;

				p {
					margin: 8rpx 0;
				}
			}
		}
		.application-table {
			background-color: #fff;
			border-radius: 16px;
			margin-top: 24px;
			padding: 24rpx 16rpx;
			padding-top:8px;
		}

		.application-form {
			background-color: #fff;
			border-radius: 16px;
			margin-top: 24px;
			padding: 24px;
			.titlespan{
				font-weight: bold;
				color: rgba(16, 16, 16, 1);
			}
			.title{
				color: rgba(16, 16, 16, 1);
				font-size: 36rpx;
				font-weight: bold;
				margin-bottom: 24rpx
			}
			
			.u-input {
				border-radius: 50px;
				background-color: rgba(232, 236, 234, 100);
				margin-top: 12px;

			}

			/deep/.uni-input-input {
				margin: 20px;
			}

			/deep/.u-input__right-icon {
				margin-right: 10px;
			}

			p {
				font-size: 18px;

				@include themeify {

					line-height: themed('font-size4');
					height: themed('font-size4');
				}

				/*		  				  height: 18px;
							  line-height: 18px;*/
				color: rgba(16, 16, 16, 100);
				/*		  				  font-size: 18px;*/
			}

			.tel,
			.place,
			.type,
			.want {
				//margin-top: 24px;
			}

			.textarea {
				width: 72.2vw;
				height: 140px;
				border-radius: 22px;
				background-color: rgba(232, 236, 234, 100);
				margin-top: 12px;
				overflow-y: scroll;

				@include themeify {
					font-size: themed('font-size2');
					line-height: themed('font-size2');
				}

				.uni-textarea-placeholder {
					padding: 12px 20px;

					@include themeify {
						font-size: themed('font-size2');
						line-height: themed('font-size2');
					}
				}

				/deep/.uni-textarea-textarea {
					width: 90%;
					padding: 10px 20px;

				}

				/deep/.u-input__right-icon {
					display: none;
				}
			}
		}

		.type {
			.checkbox {
				margin-top: 12px;

				/deep/.u-checkbox {
					width: 50% !important;
					margin-top: 4px;
				}
			}

		}

		.want {
			/deep/.u-checkbox {
				margin-top: 8px;
			}
		}

		.hint {
			margin-top: 12px;

			@include themeify {
				font-size: themed('font-size2');
				line-height: themed('font-size5');
			}

			/*
			font-size: 14px;
			line-height: 20px;
			*/
			text-align: center;

			.tel-num {
				color: #9FC7FF;
			}
		}

		/deep/.u-btn {
			border-radius: 50px;
			margin-top: 40rpx;
		}
	}

	.InviteFriends {
		//background-image: linear-gradient(0deg, #a2e9c9, #01b963);
		background: #c9382c;

	}



	.opacityClass {
		opacity: 0.2;
	}

	// 底部
	.bottomView {
		border-radius: 50px;
		color: rgba(0, 185, 98, 100);

		// width: 100%;
		// height: 64px;
		// text-align: center;
		// background-color: #fff;
		.button {
			//width: 90%;
			border-radius: 50px;
			// background-color: #fff;
			color: #fff;
			font-size: 16px;
			background: linear-gradient(90deg, rgba(255, 98, 0, 1) 0%, rgba(255, 150, 0, 1) 100%);
			//border: 1px solid rgba(0, 163, 86, 1);
		}

		// 	button::after {
		// 		border: rgba(0, 185, 98, 100);
		// 	}
	}

	.carAuth {
		border-radius: 12px;
		background-color: rgba(255, 255, 255, 1);
		border: 2px dashed rgba(187, 187, 187, 1);
		//height: 400rpx;
		width: 100%;
		overflow: hidden;
		text-align: center;

		.carAuthImg {
			margin-top: 10px;
			margin-bottom: 10px;
			width: 510rpx;
			height: 360rpx;
		}

		.carAuthIcon {
			position: absolute;
			background: #6e7175;
			width: 44px;
			height: 44px;
			border-radius: 50px;
			/* left: 200px; */
			/* top: 200px; */
			margin: 160rpx 230rpx;
			z-index: 99;
			display: flex;
			justify-content: center;

		}
	}

	// .car-type{
	// 	    display: flex;
	// 	    flex-direction: row;
	// 		margin: 0 40rpx;
	// 		flex-wrap: wrap;
	// }
	.want {
		.wantView {
			display: flex;
		}

		button {
			width: 45%;
			color: rgba(51, 51, 51, 1);
			background-color: rgba(232, 236, 234, 1);

		}

		button::after {
			border: none;
		}

		.wantBtn {
			background-color: #fff;
			border: 2px solid #00B962;
		}

		.wanttpis {
			position: relative;
			top: -100rpx;
			left: 180rpx;
			z-index: 99;
			background: #00B962;
			padding: 2px 3px;
			font-size: 10px;
			color: #fff;
			border-radius: 4px;

		}
	}

	.carTempBlInput {
		display: flex;
		align-items: center;
		font-size: 16px;
		min-height: 44px;
		padding: 4px 16px;
		border-radius: 20px;
		background: #e9ecea;
		color: #808080
	}
	
	.table {
		table {
			border-spacing:0;
			font-size: 32rpx;
			.th {
				background-color: #f2efef;
				color:	#101010;
				font-weight: bold;
				td{
					border: 1px solid   #dbdbdb;
					
				}
			}
	
			.td1 {
				text-align: start;
			//	background-color: rgba(243, 245, 247, 1);
				width: 212rpx;
				
				border-left: 1px solid   #dbdbdb;
				border-right: 1px solid   #dbdbdb;
				
			}
			.td3 {
				text-align: start;
				//background-color: rgba(243, 245, 247, 1);
				//width: 100rpx;
			
				border-left: 1px solid   #dbdbdb;
				border-right: 1px solid   #dbdbdb;
			}
	
			td {
				//text-align: center;
				border-bottom: 1px solid   #dbdbdb;
				//width: 160rpx;
			}
		}
	
	
	}
</style>