<template>

	<RefreshView ref="mescrollRef" :pageBg="EDEDED" :hasBack="true" text="实名信息" :useDownScroll="false" :useUpScroll="false" >
		<view @click="toModiRealName()" class="menu-item">
			<text class="text">姓名</text>
			<text class="explain">{{page.realName}}</text>
			<image class = "more" src="../../static/img/public/more.png" ></image>
		</view>
		<view class="line-thin"></view>
		<view @click="clickSex()" class="menu-item">
			<text class="text">性别</text>
			<text class="explain">{{page.sexView}}</text>
			<image class = "more" src="../../static/img/public/more.png" ></image>
		</view>
		<view class="line-thin"></view>
		<uni-datetime-picker style="flex: 1;" type="date" :value="page.birthday" :start="startDate" :end="endData"
			@change="modiBirthday()">
			<view class="menu-item">
				<text class="text">生日</text>
				<text class="explain">{{this.IsEmpty(page.birthday) ?"请选择生日":page.birthday}}</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
		</uni-datetime-picker>

		<view class="line-thin"></view>
		<pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
			<view class="menu-item">
				<text class="text">地区</text>
				<text class="explain">{{this.IsEmpty(page.adName) ?"请选择地区":page.adName}}</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
		</pick-regions>
	</RefreshView>

</template>

<script>
	import pickRegions from '@/components/pick-regions/pick-regions.vue'
	export default {
		components: {
			pickRegions
		},
		created() {
			this.startDate = this.TimeFormat(this.CurrentMillions() - 100 * 365 * 24 * 60 * 60 * 1000);
			this.endData = this.TimeFormat(this.CurrentMillions() );
		},
		data() {
			return {
				region: [],
				defaultRegion: ['北京市', '市辖区', '东城区'],
				defaultRegionCode: '110101',
				region_sid_path: "",
				address_path: "北京市/市辖区/东城区",
				startDate: "1921-01-01",
				endData: "",
				pickerDate: "",
				page: {
					sid:"",
					realName:"",
					sex:"男",
					birthday:"",
					mobile:"",
					adCode:"110101",
					adName:"北京市/市辖区/东城区"
				},
				contorl:{
					listSex:["男","女"]
				},
			}
		},
		onLoad(options){
			this.page.sysUserSid = options.sysUserSid
		},
		onShow() {
			
			let _this = this
			_this.HTTP({
				url: 'aos/v1/aosUser/getRealInfoBySysUserSid/' + getApp().globalData.sysUserSid,
				method: 'GET',
				paramsType: "FORM",
				loading: true
			}).then((res) => {
				console.log('=======', res)
				_this.page = res.data				
			});
		},
		methods: {

			clickSex() {
				let _this = this;
				uni.showActionSheet({
					itemList: this.contorl.listSex,
					success: function(res) {
						_this.selectSex(res.tapIndex + 1)
					}
				});
			},
			selectSex(id) {
				let _this = this
				switch (id) {
					case 1:
						this.page.sex = '男'
						_this.HTTP({
							url: 'aos/v1/aosUser/realInfoAttestation',
							method: 'POST',
							paramsType: "JSON",
							data: {
								sid: _this.page.sid,
								sex:  1
							},
							toast: true,
							loading: true
						}).then((res) => {
							console.log('=======', res)
						});
						break;
					case 2:
						this.page.sex = '女'
						
						_this.HTTP({
							url: 'aos/v1/aosUser/realInfoAttestation',
							method: 'POST',
							paramsType: "JSON",
							data: {
								sid: _this.page.sid,
								sex:  2
							},
							toast: true,
							loading: true
						}).then((res) => {
							console.log('=======', res)
						});
						break;
					case 3:
						break
				}
			},
			modiBirthday(e) {
				let _this = this
				_this.page.birthday = e
				_this.HTTP({
					url: 'aos/v1/aosUser/realInfoAttestation',
					method: 'POST',
					paramsType: "JSON",
					data: {
						sid:  _this.page.sid,
						birthday: _this.page.birthday
					},
					toast: true,
					loading: true
				}).then((res) => {
					console.log('=======', res)
				});
				console.log("生日", _this.page.birthday);
				return;
			},
			toModiRealName(){
				let _this = this
				if (getApp().globalData.isLogin ) {
						uni.navigateTo({
							url: 'ModiRealName?realName=' + _this.page.realName + '&sysUserInfoSid=' +  _this.page.sid
						})
					}
			},
			realInfoAttestation(data){
				let _this = this
				_this.HTTP({
					url: 'aos/v1/aosUserManagement/attestation',
					method: 'POST',
					paramsType: "JSON",
					data: data,
					toast: true,
					loading: true
				}).then((res) => {
					console.log('=======', res)
				});
			},
			modiSex(){
				let _this = this
				_this.HTTP({
					url: 'aos/v1/aosUser/realInfoAttestation',
					method: 'POST',
					paramsType: "JSON",
					data: {
						sid:  _this.page.sid,
						sex: _this.page.sex == "女" ? "2" : "1"
					},
					toast: true,
					loading: true
				}).then((res) => {
					console.log('=======', res)
				});
			},
			// 获取选择的地区
			handleGetRegion(region) {
				let _this = this
				_this.region = region
				let code = _this.region.map(item => item.code)
				let name = _this.region.map(item => item.name)
				console.log('地区代码', code)
				console.log('地区名称', name)
				_this.page.adCode = code[2]
				_this.page.adName = name[0] + " " + name[1] + " " + name[2]
				_this.HTTP({
					url: 'aos/v1/aosUser/realInfoAttestation',
					method: 'POST',
					paramsType: "JSON",
					data: {
						sid: _this.page.sid,
						adCode: _this.page.adCode,
						adName: _this.page.adName
					},
					toast: true,
					loading: true
				}).then((res) => {
					console.log('=======', res)
				});
				return
			}
		}
	}
</script>

<style lang="scss">
	@import url("../../static/master.css");
</style>