<template>
	<uv-toast ref="toast"></uv-toast>
	<view class='titlearea'>        
		<text class='title_2'>{{$t('select_gender_for_valuating_people')}}</text>
		<text class='title_member'>{{$t('valuating_people')}}：{{selectuser.membername}}</text>
		<text class='title_desstr' decode='true'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{$t('select_gender_text_1')}}</text>
	</view>
	<view>
		<uv-row justify="space-between" customStyle="margin-top: 6%">
			<uv-col span="6" align="center" @click="selectsex(1)">
				<uv-image class="img" src="/static/image/selecttype/man.png" mode="aspectFill"
					shape="circle" :lazy-load="true" width="150" height="150">
				</uv-image>
				<view class='mybtn' >{{$t('is_man')}}</view>
			</uv-col>
			<uv-col span="6" align="center" @click="selectsex(2)">
				<uv-image class="img" src="/static/image/selecttype/woman.png" mode="aspectFill"
					shape="circle" :lazy-load="true" width="150" height="150">
				</uv-image>
				<view class='mybtn'  >{{$t('is_female')}}</view>
			</uv-col>
		</uv-row>
	</view>
</template>

<script>
	import {tohome,tostemlistnext} from "/common/js/common.js"
	import {subanswerbyuserid} from "/common/api/scale.js"
	import {submembergenderwithuid} from "/common/api/fmember.js"
	export default{
		data(){
			return{
				userinfo:{},
				selectuser:{},
				scaleid:0,
				srid:0,
				scaleid:0,
				stemid:3,
				answertype: 1,
			}	
		},
		methods: {
			init(){
				this.userinfo = uni.getStorageSync("userinfo")
				this.selectuser = uni.getStorageSync("selectuser")
			},
			selectsex(sex){
				let answervalue = false
				let answeroptionid = false
				switch(sex){
					case 1:
						answervalue=this.$t('man');
						answeroptionid=64
					break;
					case 2:
						answervalue=this.$t('female');
						answeroptionid=65
					break;
					default:
						return
					break;
					}
				let answer={
					userid:this.userinfo.id,
					fmemberid:this.selectuser.fmemberid,
					stemid:this.stemid,
					answertype:this.answertype,
					answervalue:answervalue,
					answeroptionid:answeroptionid
				}
				let data={
					userid:this.userinfo.id,
					fmemberid:this.selectuser.fmemberid,
					srid: this.srid,
					scaleid: this.scaleid,
				}
				subanswerbyuserid(answer,data).then(res=>{
					res = res.data
					if(0==res.code){
						this.$refs.toast.show({
							type: 'error',
							message: res.errmsg
						})
						return false
					}
					if(200==res.code){
						uni.setStorage({
							key: 'srid',
							data: res.resultData,
						});
						let data1 = {
							userid:this.userinfo.id,
							fmemberid:this.selectuser.fmemberid,
							gender:sex
						}
						submembergenderwithuid(data1)
						tostemlistnext(this.sindex,1)
					}
				})
			}
		},
		mounted() {
			uni.setNavigationBarTitle({
				title: this.$t('select_sex')
			});
			this.init()
		},
		onLoad: function (option) {
			this.scaleid=option.scaleid
			this.srid=option.srid
			this.sindex = option.sindex
		},
		onBackPress:function(option){
			tohome()
			return true
		}
	}
</script>

<style scoped>
	.titlearea{
	    height:400rpx;
	    display:flex;
	    flex-direction:column;
	    justify-content: center;  
	    align-items:center;
	}
	.title_2{
	    margin-top:15rpx;
	    font-size:36rpx;
	    font-weight:400;
	    color:#666666 
	}
	.title_member{
	    margin-top:30rpx;
	    font-size:36rpx;
	    font-weight:400;
	    color:#648EB8; 
	}
	.title_desstr{
	    width:700rpx;
	    margin-left:25rpx;
	    margin-top:30rpx;
	    font-size:36rpx;
	    font-weight:400;
	    color:#9C9C9C;
	}
	.mybtn{
		width:50%;
		font-size: 15px;
	}
</style>