<template>
	<view :style="{ minHeight: sys.windowHeight + 'px' }"
		:class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
		<tm-menubars title="添加成员" :shadow="0" :showback="true"></tm-menubars>
		<div class="zhuti">
			<tm-sheet class="kuang" style="padding-bottom: 70px !important;">
				<view>
					<view>
						<!-- <view class="fl zuo" style="width:70px;">
							<view class="flex-center flex-col mt-30" style="position: relative;" v-for="(item,index) in reqData.role">
								<image @click="qiehuanren(index)" block v-if="index==0" mode="widthFix" src="/static/img/53.png"></image>
								<image @click="qiehuanren(index)" block v-else mode="widthFix" src="/static/img/61.png"></image>
								<tm-badges icon="icon-times" @click="shanchu(item.timestamp)" v-if="(show==index && index !=0)"></tm-badges>
							</view>
							<view class="flex-center flex-col mt-30" style="position: relative;" v-if="reqData.role.length<4">
								<image block mode="widthFix" src="/static/img/54.png" @click="add()"></image>
							</view>
						</view> -->
						<view class="fr you black mt-30" style="width: 92%;">
							<tm-input  :required="true"  title="用户名" v-model="reqData.username" placeholder="你想叫自己什么" align="right"></tm-input>
							<tm-input  :required="true"  title="身高（cm）" v-model="reqData.height" align="right"></tm-input>
							<tm-input  :required="true"  title="体重（kg）" v-model="reqData.weight" align="right"></tm-input>
							<tm-pickers class="tan" :default-value.sync="reqData.body_arr" rang-key="title" :list="chelianglis">
								<tm-input name="shencai" title="身材" placeholder="请选择身材" disabled :value="obTstr2(reqData.body_arr)" right-icon="icon-angle-right"></tm-input>
							</tm-pickers>
						</view>
					</view>
					<view style="clear: both;"></view>
					<view class="anniu">
						<tm-button v-if="id != ''" @click="quxiao()" theme="gray" size="n">删除</tm-button>
						<tm-button @click="tijiao()" class="fr" theme="primary" size="n">确认</tm-button>
					</view>
					<!-- <tm-button :round="24" class="sao mb-40" style="margin-top: 50px;" @click="tijiao()" block>保存</tm-button> -->
				</view>
			</tm-sheet>
		</div>
		<!-- 弹出层消息 -->
		<tm-message ref="toast"></tm-message>
	</view>
</template>	
<script>
import{myRequest} from '@/api/request.js'
export default {
	data() {
		return {
			active:1,
			chelianglis:[
				{title:"标准",id:1},
				{title:"偏瘦",id:2},
				{title:"偏胖",id:3},
				{title:"梨形",id:4}
			],
			show:0,
			reqData:{
				family_id:uni.getStorageSync("family_id"),
				username:'',
				weight:'',
				height:'',
				body_type:'',
				body_arr:[]
			},
			id:''
		};
	},
	onLoad(e) {
		
		this.reqData.username=e.username;
		this.reqData.weight=e.weight;
		this.reqData.height=e.height;
		this.reqData.body_type=e.body_type;
		this.id=e.id?e.id:'';
		if(e.body_type){
			this.reqData.body_arr.push(this.chelianglis[e.body_type])
		}
		console.log(this.id)
	},
	created() {
		this.sys = uni.getSystemInfoSync();
	},
	methods: {
		qiehuanren(index){
			this.show=index;
		},
		quyifu(){
			uni.navigateTo({
				url: "/pages/luru/index",
			})
		},
		tijiao(){
			var that=this;
			if(this.reqData.username==""){
				that.$refs.toast.show({model:'warn',label:'请将数据填写完整'})
				return;
			}if(this.reqData.weight==""){
				that.$refs.toast.show({model:'warn',label:'请将数据填写完整'})
				return;
			}if(this.reqData.height==""){
				that.$refs.toast.show({model:'warn',label:'请将数据填写完整'})
				return;
			}
			if(this.reqData.body_arr.length !=0){
				this.reqData.body_type=this.reqData.body_arr[0].id;
			}
			if(that.id){
				this.reqData.id=that.id;
				var url="/api/MemberInfo/updateMemberInfo";
			}else{
				var url="/api/MemberInfo/addOneMemberInfo";
			}
			myRequest({
				url:url ,
				method:'post',
				data:that.reqData
			}).then(res => {
				console.log(res.data)
				if (res.data.code == 200) {
					let pages = getCurrentPages(); // 当前页面
					let beforePage = pages[pages.length - 2]; // 前一个页面
					uni.navigateBack({
						delta: 1,
						success: function() {
							beforePage.$vm.getDate()
						}
					});
				}else{
					that.$refs.toast.show({model:'error',label:res.data.msg})
				}
			})
			
		},
		quxiao(){
			var that=this;
			myRequest({
				url: "/api/MemberInfo/deleteMemberInfo",
				method:'post',
				data:{id:that.id}
			}).then(res => {
				console.log(res.data)
				if (res.data.code == 200) {
					let pages = getCurrentPages(); // 当前页面
					let beforePage = pages[pages.length - 2]; // 前一个页面
					uni.navigateBack({
						delta: 1,
						success: function() {
							beforePage.$vm.getDate()
						}
					});
				}else{
					that.$refs.toast.show({model:'error',label:res.data.msg})
				}
			})
		},
		obTstr2(o){
			if(Array.isArray(o)){
				if(o.length.length===0) return "";
				return o[0]?.title??""
			}
			return ''
		},
		saoma(){
			var that=this;
			uni.scanCode({
				scanType: ['barCode'],
				success: function (res) {
					console.log('条码类型：' + res.scanType);
					console.log('条码内容：' + res.result);
					that.reqData.wardrode_no=res.result;
					that.active=2;
				},
				error : function(e) {
					alert("网络异常，请重试");
				}
			})
		},
		chuangjianFun(){
			var that=this;
			if(that.reqData.familyname==""){
				that.$refs.toast.show({model:'warn',label:'请输入家庭名称'})
				return
			}
			that.active=3;
		}
	},
}
</script>

<style lang="scss">
	.zhanshi{
		width: 100%;
		margin: 0 auto;
		margin-top: 10px;
		margin-bottom: 40px;
	}
	/deep/ .tm-menubars .body{
		background-color: #1b1b1b !important;
	}
	/deep/ .kuang{margin:0 !important;padding: 14px !important;margin-bottom: 40px !important;}
	.jindu{width: 90%;margin: 0 auto;display: block;}
	.wenzi{width: 94%;margin: 0 auto;}
	.nicheng{width: 130px;height:132px;display: block;margin:0 auto;margin-top: 50px;}
	/deep/ .shuru .grey-darken-5{
		background-color: #0d0d0d!important;
		padding: 0px !important;
	}
	.shuru{border:1px solid #303030;border-radius: 10px;}
	/deep/ .shuru .text-primary.bk{color:#303030 !important;}
	/deep/ .shuru .border-grey-darken-4-b-1{border-bottom:none !important;}
	.zuo image{width:60px;display: block;}
	.you{border:1px solid #303030;border-radius: 10px;padding:10px;height: 300px;}
	/deep/ .you .grey-darken-5{
		background-color: #0d0d0d!important;
		padding: 0px !important;
	}
	/deep/ .you .text-red{color: white;}
	/deep/ .tan .active{background-color: #AAAAAA !important;}
	/deep/ .tan .tm-poups .grey-darken-5{background-color: gray !important;}
	/deep/ .tan uni-input{text-align: right;}
	/deep/ .you .border-grey-darken-4-b-1 {
	    border-bottom: solid 1px #313131 !important;
	}
	/deep/ .tm--badges{position: absolute;top: 0px;right:6px}
	.logincla{margin-top: 100px;}
	/deep/ .quindex uni-button{background-color: #0A84FF !important;}
	.anniu{width: 80%;margin: 0 auto;margin-top: 20px;}
	/deep/ .anniu .gray.bk{color: white !important;}
</style>
