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

		</u-mask>

		<ujp-navbar title="PICC车险活动"  :startGz="false"  :isBack="back" ></ujp-navbar>
		<view class="InviteFriends" :class="{
			opacityClass:show
		}">
		<view class="text imgHead">
					<view class="imgHead1">
						<img   style="width: 105px;" src="@/assets/img/piccShare/1.png"></img>
						<img style="width: 16px;height:16px;margin: 3px;" src="@/assets/img/piccShare/2.png"></img>
						<img  src="@/assets/img/piccShare/3.png"></img>
						
					</view>
					<view class="imgHead2">
						<img  style="width: 252px;height: 28px;" src="@/assets/img/piccShare/4.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">
					2023年12月1日-2024年5月31日
					</view>
					
					<p class="title">活动说明 :</p>
					<view class="content">
						<p>1.本活动为51充电联盟发起，由中国人民财产保险股份有限公司荆州分公司提供服务。</p>
						
						<p>2.<span style="color: #01b963;">新能源车</span>、<span style="color: #ee6e30;">燃油车</span>成功参与本活动，可获得本平台充电5折年卡1张，详情请点击查看<span style="color: #01b963;" @click="gotoUrl('pages/article/details?code=PICCSendPass')"  >《活动规则》</span>”。</p>
						<p>3.分享奖励：您可以分享此页面至微信社群，其他车友通过链接填报信息并投保成功后，您可获得1张10元超级代金券。</p>
						<p>4.本次报名不限数量，如有多辆汽车需要购买车险，可多次报名。</p>
					</view>
					<view class="bottomView">
						<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="name">
						<p><span style="color: red;">*</span>真实姓名</p>
						<u-input v-model="subForm.realName" :customStyle="placeholderStyle" :placeholderStyle="placeholderStyle"
							placeholder="请填写真实姓名"></u-input>
					</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="want" v-if="isLogin">
						<p><span style="color: red;">*</span>是否使用平台已认证车辆信息</p>
						<view class="wantView">
							<u-button  :class="{
								wantBtn:carLicense
							}" shape="circle" @tap="carLicense=true">
								<span  @tap="carLicense=true">{{carNum}}</span>
							</u-button>
							
							<u-button   :class="{
								wantBtn:!carLicense
							}"  shape="circle" @tap="carLicense=false">
								<span  @tap="carLicense=false">其他车辆</span>
							</u-button>
							
						</view>
						<span v-show="carLicense" class="wanttpis" >已认证</span>
					</view>
					<view class="place"  v-show="!carLicense">
						<p><span style="color: red;">*</span>车牌号码</p>
						 
							<view @click="carTempBl=true,carTempBlInit" class="carTempBlInput">
								{{subForm.carNum?subForm.carNum:'请填写车牌号码'}}
							</view>
					</view>
					<view class="type"  v-show="!carLicense">
						<p><span style="color: red;">*</span>车辆认证</p>
						<view style="font-size: 12px;color:rgba(51, 51, 51, 1);margin: 2px 0;">上传机动车行驶证清晰照片</view>
						
						<view class="checkbox">
							
							<view class="car-type">
								
								<view class="carAuth">
									<view class="mark"  v-show="!carAuthImg">
										<view class="text">例</view>
									</view>
									<view class="carAuthIcon" @click="uploadPhoto">
										<u-icon name="camera-fill" custom-prefix="custom-icon" color="#fff" size="48"></u-icon>
										
									</view>
									<image class="carAuthImg"  @click="uploadPhoto" v-show="carAuthImg" :src="carAuthImg"></image>
									
									<image class="carAuthImg"  @click="uploadPhoto" v-show="!carAuthImg" src="@/assets/img/carDet/authtest.png"></image>
									
								</view>
								
							</view>
						</view>
					</view>
					
					<view class="hint">
						查看<span style="color: #01b963;" @click="gotoUrl('pages/article/details?code=PICCSendPass')"  >《购车险送年卡活动规则》</span>
					</view>
					<view class="bottomView">
						
							<u-button class="button"  type="warning" @click="submit">提交申请</u-button>
					</view>
				
				</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 {
				isLogin:false,
				carAuthImg:"",
				id: "",
				carTempBl:false,
				code: "",
				show: false,
			 
				uid: "",
			 
				show1: false,
				show2: false,
				projectName: "",
				name: "",
				 
				back: true,
				 
				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_1112",{
						sid:op.sid,
						time:new Date().getTime()
					});
			}else{
				var obj=this.carhelp.get("picc_shareUserId_1112")
				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();

		},
		onReady() {
		
			var info = this.carhelp.getPersonInfo();
		
			if(info.id&&info.carLicense){
				this.isLogin=true
				this.userInfo=info;
				this.carLicense=true;
				//console.log(JSON.parse(info.carLicenseJson))
				this.carNum=JSON.parse(info.carLicenseJson)["号牌号码"].words
			}
		},
		onShow() {

			this.checkSubscribe()

		},
		methods: {
			carTempBlInit() {
				var aaa = this.$refs.uKeyboard.changeCarInputValue();
				console.log(aaa)
				if (this.subForm.carNum.length && !aaa) {
					var c = this.$refs.uKeyboard.changeCarInputMode();
			
				}
			},
			// 按键被点击(点击退格键不会触发此事件)
			// 按键被点击(点击退格键不会触发此事件)
			valChange(val) {
			
				if (this.subForm.carNum.length >= 8) {
					return
				}
			
				this.subForm.carNum += val;
				// 将每次按键的值拼接到form.carNum变量中，注意+=写法
			
				//(this.subForm.carNum);
			
				var aaa = this.$refs.uKeyboard.changeCarInputValue();
				if ((this.subForm.carNum.length == 0) && aaa) {
					this.$refs.uKeyboard.changeCarInputMode();
				} else if (!aaa) {
					this.$refs.uKeyboard.changeCarInputMode();
				}
			},
			// 退格键被点击
			backspace() {
				// 删除form.carNum的最后一个字符
				if (this.subForm.carNum.length) {
					if (true) {
			
						this.subForm.carNum = this.subForm.carNum.substr(0, this.subForm.carNum.length - 1);
			
					} else {
			
						//this.selectIndex=-1;
					}
				}
			
			
			
			
				//(this.subForm.carNum);
			
				var aaa = this.$refs.uKeyboard.changeCarInputValue();
				if (this.subForm.carNum.length == 0 && aaa) {
					this.$refs.uKeyboard.changeCarInputMode();
				}
			},
			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 = "https://mp.weixin.qq.com/s/mCHz1nNvg0xAICiBeIyKRQ";
				window.location.href = url
			
			},
			submit(){
				this.subForm.openId=this.carhelp.getOpenId();
				this.subForm.shareUserId=this.shareUserId;
				this.subForm.licenseFileUrl=this.carAuthImg
				if(this.carLicense){
					this.subForm.licenseFileUrl=this.userInfo.carLicense
					this.subForm.carNum=this.carNum
				}
				if(!this.subForm.realName){
					uni.showToast({
						title:"请输入车主姓名"
					})
					return
				}
				if(!this.subForm.phone){
					uni.showToast({
						title:"请输入联系电话"
					})
					return
				}
				var checkPhoneResult = checkPhone(this.subForm.phone);
							
				if (checkPhoneResult !== true) {
					uni.showToast({
						title: checkPhoneResult,
					})
					return;
				}
				
				if(!this.subForm.carNum){
					uni.showToast({
						title:"请输入车牌号码"
					})
					return
				}
				
				if(!this.subForm.licenseFileUrl){
					uni.showToast({
						title:"请上传行驶证"
					})
					return
				}
				
				uni.showLoading({
					title: "加载中",
					mask: true,
				})		
				API.submitPicc(this.subForm).then((res) => {
					uni.hideLoading()
					
					if(res.result){
						uni.showModal({
							//showCancel:false,
						
							title:"提示",
							content:"提交成功！",
							confirmText:"前往主页",
							success:(me)=> {
								this.carAuthImg="";
								this.subForm={
									realName:"",
									phone: "",
									carNum:"",
									licenseFileUrl: "",
									//openId:"",
									//shareUserId: ""
								}
								if(me.confirm){
									uni.reLaunch({
										url:"/"
									})
								}
							
							}
						})
					}
					
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			uploadFile(imageSrc){
				var action=process.car.BASE_URL+"uploadPicture"
				var token=this.carhelp.getToken()
				var header={
					'Authorization':token
				}
				var formData={
					subFolder:"/team51/picc"
				}
				var _this=this
				uni.showLoading({
				   					title: '上传中',
									mask: true,
				   				})
				   				  uni.uploadFile({
				   					url: action, //仅为示例，非真实的接口地址
				   					filePath: imageSrc,
				   					name: 'photoFile',
									header: header,
				   					formData: formData,
				   					success: (res) => {
				   						
				   						uni.hideLoading();
				   						uni.showToast({
				   							title: '上传成功',
				   							icon: 'success',
				   							duration: 1000
				   						})
										
				   						_this.carAuthImg = JSON.parse(res.data).data
				   						_this.$forceUpdate()
										
										
				   					},
				   					fail: (err) => {
				   						console.log('uploadImage fail', err);
				   						uni.hideLoading();
				   						uni.showModal({
				   							content: err.errMsg,
				   							showCancel: false
				   						});
				   					},
				   				});
			},
			uploadPhoto() {
				
				uni.chooseImage({
					count: 1,
					sizeType:['compressed'],
					success: async (res) => {
						console.log(res)
						var imageSrc = res.tempFilePaths[0]
						this.uploadFile(imageSrc);
							
					},
					fail: (err) => {
					   	console.log('chooseImage fail', err)
					}
				})
			},
			 
			
			 
		 
			//获取微信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'], // 必填，需要使用的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/sharePicc?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 {}
</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: 20px;
			}
			
			    display: flex;
			    justify-content: center;
		}
		.imgHead2{
			
			    display: flex;
			img{
				width: 100%;
				height: 20px;
			}
			    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%);
			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-form {
			background-color: #fff;
			border-radius: 16px;
			margin-top: 24px;
			padding: 24px;

			.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: 24px;
		}
	}

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

	}

	

	.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
	}
</style>