<template>
	<view class="default_page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='编辑团队'></cus-header>
		<cus-team-info-fill ref="teamRef" @handleConfirm="handleConfirm" :confirmText="confirmText"></cus-team-info-fill>
		<view class="dialog adffcacjc" v-if="show">
			<view class="dbox">
				<view class="dbox-title">温馨提示</view>
				<view class="dbox-content">本次团队配置修改将在本团队<span>所有激活状态下的PERILL团队发展动态评估问卷中</span>生效，确定提交吗？</view>
				<view class="dbox-btns adfacjb">
					<view class="zt_btn" @click="editConfirm">确定</view>
					<view class="qx_btn" @click="show=false">取消</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import CusTeamInfoFill from '@/components/CusTeamInfoFill/index.vue'
	export default {
		components:{ CusTeamInfoFill },
		data(){
			return {
				id:'',
				teamInfo:null,
				confirmText:'确定',
				scaleName:'',
				hierarchyName:'',
				submitDto:null,
				show:false
			}
		},
		onLoad(options) {
			this.id = options.id;
			this.scaleName = options.scaleName;
			this.hierarchyName = options.hierarchyName;
			this.getDetail()
		},
		methods:{
			getDetail(){
				this.$api.get(`/core/user/team/${this.id}`).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.teamInfo = res.data;
					this.$refs.teamRef.setTeamInfo(res.data)
					this.$refs.teamRef.teamInfo.functionIds = res.data.functions.map(f=>f.id);
					this.$refs.teamRef.teamInfo.orgIds = res.data.organizations.map(o=>o.id);
					this.$refs.teamRef.areaText = res.data.provinceName+res.data.cityName;
					this.$refs.teamRef.industryText = res.data.industryName;
					this.$refs.teamRef.functionTypeText = res.data.functions.map(f=>f.functionName).join('、');
					this.$refs.teamRef.architectureTypeText = res.data.organizations.map(f=>f.orgName).join('、');
					this.$refs.teamRef.teamScaleText = this.scaleName;
					this.$refs.teamRef.teamLevelText = this.hierarchyName;
				})
			},
			handleConfirm(data){
				data.coachId = JSON.parse(uni.getStorageSync('userInfo')).id;
				this.submitDto = data;
				this.show = true;
			},
			editConfirm(){
				this.$api.put('/core/user/team',this.submitDto).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.$showToast('编辑成功')
					setTimeout(()=>{
						uni.redirectTo({
							url:'/pagesMy/team'
						})
					},1500)
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.default_page{
		box-sizing: border-box;
	}
	.dialog{
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		background: rgba(0, 0, 0, .4);
		z-index: 1000;
		.dbox{
			width: calc(100% - 150rpx);
			background: #FFFFFF;
			border-radius: 32rpx;
			padding: 48rpx 30rpx;
			box-sizing: border-box;
			&-title{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 34rpx;
				color: #002846;
				line-height: 48rpx;
				text-align: center;
			}
			&-content{
				padding: 0 14rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 32rpx;
				color: #002846;
				line-height: 54rpx;
				text-align: center;
				margin-top: 30rpx;
				span{
					font-weight: bold;
				}
			}
			&-btns{
				margin-top: 56rpx;
				&>view{
					width: calc(50% - 20rpx);
				}
			}
		}
	}
</style>