<template>
	<view class="page-wrap">
		<view class="pageTabs">
			<uni-segmented-control :current="tabIdx" :values="tabs" style-type="text" active-color="#007aff" @clickItem="changeTab" />				
		</view>	
		<view class="pageMain">
			<view class="teamhead">
				<uni-data-select  v-model="teamId" class="item-select" @change="changeTeamType":localdata="teamList" :clear="false"></uni-data-select>	
				<view class="handle-bt" @click="editTeam">
					<text>编辑</text>
				</view>
			</view>
			<uni-collapse value="0" ref="collapse" accordion>
				<uni-collapse-item :title="teamName">
					<view class="teamDuty">
						<text>{{teamDuty}}</text>
					</view>
				</uni-collapse-item>
			</uni-collapse>
			<view class="item-container">
				<view class="teamhead">
					<view class="item-select">
						<text>成员列表</text>
					</view>
					<view class="handle-bt" @click="addMember">
						<text>新增</text>
					</view>
				</view>
				<view class="item" v-for="item in items" :key="item.memberId">
					<view class="avatar">
						<image :src="item.memberAvatar" v-if="item.memberAvatar"></image>
						<image class="icon" src="/static/images/avatar.png" v-else></image>
					</view>
					<view class="info">
						
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import teamApi from '@/api/team.js'
	export default {
		data() {
			return {
				tabIdx:0,
				tabs:['专业救援队伍','行业救援队伍','综合抢险队伍'],
				teamList:[],
				teamId:undefined,
				teamId:undefined,
				teamName:"",
				teamDuty:"",
				items:[]
			}
		},
		onShow() {
			this.getData()
		},
		methods: {
			changeTab({currentIndex}){
				if (this.tabIdx !== currentIndex) {
					this.tabIdx = currentIndex	
					this.getData()
				}
			},
			changeTeamType(){
				this.getTeamInfo()
			},
			getData(){
				teamApi.getByList({teamType:this.tabIdx+1}).then((res)=>{
					if(res.data.length>0){
						this.teamList=res.data.map(item=>{
							return{
								value:item.teamId,
								text:item.teamName
							}
						})	
						this.teamId=res.data[0].teamId				
						this.getTeamInfo()
					}
				})				
			},
			getTeamInfo(){
				teamApi.getById(this.teamId).then((result)=>{
					this.teamName=result.data.teamName
					this.teamDuty=result.data.teamDuty
					// #ifdef MP
					this.$nextTick(() => {
						this.$refs.collapse.resize()
					})
					// #endif
				})	
				teamApi.getMemberByList({teamId:this.teamId}).then((res)=>{
					this.items=res.data
				})	
			},
			editTeam(){
				
			},
			addMember(){
				
			}
		}
	}
</script>

<style lang="scss" scoped>
.page-wrap{
	padding:0 20rpx;
	.pageTabs{
		background-color: #fff;
	}
	.pageMain{
		margin-top: 20rpx;
		background-color: #f5f5f5;
		.teamhead{
			padding: 20rpx;
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.item-select{
				width: 400rpx;
			}
			.handle-bt{
				padding: 20rpx 30rpx;
				font-size: 24rpx;
				color: #409eff;
				line-height: 1;
				flex-shrink: 0;
			}
		}
		.teamDuty{
			padding: 20rpx;
			line-height: 1.5;
		}
		.item-container{
			margin-top: 20rpx;
			padding-bottom: 50rpx;
			.item{
				&{
					display: flex;
					justify-content: space-between;
					align-items: center;
					background-color: #fff;
					box-shadow:0 0 2px rgba(0,0,0,0.3) ;
					margin-top: 20rpx;
					padding: 20rpx;
				}
				.avatar {
					flex-shrink: 0;
					width: 60rpx;
					height: 60rpx;
					overflow: hidden;
					border-radius: 50%;
					background-color: #ddd;
					image{
						width: 60rpx;
						height: 60rpx;	
					}
				}
			}
		}
	}
}
</style>
