<template>
	<RefreshView ref="mescrollRef" text="报名条件" :useDownScroll="false" :useUpScroll="false" :useTitleLeftBtn="1" titleLeftBtnSource="设置" @leftBtn='setup'>
		<view class="row">
			<text class="field">性别限制</text>
			<radio-group @change="radioSexChange($event)">
				<radio :checked="data.listEnrollConditionRelationSexAge[0].sex==0" :value="0" >不限</radio>
				<radio :checked="data.listEnrollConditionRelationSexAge[0].sex==1" :value="1" style="margin-left: 80rpx;">男</radio>
				<radio :checked="data.listEnrollConditionRelationSexAge[0].sex==2" :value="2" style="margin-left: 80rpx;">女</radio>
			</radio-group>
		</view>
		<view class="line-thin"></view>
		<picker mode="multiSelector" :range="page.age" @change="bindAgeChange($event,index)">
			<view class="row">
				<text class="field">年龄段</text>
				<text class="explain">{{page.ageRangeText}}</text>
				<image class = "more" src="../../static/img/public/more.png" ></image>
			</view>
		</picker>
	</RefreshView>
</template>

<script>
	export default {
		data() {
			return {
				data:{
					listEnrollConditionRelationSexAge:[{
						enrollConditionRelationsid: "",
						conditionSid: "",
						sex:0,
						minAge:0,
						maxAge:0
						}
					]
				},
				page:{
					age:[
						[],
						[]
						]
					},
					ageRangeText:""
			}
		},
		onLoad(options){
			let listEnrollConditionRelationSexAge = JSON.parse(options.listEnrollConditionRelationSexAge)
			console.log("==================================",listEnrollConditionRelationSexAge)
			let _this = this
			if (listEnrollConditionRelationSexAge != undefined){
				_this.data.listEnrollConditionRelationSexAge[0].enrollConditionRelationsid = listEnrollConditionRelationSexAge[0].enrollConditionRelationsid;
				_this.data.listEnrollConditionRelationSexAge[0].conditionSid = listEnrollConditionRelationSexAge[0].conditionSid;
				_this.data.listEnrollConditionRelationSexAge[0].sex = listEnrollConditionRelationSexAge[0].sex == undefined ?0 :listEnrollConditionRelationSexAge[0].sex;
				_this.data.listEnrollConditionRelationSexAge[0].minAge = listEnrollConditionRelationSexAge[0].minAge == undefined ?0:listEnrollConditionRelationSexAge[0].minAge;
				_this.data.listEnrollConditionRelationSexAge[0].maxAge = listEnrollConditionRelationSexAge[0].maxAge == undefined ?0:listEnrollConditionRelationSexAge[0].maxAge;
			}
			// 设置10岁到100岁的数组
			_this.page.age[0].push("不限")
			_this.page.age[1].push("不限")
			for(let i =10; i<=100; i++){
				_this.page.age[0].push(i + "岁");
				_this.page.age[1].push(i + "岁");
			}
			// 年龄段范围文字赋值
			this.page.ageRangeText = this.convertAgeRangeText(this.data.listEnrollConditionRelationSexAge[0].minAge,this.data.listEnrollConditionRelationSexAge[0].maxAge)
		},
		methods:{
			radioSexChange(e) {
				let _this = this
				_this.data.listEnrollConditionRelationSexAge[0].sex = parseInt( e.detail.value)
			},
			bindAgeChange(e,index){		
				console.log("--------------------------",JSON.stringify(e.detail.value[0]))
				if (e.detail.value[0] == 0){this.data.listEnrollConditionRelationSexAge[0].minAge = 0}else{this.data.listEnrollConditionRelationSexAge[0].minAge =  e.detail.value[0] + 9}
				if (e.detail.value[1] == 0){this.data.listEnrollConditionRelationSexAge[0].maxAge = 0}else{this.data.listEnrollConditionRelationSexAge[0].maxAge =  e.detail.value[1] + 9}
				// this.page.ageRange = this.page.age[0][e.detail.value[0]] + " 到 " + this.page.age[1][e.detail.value[1]]
				this.page.ageRangeText = this.convertAgeRangeText(this.data.listEnrollConditionRelationSexAge[0].minAge,this.data.listEnrollConditionRelationSexAge[0].maxAge)
			},
			setup(){
				this.data.listEnrollConditionRelationSexAge[0] = JSON.stringify(this.data.listEnrollConditionRelationSexAge[0])
				console.log("=======================================>>>>>>>>>>>>>>>>asdfasdf",this.data)
				this.SetResult(this.data)
			},
			convertAgeRangeText(minAge,maxAge){
				if(minAge == 0 && maxAge == 0 ){
					return "不限年龄"
				}
				if(minAge == 0 && maxAge > 0 ){
					return maxAge + "岁以下"
				}
				if(minAge > 0 && maxAge == 0 ){
					return minAge + "岁以上"
				}
				if(minAge > 0 && maxAge > 0 ){
					return minAge + "岁  至  " + maxAge +"岁"
				}
			}
		}
	}
</script>
<style>
	@import url("../../static/master.css");
</style>