<template>
	<view>
		<uni-popup ref="popup" type="bottom" background-color="#fff" @touchmove.stop.prevent>
			<view class="popup_title">选择团队成员</view>
			<view class="searbox">
				<image :src="BASE_IMG_URL+'ss.png'" class="searimg" mode="scaleToFill"></image>
				<input @input="searchName" type="text" placeholder-style="color:#999;" 
					:class="keyword ? 'fontactive' : ''" v-model="keyword" placeholder="员工名称" class="li_box" />
			</view>
			<scroll-view scroll-y class="scrollbox" lower-threshold="30">
				<view class="liwarp" v-for="(item,index) in staffList" :key="index" @click="selectItem(item,index)">
					<view class="warpleft">
						<view class="name">名称:{{item.name}}({{item.roles == 1?'负责人':'成员'}})</view>
					</view>
					<label class="radio">
						<radio value="r1" color="#008EFF" :checked="staffObj.id == item.id" />
					</label>
				</view>
				<view class="noData" v-if="staffList.length == 0">暂无更多</view>
			</scroll-view>
			<view class="btnlist" @tap.stop.prevent>
				<view class="btn secbtn" @click="hideSelect">取消</view>
				<view class="btn firbtn" @click="sureSelect">确定</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import { netTeamList } from '@/api/index.js'
	import { BASE_IMG_URL } from '@/util/api.js'
	
	export default{
		props:{
			
		},
		data(){
			return{
				id:'',  //客户id
				keyword:'',
				staffList:[],
				staffObj:{},
				BASE_IMG_URL:BASE_IMG_URL
			}
		},
		methods:{
			init(id) {
				this.id = id
				this.$refs.popup.open()
				this.staffList = []
				this.getList()
			},
			getList() {
				let params = {
					name:this.keyword,
					id:this.id
				}
				netTeamList(params).then(res=>{
					this.staffList = res.data
				})
			},
			searchName(e) {
				this.staffList = []
				this.getList()
			},
			selectItem(item,index) {
				if(this.staffObj && this.staffObj.id == item.id){
					this.staffObj = null
				}else{
					this.staffObj = item
				}
			},
			closePopup() {
				this.$refs.popup.close()
			},
			sureSelect() {
				if(!this.staffObj){
					this.$refs.popup.close()
					return
				}
				this.$refs.popup.close()
				this.$emit('sureTeam',this.staffObj)
			},
			hideSelect() {
				this.$refs.popup.close()
			}
		}
	}
</script>

<style>
	radio{
		transform: scale(0.7);
	}
</style>
<style lang="scss" scoped>
	.popup_title{
		text-align: center;
		font-size:34rpx;
		color:#333;
		padding:24rpx;
	}
	.searbox{
		width:690rpx;
		height:60rpx;
		margin:0 24rpx 15rpx;
		border-radius: 30rpx;
		padding:0 24rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		background:#f5f5f5;
		.searimg{
			width: 50rpx;
			height: 50rpx;
			margin-right:10rpx;
		}
		.li_box{
			width:630rpx;
		}
	}
	.scrollbox{
		width:100%;
		height:600rpx;
		background:#f5f5f5;
		.liwarp {
			width: 702rpx;
			padding: 20rpx 30rpx;
			margin: 20rpx auto;
			background: #fff;
			border-radius: 10rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			
			.warpleft {
				flex: 1;
				display: flex;
				justify-content: flex-start;
				align-items: center;
			
				.headerimg {
					width: 50rpx;
					height: 50rpx;
					border-radius: 50%;
					margin-right: 15rpx;
				}
			
				.name {
					font-size: 24rpx;
					color: #333;
				}
			
				.number {
					font-size: 24rpx;
					color: #999;
					margin: 15rpx 0;
				}
			
				.guishu {
					font-size: 24rpx;
					color: #666;
				}
			}
		}
	}
	.btnlist {
		width: 750rpx;
		display: flex;
		justify-content: space-around;
		padding: 30rpx 0;
		border-top:1rpx solid #f5f5f5;
		.btn {
			width: 200rpx;
			height: 60rpx;
			border-radius: 30rpx;
			font-size: 24rpx;
			color: #fff;
			text-align: center;
			line-height: 60rpx;
		}
		
		.firbtn {
			background: #14C2C1;
		}
		
		.secbtn {
			background: #ff7800;
		}
	}
</style>
