<template>
	<view class="all">
		<ujp-navbar :is-back="back" title="我要加盟" ></ujp-navbar>
	
		<view class="main">
			<view class="main-content">
				<p class="title">适合对象:</p>
				<view class="text">
					已经在经营充电桩业务的商家，可以申请加入“<text style="color: #e14173;">{{projectName}}</text>”。
				</view>
				<p class="title">平台能为您提供：</p>
				<view class="text-box">
					<p>1.便捷的找桩、充电服务，提升用户体验。</p>
					<p>2.获得更多的用户资源和运营支持，提高市场竞争力。</p>
					<p>3.良好的平台背书,提高公信力</p>
				</view>
			</view>
			<view class="application-form ">
				<view class="name">
					<p>申请人姓名</p>

					<u-input   v-model="name" :customStyle="customStyle" :placeholderStyle="placeholderStyle" placeholder=""></u-input>
				</view>
				<view class="tel">
					<p>联系电话</p>
					<u-input :customStyle="customStyle"  v-model="subForm.phone" :placeholderStyle="placeholderStyle" placeholder=""></u-input>
 				</view>
				<view class="place">
					<p>自有电桩地点</p>
				
					<u-input class="textarea"  type="textarea" height="200"  v-model="address" placeholder="填写详细位置" ></u-input>
				</view>
				<view class="type">
					<p>自有电桩类型</p>
					<view class="checkbox">
							<view class="">
									<u-checkbox-group    active-color="#00B962">
										<u-checkbox 
										 
											v-model="item.checked" 
											v-for="(item, index) in typeList" :key="index" 
											:name="item.name"
										>{{item.name}}</u-checkbox>
									</u-checkbox-group>
									
								</view>
						</view>
				</view>
				<view class="want">
					<p>自有电桩数量</p>
					<view class="radio-box">
						
									<view class="">
										<u-radio-group v-model="text2"  active-color="#00B962">
											<u-radio 
											 
												v-for="(item, index) in numlist" :key="index" 
												:name="item.name"
												
												:disabled="item.disabled"
											>
												{{item.name}}
											</u-radio>
										</u-radio-group>
									</view>
						</view>
				</view>
			      <view class="hint">
			      	<span style="color: red;">*</span>请保持手机畅通，我们将安排专人与您联系。您也可以拨打 
					 <text class="tel-num" @click="calltel('400-8899-619')">400-8899-619</text>查询申请审核进度！
			      </view>
				 <u-button type="warning"  @click="submit"  >提交申请</u-button>
			</view>


		</view>

	</view>
</template>

<script>
	import * as API from '@/apis/friends.js'
	import {
		checkPhone
	} from '@/utils'
	export default{
		data() {
				return {
					name:"",
					address:"",
					text1:[],
					back:false,
					text2:"5台以内",
					subForm:{
						phone:"",
						openId:"",
						type:"1",
						content:""
					},
					elderMode:false,
					customStyle:{
						'font-size':'28rpx'
					},
					placeholderStyle:"font-size:28rpx",
					typeList: [
									{
										name: '电动汽车充电桩（快充）',
										checked: false,
										disabled: false
									},
									{
										name: '电动汽车充电桩（慢充）',
										checked: false,
										disabled: false
									},
									{
										name: '电动摩托/自行车充电桩',
										checked: false,
										disabled: false
									}
								],
								numlist: [
												{
													name: '5台以内',
													disabled: false,
													checked: true,
												},
												{
													name: '5~10台',
													disabled: false,
													checked: false,
												},
												{
													name: '10台以上',
													disabled: false,
													checked: false,
												}
											],
											// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
											value: 'orange',
							
								
				};
				
			},
			onLoad(op) {
				if(op.isback){
					this.back=true;
				}
			},
			methods:{
				calltel(tel){
					uni.makePhoneCall({
						phoneNumber:tel //仅为示例
					});
				},
				
				submit(){
				
					var obj=[]
					if(!this.name){
						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.address){
						uni.showToast({
							title:"请填写详细位置"
						})
						return
					}
					obj.push({
						name:"申请人姓名",
						value:this.name,
						type:"text"
					})
					obj.push({
						name:"自有电桩地点",
						value:this.address,
						type:"text"
					})
					this.text1="";
					this.text1b=false;
				
					var list1=this.typeList.map(item=>{
						if(item.checked){
							this.text1+="1"
							this.text1b=true;
						}else{
							this.text1+="0"
						}
						return item.name
					})
					
					//this.text2="";
					var text2value="";
					this.text2b=false;
					var list2=this.numlist.map(item=>{
						if(item.name==this.text2){
							text2value+="1"
								this.text2b=true;
						}else{
							text2value+="0"
						}
						return item.name
					})
					
					if(!this.text1b){
						uni.showToast({
							title:"请至少勾选一项“自有电桩类型”"
						})
						return
					}
					if(!this.text2b){
						uni.showToast({
							title:"请至少勾选一项“自有电桩数量”"
						})
						return
					}
					obj.push({
						name:"自有电桩类型",
						value:this.text1,
						type:"list",
						list:list1
					})
					obj.push({
						name:"自有电桩数量",
						value:text2value,
						type:"list",
						list:list2
					})
					this.subForm.openId=this.carhelp.getOpenId();
					this.subForm.content=JSON.stringify(obj);
					//(this.subForm)
					
					uni.showLoading({
						title: "加载中",
						mask: true,
					})		
					API.submit(this.subForm).then((res) => {
						uni.hideLoading()
						uni.showModal({
							showCancel:false,
							title:"提示",
							content:"提交成功！",
							confirmText:"前往主页",
							success() {
								uni.reLaunch({
									url:"/"
								})
							}
						})
						
					}).catch(error => {
						uni.showToast({
							title: error,
							icon: "none"
						})
					})
				},
				theme(type) {
					
				  if(type == 'elder')	
				  {
					document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
					 let data = {
					 	"font-size":'32rpx', 
					 	};
					this.customStyle = data;
					this.placeholderStyle = "font-size:32rpx";//data;
				  }
				  else
				  {
					document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
					 let data = {
					 	"font-size":'28rpx'
					 	};
					this.customStyle = data;
					this.placeholderStyle = "font-size:28rpx";//data;
				  } 
				}
			},
			onReady(){
				this.elderMode = this.carhelp.get('getElderModeClass')  == '长辈模式';
				if(this.elderMode)
					this.theme('elder')
				else
					this.theme('standard')
			}
	}
</script>

<style>
	page {
		
		background:url(@/assets/static/img/earth_@2.png) no-repeat top center #00b962 ;
		background-size: 100%;
		background-position: 50% 4%
	}
</style>

<style lang="scss" scoped>
	@import "@/_theme.scss";
	.all{
		@include themeify{
			font-size: themed('font-size1');
		}
	}
	.main {
		width: 100%;
	    margin-top: 131px;
		@include themeify{
 			line-height: themed('font-size5');
		}
/*		line-height: 20px;*/
		border-radius: 16px;
	
		padding: 0 28px 85px;

		.main-content {
			padding:24px 24px;
			background-color: #fff;
            border-radius: 16px;
			.title{
/*				height: 18px;*/
				color: rgba(16, 16, 16, 100);
				@include themeify{
					font-size: themed('font-size4');
					height: themed('font-size4');
				}
/*				font-size: 18px;*/
				font-weight: 600;
				
			}
			.text{
				margin-top: 12px;
				margin-bottom: 24px;
			}
			.text-box{
				margin-top: 12px;
				p{
					margin-top: 10px;
					@include themeify{
						line-height: themed('font-size7');
					}
/*					line-height: 24px;*/
					text-align: justify;
				}
			}
		}
		.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;
				
			  }
			 ::v-deep .uni-input-input{
			 			  margin: 20px;
			 }
			 ::v-deep .u-input__right-icon{
			 			  margin-right: 10px;
			 }
			  p{
				  @include themeify{
				  	font-size: themed('font-size4');
				  	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);
			      overflow-y: scroll;
			
				   margin-top: 12px;
				  @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');
 					 }
				 }
				 ::v-deep .uni-textarea-textarea{
					 width: 90%;
					 padding: 10px 20px;
					  
				 }
				 ::v-deep .u-input__right-icon {
					 display: none;
				 }
				
			  }
			  .type{
			  	.checkbox{
			  		margin-top: 12px;
			  		::v-deep .u-checkbox{
			  			
			  			margin-top: 4px;
			  		}
			  	}
			  	
			  }
			  .want{
				
				  .radio-box{
					  margin-top: 12px;
				  }
			  ::v-deep .u-radio{
			  	width: 50% !important;
				margin-top: 4px;
			  }
			  }
			  .hint{
			  	margin-top: 12px;
			  	@include themeify{
			  		font-size: themed('font-size2');
			  		line-height: themed('font-size5'); 
			  	}
/*			  	font-size: 14px;
			  	line-height: 20px;*/
			  	text-align: justify;
			  	.tel-num{
			  		color: #9FC7FF;
			  	}
			  }
			  ::v-deep .u-btn{
			  	border-radius: 50px ;
			  	margin-top: 24px;
			  }
		}

	}
</style>
