<template>
	<view class="content">
		<process :process="1" :type="0" title="业务流程"></process>
		<view class="base-list">
			<view class="item item-select u-row-between">
				<view class="label">实名认证</view>
				<p class="u-flex-1 u-text-right txt">{{ areaTxts.slice(0,2).join(',') || "" }}</p>
				<u-icon name="arrow-right" color="#999" size="28"></u-icon>
			</view>
			<view class="newAddressView">
				<view class="newAddressTitleView"  @click="locationClick()">
					<view class="address">
						<text class="itemTitle">收货地址</text>
					</view>
					<view class="right-margin-40">
						<u-icon name="map" color="#999" size="34"></u-icon>
						<text class="blueColor">定位</text>
					</view>
				</view>
				<view class="addressBackView">
					<textarea 
					class="addressTextAreaView"  
					maxlength="100" 
					v-model="baseInfo.address" 
					auto-height="true" 
					value="" 
					placeholder="请输入详细服务地址"  
					placeholder-style='color:#CCCCCC;font-size:28rpx;'/>
				</view>
				<view class="tips">（必填项）填写可接收物料的地址</view>
			</view>
			<view class="item item-select u-row-between" @click="gopage('/pages/settle/select?selectType=area')">
				<view class="label">接单城市：</view>
				<p class="u-flex-1 u-text-right txt">{{ areaTxts.slice(0,2).join(',') || "" }}</p>
				<u-icon name="arrow-right" color="#999" size="28"></u-icon>
			</view>
			<view class="tips">（必选项）选择你可以服务的城市，可选多个</view>
			<view class="item item-select u-row-between">
				<view class="label">电工证</view>
				<p class="u-flex-1 u-text-right txt">{{ areaTxts.slice(0,2).join(',') || "" }}</p>
				<u-icon name="arrow-right" color="#999" size="28"></u-icon>
			</view>
			<view class="item item-select flex-yc" @click="gopage('/pages/settle/select?selectType=working_age')">
				<view class="label">电工工龄(年)：</view>
				<p class="u-flex-1 u-text-right area" v-show="baseInfo.working_age !== ''">
					{{ workingAgeTxt }}
				</p>
				<u-icon name="arrow-right" color="#999" size="28"></u-icon>
				<!-- <i class="iconfont icon-xiangyou"></i> -->
			</view>
			<view class="tips">（必选项）选择你从事电工工作的工龄</view>
			<view class="item item-select u-row-between">
				<view class="label">个人车辆信息</view>
				<p class="u-flex-1 u-text-right txt">{{ areaTxts.slice(0,2).join(',') || "" }}</p>
				<u-icon name="arrow-right" color="#999" size="28"></u-icon>
			</view>
			<view class="tips">（选填项）填写你的车辆信息</view>
			
			<view class="itemView">
				<view class="itemTitleView">
					<text class="itemTitle">师傅数量</text>
					<!--text class="itemRedStar">*</text-->
				</view>
				<input 
				class="itemInput" 
				@input="countInput" 
				v-model="name" 
				type="number" 
				value="" 
				placeholder="请输入师傅数量" 
				placeholder-style='color:#CCCCCC;font-size:32rpx;'/>
			</view>
			<view class="tips bottom_padding_80">（选填项）输入可投入交付服务的人员数量</view>
			
		</view>
		<view class="seat"></view>
		<view class="btn-wrap flex-xc">

			<button class="btn-submit" :disabled="!submitStatus" @click="$u.debounce(submitBaseInfo, 500)">
				确定
			</button>
		</view>
	</view>
</template>

<script>
	let r = require("../../libs/bmap-wx.min.js");
	let h = new r.BMapWX({
		// ak: "rpVq5d3yxaRCoKzVwmFMo0o4iC524CAG",
		ak: "lF1HoyXdiv4uZx6TrGQEZs48F5y8kEHI"
	});
	export default {
		data() {
			return {
				baseInfo: {
					name: "",
					mobile: "",
					service_area: [],
					working_age: "",
					worker_num:"",
					address:''
				},
				saving: false,
				areaTxts: [],
				workingAgeTxt: '',
				protocolContent: '',
				address:'',
				isPosting:false
			}
		},
		onLoad(e) {
			this.initLocation()
		},
		onShow() {
			if (this.isPosting) {
				this.isPosting = false
			}
		},
		
		computed: {
			submitStatus() {
				const baseInfo = this.baseInfo
				//baseInfo.name && baseInfo.mobile && 
				const flag = baseInfo.service_area && baseInfo.working_age !== ''
				return flag && !this.saving;
			},
		},
		components: {

		},
		methods: {
			initLocation(){
				const self = this
				uni.getLocation({
				    type: 'wgs84',
				    success: function (res) {
						self.baiduLocation(res.longitude,res.latitude)
				    }
				});
			},
			baiduLocation(long,lat) {
				let a = this,
					t = function() {
						let t = {
							success: function(res) {
								let e = res.wxMarkerData[0];
								let i = e.address;
								a.baseInfo.address = i
								// a.setData({
								// 	addressValue: i
								// }), o.globalData.addressValue = i, a.initWatermarkBoxHeightAndWidth();
							},
							fail: function(a) {
								// n.error(a), console.log(a);
							}
						};
						if (lat && long) {
							let e = lat + "," + long
							// let e = "113.88308" + ',' + "22.55329"
							// let e = "22.55329" + ',' + "113.88308" 
							t.location = e;
						}
						h.regeocoding(t);
					};
				t()
			},
			
			//师傅数量
			countInput(e){
				this.baseInfo.worker_num = e.detail.value
			},
			
			//定位点击
			locationClick:function(){
				let that = this
				uni.chooseLocation({
				    success: function (res) {
						that.baseInfo.address = res.address + res.name
						//that.address = res.address + res.name
				    },fail: function (res) {
						uni.showToast({
							title:'定位失败'
						})
					}
				});
				
			},
			
			gopage(url) {
				uni.navigateTo({
					url,
				});
			},
			initBaseInfo() {
				Indicator.open();
				let params = {
					id: '',
				}
				const res = this.$u.api.getSettleBaseInfo(params)
				uni.hideLoading()
				if (res.status != 200) {
					uni.showToast({
						title: res.message,
						icon: 'success'
					});
					return;
				}
				this.baseInfo = res.data
				uni.showToast({
					title: '入驻基本信息提交成功',
					icon: 'success'
				});
			},
			checkBaseInfo() {
				const baseInfo = this.baseInfo;
				let rulesObj = {
					/*
					name: function(value) {
						if (!value) {
							uni.showToast({
								title: '请输入您的姓名',
								icon: 'none'
							});
							return false;
						}
					},
					mobile: function(value) {
						const mobileReg = /^[1][3,4,5,7,8][0-9]{9}$/;
						if (!value) {
							uni.showToast({
								title: '请输入您的电话',
								icon: 'none'
							});
							return false;
							return false;
						} else if (!mobileReg.test(value)) {
							uni.showToast({
								title: '请输入正确的电话',
								icon: 'none'
							});
							return false;
						}
					},
					*/
					service_area: function(value) {
						if (!value || value.length==0) {
							uni.showToast({
								title: '请选择您的接单城市',
								icon: 'none'
							});
							return false;
						}
					},
					working_age: function(value) {
						if (value === '') {
							uni.showToast({
								title: '请选择您的工龄',
								icon: 'none'
							});
							return false;
						}
					},
					//address
					address: function(value) {
						if (value === '') {
							uni.showToast({
								title: '请选择您的地址',
								icon: 'none'
							});
							return false;
						}
					},
					
					
				};
				const flagArr = Object.keys(baseInfo).some((key) => {
					// 返回验证失败的数组
					let flag = true;
					if (rulesObj.hasOwnProperty(key)) {
						const func = rulesObj[key];
						const value = baseInfo[key];
						if (typeof func === "function") {
							flag = func(value) === false ? false : true;
						}
					}
					return !flag;
				});
				return !flagArr || flagArr.length < 1;
			},
			
			/*
			shakeCLick: function() {
				let timer = setTimeout(() => {
					clearTimeout(timer)
					this.submitBaseInfo()
				}, 2000)
			},
			*/
			
			async submitBaseInfo() {
				
				// this.newSubmitBaseInfo()
				// return
				const baseInfo = this.baseInfo;
				if (!this.checkBaseInfo()) {
					return;
				}

				this.saving = true;
				uni.showLoading({
					title: '加载中'
				});
				const params = {
					...baseInfo,
					recommender:getApp().globalData.settleRecommend
				}
				console.log(params,'params')
				params.service_area = baseInfo.service_area.join(',')
				const res = await this.$u.api.submitSettleBaseInfo(params)
				this.saving = false;
				uni.hideLoading()
				
				//this.isPosting = false
				
				if (res.code != 200) {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
					return;
				}
				uni.showToast({
					title: '入驻基本信息提交成功',
					icon: 'success'
				});
				let timer = setTimeout(() => {
					clearTimeout(timer)
					uni.navigateTo({
						url:'/pages/settle/file'
					})
				}, 2000)
			},

		},
	}
</script>

<style lang="scss">
	.base-list {
		.item {
			display: flex;
			margin-bottom: 58rpx;
			padding: 28rpx 30rpx;
			width: 100%;
			height: 100rpx;
			font-size: 32rpx;
			background-color: #fff;

			.label {
				color: #333;
				font-size: 32rpx;
				font-weight: bold;
			}

			.txt {
				line-height: 44rpx;
				color: #333;
				font-size: 32rpx;
				 display: -webkit-box;
				  overflow: hidden;
				  text-overflow: ellipsis;
				  word-wrap: break-word;
				  white-space: normal !important;
				  -webkit-line-clamp: 2;
				  -webkit-box-orient: vertical;
			}

			.required {
				margin: 0 6rpx;
				color: red;
				font-size: 32rpx;
			}

			.iconfont {
				color: #999;
			}
		}

		.tips {
			margin-top: 20rpx;
			padding: 0 30rpx;
			line-height: 40rpx;
			font-size: 28rpx;
			color: #666;

			&+.id-identity-box {
				margin-top: -38rpx;
				margin-bottom: 40rpx;
			}
		}

		.id-identity-box {
			.txt {
				padding-top: 8rpx;
				line-height: 40rpx;
				font-size: 28rpx;
				color: #666;

				&:first-child {
					margin-top: -58rpx;
					padding-top: 12rpx;
				}

				.red {
					color: red;
				}
			}

			// &.tips{
			//     margin-bottom:0!important;
			// }

		}

		.item+.tips {
			margin-top: -38rpx;
			margin-bottom: 58rpx;
		}

		/*选择内容*/
		.item-select {
			font-size: 30rpx;
			color: #333;
			font-weight: 500;
			justify-content: space-between;
			border-bottom: 1rpx solid #f5f5f5;
		}

		.flex1 {
			flex: 1 !important;

			&.txt {
				white-space: nowrap;
				max-width: 450rpx;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}

		.item-input {
			overflow: hidden;

			input {
				text-align: right;
				line-height: 44rpx;
				width: 100%;
				font-size: 30rpx;
				color: #333;
				font-weight: 400;
			}

			.input-readonly {
				font-size: 30rpx;
				color: #999;
				font-weight: 400;
			}

			input::-webkit-input-placeholder {
				font-size: 30rpx;
				color: #999;
				font-weight: 400;
			}

			input:-moz-placeholder {
				font-size: 30rpx;
				color: #999;
				font-weight: 400;
			}

			input:-ms-input-placeholder {
				font-size: 30rpx;
				color: #999;
				font-weight: 400;
			}
		}
	}

	.title {
		padding: 30rpx 0 40rpx;
		text-align: center;
		line-height: 50rpx;
		font-size: 36rpx;
		color: #333;
		font-weight: bold;
	}

	.seat {
		padding-bottom: 144rpx;
	}

	/*提交按钮*/
	.btn-wrap {
		//position: fixed;
		//left: 0;
		//right: 0;
		//bottom: 0;
		padding: 30rpx 0;
		background: #f3f3f3;
		
		width: 100%;

		.btn-submit {
			width: 600rpx;
			// left: 5%;
			// bottom: px2rem(36);
			height: 104rpx;
			line-height: 104rpx;
			border-radius: 52rpx;
			background: #2272ff;
			font-size: 32rpx;
			color: #fff;

			&[disabled] {
				border: 2rpx solid #999;
				background-color: #f3f3f3;
				color: #999;
			}
		}
	}
	
	.itemView {
		background-color: #FFFFFF;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		height: 104rpx;
	}
	
	.itemTitleView{
		background-color: #FFFFFF;
		width: 30%;
		height: 102rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	
	.borderBottom{
		border-bottom: 1rpx solid #CCCCCC;
	}
	
	.itemTitle {
		background-color: #FFFFFF;
		margin-left: 30rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
	}
	
	.itemRedStar {
		font-size: 32rpx;
		color: #D02B2B;
	}
	
	.itemInput {
		background-color: #FFFFFF;
		margin-right: 30rpx;
		height: 70rpx;
		width: 70%;
		text-align: right;
		font-size: 32rpx;
	}
	
	
	.newAddressView{
		margin-top: 60rpx;
		background-color: #FFFFFF;
		width: 100%;
		display: flex;
		flex-direction: column;
		padding-bottom: 30rpx;
	}
	
	.newAddressTitleView{
		height: 64rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}
	
	.itemTitle {
		background-color: #FFFFFF;
		margin-left: 30rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
	}
	
	.itemRedStar {
		font-size: 32rpx;
		color: #D02B2B;
	}
	
	.addressBackView{
		background-color: #FFFFFF;
		width: 690rpx;
		border: 2rpx solid #F3F3F3;
		margin-left: 30rpx;
		padding-bottom: 24prx;
	}
	.addressTextAreaView{
		background-color: #FFFFFF;
		width: 640rpx;
		height: 40rpx;
		margin-top: 24rpx;
		margin-left: 24rpx;
		font-size: 28rpx;
		line-height: 40rpx;
		padding-bottom: 20rpx;
	}
	

	.right-margin-40{
		margin-right: 40rpx;
	}
	
	.blueColor{
		color: #007AFF;
	}
	.area{
		max-width: 400rpx;
	}

	/* 	.back_view{
		background-color: #FFFFFF;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		display: flex;
		flex-direction: column;
	}
	 */
</style>
