
<template>
	<view class="content-box">
	     <view class="header-box">
			 <image src="/static/tips.png" mode="aspectFill"></image>
			  <text>温馨提示：请填写以下信息，填写后信息不可修改</text>
		 </view>
		<form @submit="formSubmit" style="width: 100%"> 
	     <view class="self-title-box">
			 <image src="/static/rect-icon.png" mode="aspectFill"></image>
			 <text>个人信息</text>
		 </view>
		<view class="info-box">
			<view class="info-title-box">
				<image src="/static/require-icon.png" mode="aspectFill"></image>
				<text>姓名</text>
			</view>
			<view class="info-value-box">
				<input type="text" placeholder="请输入姓名" name="selfName">
			</view>		
		</view>
		
		<view class="info-box" style="border-bottom: none;height: 170rpx;">
			<view class="info-title-box">
				<image src="/static/require-icon.png" mode="aspectFill"></image>
				<text>性别</text>
			</view>
			<view class="info-gender-box">
				<radio-group @change="radioCheck" class="padding-left-2">
					<label class="radio margin-right-10"><radio value="1" :checked="userSex==='1'" color="#00A1B4" class="form-radio"/>男</label>
					<label class="radio"><radio value="0" :checked="userSex==='0'"  color="#00A1B4" class="form-radio"/>女</label>
				</radio-group>
			</view>		
		</view>
		<view class="border-line-box"></view>
		<view class="self-title-box">
					 <image src="/static/rect-icon.png" mode="aspectFill"></image>
					 <text>经销商信息</text>
		</view>
		<view class="info-box">
			<view class="info-title-box">
				<image src="/static/require-icon.png" mode="aspectFill"></image>
				<text>经销商姓名</text>
			</view>
			<view class="info-value-box">
				<input type="text" placeholder="请输入姓名" name="dealerName">
			</view>		
		</view>
	<!-- 	<view class="info-box">
			<view class="info-title-box">
				<image src="/static/require-icon.png" mode="aspectFill"></image>
				<text>经销商手机号</text>
			</view>
			<view class="info-value-box">
				<input type="number" placeholder="请输入手机号" name="dealPhone">
			</view>		
		</view> -->
		<view class="info-box" style="border-bottom: none;height: auto;">
			<view class="info-title-box">
				<image src="/static/require-icon.png" mode="aspectFill"></image>
				<text>经销商展厅所在地</text>
			</view>
			<view class="info-value-box " style="margin: 2% auto;">
				
			   			<view class="uni-input picker-box">
			   				<view class="content" style="width: 100%;">
			   					<view class="content_list" style="width: 100%;">
			   						<view class="content_list_label" @click="addressShow = true" style="width: 100%;color: #888;">{{txt}}</view>
			   						<view class="content_list_content">
			   							<pickerAddress v-model="addressShow" @confirm="addresspick" />
			   							<image src="/static/right-arrow.png" mode="aspectFill"></image>
			   						</view>
			   					</view>
			   				</view>
			   			</view>
					<view class="textarea-box" v-show="!addressShow">
					     <textarea  auto-height   placeholder="请输入详细地址" v-model="addressDetail"  maxlength="26" @blur="testLength"/>
					 </view>
			</view>		
		</view>
		
		<view style="width: 100%;">
			<button type="primary" class="submit-bth" formType="submit">提交</button>
		</view>
	</form>	
	</view>
</template>

<script>
	var md5 = require("../../../common/md5.js");
	import pickerAddress from '@/components/liudx-pickerAddress/index.vue'
	var graceChecker = require("../../../common/graceChecker.js");
	export default {
		components: {
			pickerAddress
		},
		data() {
			return {
				title: 'Hello',
				detailObj:{},
				shareContent:'',
				shareCode:'',
				storeImg:'',
				isAuthPhone:getApp().globalData.user_phone,
				userSex:'1',
				txt: '请选择',
				addressShow: false,
				form: {
					province: '',
					city: '',
				},
				address: '',
				addressObj:{},
				loginObj:{},
				addressDetail:'',
			}
		},
		onLoad(option) {
			//this.getDetailInfo(option.detailId);
		},
		onShow() {
		},
		// onShareAppMessage() {
		// 	  return {
		// 	      title: '分销小助手',
		// 	      path:'/pages/index/index?scene=' + getApp().globalData.user_id
		// 	    }
		// },
		methods: {
			addresspick(obj) {
				console.log(obj)
				this.addressObj = obj;
				this.txt = obj.province.name + obj.city.name;
			},
			 radioCheck(e){
			 	console.log(e.target.value)
			 	this.userSex = e.target.value;
			 	//this.gender = e.target.value == '0' ? '男' : '女';
			 },
			 changeCity(data) {
				 this.txt = data.data.join('')
				 console.log(data.data.join(''))
			  },
			 testLength(){
				 if(this.addressDetail.length > 25){
					 uni.showToast({
					 	title: '详细地址应为0-25个字符',
					 	icon: 'none'
					 });
				 }
			 }, 
			  formSubmit(e) {
			  	//将下列代码加入到对应的检查位置
			  	//定义表单规则
			  	var rule = [
			  		{
			  			name: "selfName",
			  			checkType: "notnull",
			  			errorMsg: "姓名不能为空"
			  		},
					{
						name: "selfName",
						checkType: "string",
						checkRule: "2,15",
						errorMsg: "姓名不能小于2个字符"
					},
					{
						name: "selfName",
						checkType: "reg",
						checkRule: "[\u4e00-\u9fa5]",
						errorMsg: "姓名需为中文"
					},
			  		{
			  			name: "dealerName",
			  			checkType: "notnull",
			  			errorMsg: "经销商姓名不能为空"
			  		},
					{
						name: "dealerName",
						checkType: "string",
						checkRule: "2,15",
						errorMsg: "经销商姓名不能小于2个字符"
					},
			  	];
			  	//进行表单检查
			  	var formData = e.detail.value;
			  	var checkRes = graceChecker.check(formData, rule);
			  	if (checkRes) {
					this.txt === '请选择' ? 
					uni.showToast({
						title: '请选择地区',
						icon: "none"
					}):
					this.submitRequest(formData);
			  	} else {
			  		uni.showToast({
			  			title: graceChecker.error,
			  			icon: "none"
			  		});
			  	}
			  },
			  submitRequest(params){
				  console.log(params)
				  let that = this;
				  uni.request({
					url:getApp().globalData.shareUrl, //需要设置为全局
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						method: 'jxs_guest_login',
						timestamp: getApp().globalData.globalTimestamp, //Date.now()
						sign: md5('jxs_guest_login' + getApp().globalData.globalTimestamp),
						phone:getApp().globalData.userPhone,
						wxopenid:getApp().globalData.openId,
						name:params.selfName,
						sex:that.userSex,//0-女 1-男
						province:that.addressObj.province.id,//省份id
						city:that.addressObj.city.id,//城市id
						detailaddress:that.addressDetail,
						jxs_name:params.dealerName,
					},
					success: res => {
						console.log(res)
						if(res.data.code === 200){
							that.loginObj = res.data.msg;
							getApp().globalData.userCodeNumber = that.loginObj.code;
							getApp().globalData.managerPhone = that.loginObj.qyjl_phone;
							getApp().globalData.managerName = that.loginObj.qyjl_name;
							getApp().globalData.addTime = that.loginObj.addtime;
							this.goCustomCardPage(that.loginObj.pass)
						}
						else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							});
						}
					} 
				  });
			  },  
			  goCustomCardPage(type){
			  	type === 1 ? 
			  	uni.redirectTo({
			  		url: '/pages/index/successPage/index?types='+'dealer', //经销商成功页面
			  		success: res => {},
			  		fail: () => {},
			  		complete: () => {}
			  	}):
			  	uni.redirectTo({
			  		url: '/pages/index/failPage/index', //失败页面
			  		success: res => {},
			  		fail: () => {},
			  		complete: () => {}
			  	});
			  }  
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		&_list{
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content:space-around;
			&_lable{
				
			}
			&_content{
				flex: 1;
				width: auto;
				text-align: right;
			}
		}
	}
	.content-box {
		width: 100%;
		/* height: 100%; */
		display: flex;
		flex-direction: column;
		align-items: center;
		/* justify-content: center; */
	}
	.header-box {
		width: 85%;
		height:80rpx;
		border: .5px dotted #00A1B4;
		border-radius: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 24rpx;
		color:#00A1B4 ;
		/* font-family: PingFangSC-Regular; */
		margin-top: 2%;
	}
	.header-box image {
		width: 36rpx;
		height: 36rpx;
		margin-right: 1%;
	}
	.self-title-box {
		width: 90%;
		display: flex;
		align-items: center;
		font-size: 32rpx;
		letter-spacing: 2rpx;
		color:#3C3C3C ;
		/* font-family: SimHei; */
		margin: 4% auto;
		font-weight: bold;
		height: 50rpx;
		line-height: 50rpx;

	}
	.self-title-box image {
		width: 6rpx;
		height: 32rpx;
		margin-right: 2%;
	}
	.info-box {
		width: 90%;
		margin: 3% auto;
		height: 180rpx;
		border-bottom: 1px solid #f7f7f7;
	}
	.info-title-box {
		width: 100%;
		display: flex;
		align-items: center;
		font-size: 28rpx;
		height: 50rpx;
		line-height: 50rpx;

	}
	.info-title-box image{
		width: 15rpx;
		height: 15rpx;
		margin-right: 2%;
	}
	.info-value-box input {
		height: 88rpx;
		background: #f7f7f7;
		font-size: 28rpx;
		padding-left: 4%;
		margin: 2% auto;
	}
	.info-gender-box {
		margin: 3% auto;
		font-size: 28rpx;
	}
	.form-radio {
			 transform: scale(0.6);
	}
	.padding-left-2 {
		padding-left: 2%;
	}
	.margin-right-10 {
		margin-right: 10%;
	}
	.border-line-box {
		width: 100%;
		height: 20rpx;
		background: #f7f7f7;
	}
	.picker-box{
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 60rpx;
		line-height: 60rpx;
		background: #f7f7f7;
		height: 88rpx;
		line-height: 88rpx;
		background: #f7f7f7;
		font-size: 28rpx;
		padding-left: 4%;
	}
	.uni-input image {
		width: 40rpx;
		height: 40rpx;
		margin-right: 2%;
		float: right;
	}
	.textarea-box {
		background: #f7f7f7;
		min-height: 120rpx;
		font-size: 28rpx;
		margin: 5% auto;
		padding: 4%;
		margin-bottom: 8%;
	}
	.submit-bth {
		width: 80%;
		height: 80rpx;
		line-height: 80rpx;
		background: #00A1B4!important;
		-webkit-box-shadow: 0 2rpx 16rpx 0 rgba(60,120,109,0.20);
		box-shadow: 0 2rpx 16rpx 0 rgba(60,120,109,0.20);
		border-radius: 50rpx;
		margin-bottom: 10%;
		font-size: 30rpx;
	}
</style>
