<template>
	<view class="default_page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header :title='title'></cus-header>
		<view class="form">
			<view class="form-item adfacjb">
				<view class="form-item-left">姓名</view>
				<view class="form-item-right">
					<u-input v-model="userInfo.realName" placeholder="请输入团队人员姓名" border="none" style="font-size: 28rpx;color: #B3BFC8;line-height: 28rpx;" inputAlign="right"></u-input>
				</view>
			</view>
			<view class="form-item adfacjb">
				<view class="form-item-left">手机号码</view>
				<view class="form-item-right">
					<u-input v-model="userInfo.mobile" placeholder="请输入手机号码" border="none" style="font-size: 28rpx;color: #B3BFC8;line-height: 28rpx;" inputAlign="right"></u-input>
				</view>
			</view>
			<view class="form-item adfacjb">
				<view class="form-item-left">邮箱</view>
				<view class="form-item-right">
					<u-input v-model="userInfo.email" placeholder="请输入邮箱" border="none" style="font-size: 28rpx;color: #B3BFC8;line-height: 28rpx;" inputAlign="right"></u-input>
				</view>
			</view>
		</view>
		<!-- <view class="type adfacjb" @click="typeShow=true">
			<view class="type-left">团队人员身份类型</view>
			<view class="type-right adfac">
				<text>{{typeText}}</text>
				<image :src="imgBase+'my_arrow_right.png'"></image>
			</view>
		</view> -->
		<view class="zt_btn" @click="handleConfirm">确定</view>
		<u-picker :itemHeight="88" :immediateChange="true" :show="typeShow" :columns="typeData" title="成员身份类型"
			@cancel="typeShow=false" @confirm="typeConfirm" keyName="name" ></u-picker>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				type:'',
				title:'团队成员',
				userInfo:{
					id:'',
					coachId:JSON.parse(uni.getStorageSync('userInfo')).id,
					realName:'',
					mobile:'',
					email:'',
				},
				typeText:'请选择',
				typeShow:false,
				typeData:[[
					{id:1,name:'团队Leader'},
					{id:2,name:'团队成员Member'},
					{id:3,name:'利益相关者Stakeholder'},
					{id:4,name:'赞助人Sponsor'}
				]],
			}
		},
		onLoad(options) {
			this.type = options.type;
			if(options.id){
				this.title = '编辑成员';
				this.getDetail(options.id)
			} 
		},
		methods:{
			getDetail(id){
				this.$api.get(`/core/member/${id}`).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.userInfo = {...this.userInfo,...res.data}
				})
			},
			typeConfirm(e){
				this.typeShow = false;
			},
			handleConfirm(){
				if(!this.userInfo.realName) return this.$showToast('请输入姓名')
				if(!this.$reg.mobile(this.userInfo.mobile)) return this.$showToast('请输入正确的手机号')
				if(!this.$reg.email(this.userInfo.email)) return this.$showToast('请输入正确的邮箱')
				
				this.$api[this.userInfo.id?'put':'post']('/core/member',this.userInfo).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.$showToast(`${this.userInfo.id?'编辑':'添加'}成功`);
					uni.navigateBack();
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.default_page{
		padding: 0 24rpx 54rpx;
		box-sizing: border-box;
		background: #F7F7F7;
		
		.form{
			background: #FFFFFF;
			border-radius: 24rpx 24rpx 0rpx 0rpx;
			margin-top: 20rpx;
			&-item{
				box-shadow: inset 0rpx -1rpx 0rpx 0rpx #EFEFEF;
				padding: 28rpx 24rpx;
				&-left{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 30rpx;
					color: #002846;
					line-height: 42rpx;
				}
			}
		}
		
		.type{
			background: #FFFFFF;
			box-shadow: inset 0rpx -1rpx 0rpx 0rpx rgba(229,231,235,0.5);
			border-radius: 24rpx;
			margin-top: 20rpx;
			padding: 28rpx 24rpx;
			&-left{
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #002846;
				line-height: 42rpx;
			}
			&-right{
				text{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #B3BFC8;
					line-height: 40rpx;
				}
				image{
					width: 30rpx;
					height: 30rpx;
					box-sizing: border-box;
				}
			}
		}
		
		.zt_btn{
			width: calc(100% - 100rpx);
			position: fixed;
			left: 50rpx;
			bottom: 54px;
		}
	}
</style>