<template>
	<view>
		<view class="content pb180">
			<view class="info-item">
				<view class="label">姓名</view>
				<view class="right">
					<text class="text">{{name}}</text>
				</view>
			</view>
			<view class="info-item">
				<view class="label">性别</view>
				<view class="right">
					<view class="fs28" :class="sex?'base-color-0':'base-color-6'"
					@click="show=!show">{{sex?sex:'请输入性别'}}</view>
					<u-picker :show="show" :columns="columns" @confirm='confirm'
					@cancel='show=!show'></u-picker>
				</view>
			</view>
			<view class="info-item">
				<view class="label">年龄</view>
				<view class="right">
					<input type="text" v-model="age" placeholder="请输入年龄" class="input"></text>
				</view>
			</view>
			<view class="info-item">
				<view class="label">行为习惯</view>
				<view class="right">
					<input type="text" v-model="habits" placeholder="请输入行为习惯" class="input"></text>
				</view>
			</view>
			<view class="info-item">
				<view class="label">患病时间</view>
				<view class="right">
					<input type="text" v-model="illnessTime" placeholder="请输入患病时间" class="input"></text>
				</view>
			</view>
			<view class="info-item">
				<view class="label">疾病</view>
				<view class="right">
					<input type="text" v-model="disease" placeholder="请输入疾病" class="input"></text>
				</view>
			</view>
			 <view class="info-item">
			 	<view class="label">家人的疾病</view>
			 	<view class="right">
					<input type="text" v-model="familyDisease" placeholder="请输入家人的疾病" class="input"></text>
			 	</view>
			 </view>
			<view class="info-item">
				<view class="label">是否线下就诊</view>
				<view class="right">
					<input type="text" v-model="isLine" placeholder="请输入是否线下就诊" class="input"></text>
				</view>
			</view>
			<view class="info-item">
				<view class="label">体质</view>
				<view class="right">
					<input type="text" v-model="constitution" placeholder="请输入体质" class="input"></text>
				</view>
			</view>
			<view class="info-item">
				<view class="label">使用药品</view>
				<view class="right">
					<input type="text" v-model="medicine" placeholder="请输入使用药品" class="input"></text>
				</view>
			</view>
			<view class="info-item">
				<view class="label">咨询产品</view>
				<view class="right">
					<input type="text" v-model="consultProduct" placeholder="请输入咨询产品" class="input"></text>
				</view>
			</view>
			<view class="info-item">
				<view class="label">是否已经购买产品</view>
				<view class="right">
					<input type="text" v-model="isBuy" placeholder="请输入是否已经购买产品" class="input"></text>
				</view>
			</view>
		</view>
		<view class="btn-box">
			<view class="sub-btn" @click="submit()">保存修改</view>
		</view>
	</view>
	

</template>

<script>
	import { getcustomer,updataUser } from "@/api/user.js";
	export default {
		data() {
			return {
				name:"",
				deptName:"",
				postNames:"",
				sexPicker: ['男', '女','未知'],
				sex: 0, // 性别
				age:"",
				habits:"",//行为习惯
				illnessTime:"",//患病时间
				disease:"",//疾病
				familyDisease:"",//家人疾病
				isLine:"",//是否线下就诊
				constitution:"",//体质
				medicine:"",//使用药品
				consultProduct:"",//咨询产品
				isBuy:"",//是否已经购买产品
				externalUserId:50,
				show: false,
				columns: [
					['男', '女', '未知']
				],
			}
		},
		onLoad(options) {
			// this.externalUserId=options.externalUserId
			this.getuser()
		},
		methods: {
			confirm(e) {
				console.log('confirm', e)
				this.sex=e.value[0]
				this.show = false
			},
			bindUser(data){
				var that=this;
				that.sex=data.sex;
				that.age=data.age;
				that.habits=data.habits;
				that.illnessTime=data.illnessTime;
				that.disease=data.disease;
				that.familyDisease=data.familyDisease;
				that.isLine=data.isLine;
				that.constitution=data.constitution;
				that.medicine=data.medicine;
				that.consultProduct=data.consultProduct;
				that.isBuy=data.isBuy;
			},
			getuser(){
				const data={
					qwExternalContactId:this.externalUserId
				}
				getcustomer(data).then(res=>{
					if (res.code == 200) {
						this.detailUser=res.data
						// this.moreInfo=res.moreInfo
						this.name=res.data.name;
						this.bindUser(res.moreInfo);
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			},
			// 性别选择
			pickerSex(e) {
				console.log(e)
				this.sex = e.detail.value
			},
			submit(){
				if (this.utils.isEmpty(this.sex)) {
					uni.showToast({
						title: "请输入性别",
						icon: 'none',
					});
					return
				}
				if (this.utils.isEmpty(this.age)) {
					uni.showToast({
						title: "请输入年龄",
						icon: 'none',
					});
					return
				}
				uni.showLoading({
					title: '加载中'
				});
				var data = {
					externalContactId:this.externalUserId,
					name:this.phonenumber,
					age:this.age,
					sex:this.sex.toString(),
					habits:this.habits,
					illnessTime:this.illnessTime,
					disease:this.disease,
					familyDisease:this.familyDisease,
					isLine:this.isLine,
					constitution:this.constitution,
					medicine:this.medicine,
					consultProduct:this.consultProduct,
					isBuy:this.isBuy
					};
				console.log(data);
				updataUser(data).then(
					res => {
						uni.hideLoading();
						if(res.code==200){
							uni.showToast({
								title: '修改成功',
								duration: 2000
							});
							// setTimeout(function() {
							// 	uni.navigateBack({
							// 	  success: () => {
							// 	  }
							// 	})
							// }, 500);
							this.getuser()
						}
						else{
							uni.showToast({
								title: res.msg,
								icon: 'none',
							});
						}
						
					},
					rej => {}
				);
				
			}
			
		}
	}
</script>


<style scoped lang="scss">
	.base-color-0{
		color: #000;
	}
	.content{
		padding-top: 20rpx;
		border-top: 1px solid #F5F6FA;
	}
	.info-item{
		height: 104upx;
		background: #FFFFFF;
		padding: 0 30upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1px solid #F5F6FA;
		&:last-child{
			border-bottom: none;
		}
		.label{
			
			font-size: 30upx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #0F1826;
		}
		.right{
			display: flex;
			align-items: center;
			justify-content: center;
			.text{
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #0F1826;
			}
			.image{
				margin-left: 10upx;
				width: 30upx;
				height: 30upx;
			}
			.input{
				text-align: right;
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #0F1826;
			}
		}
		.head{
			border-radius: 50%;
			width: 80upx;
			height: 80upx;
		}
		.arrow{
			width: 30upx;
			height: 30upx;
		}
		.text{
			font-size: 30upx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #0F1826;
		}
		.input{
			text-align: right;
			font-size: 30upx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #0F1826;
		}
		&.password{
			margin-top: 20upx;
			.right{
				display: flex;
				align-items: center;
				.text{
					font-size: 30upx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #0F1826;
					margin-right: 15upx;
				}
			}
		}
	}
	.btn-box{
		margin-top: 15rpx;
		padding: 0 30upx;
		position: fixed;
		bottom: 0;
		background-color: #FFFFFF;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
		width: 100%;
		align-items: center;
		justify-content: center;
		.sub-btn{
			width: 100%;
			height: 88upx;
			line-height: 88upx;
			text-align: center;
			font-size: 30upx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			background: #078df3;
			border-radius: 44upx;
		}
	}
</style>
