<template>
	<RefreshView ref="mescrollRef" :hasBack="true" text="成员管理" :useDownScroll="false" :useUpScroll="false">
		<view class="top">
			<text class="top_lift">选中({{sidListSize}})</text>
			<text class="top_right" v-if="type==0" @click="agreeJoin()">同意入队</text>
			<text class="top_right" v-if="type==1" @click="deleteMember()">删除队员</text>
		</view>
		<view class="line"></view>
		<view>
			<view v-for="(item,index) in list " :key="index">
				<view class="item">
					<view class="line" style="height: 1px;"></view>
					<view class="item_content">
						<checkbox-group class="item_check" @change="checkboxChange($event, index)">
							<checkbox :checked="item.checked"></checkbox>
						</checkbox-group>
						<image class="item_img" :src="item.headImage" mode="aspectFill"></image>
						<text class="item_text">{{item.realName}}</text>
					</view>
				</view>
			</view>
		</view>
	</RefreshView>
</template>
<script>
	export default {
		data() {
			return {
				type: 0,
				// list: [{
				// 		headImage: "https://www.keaidian.com/uploads/allimg/190424/24110307_8.jpg",
				// 		realName: "张三",
				// 		sid: "111",
				// 		checked: false
				// 	},
				// 	{
				// 		headImage: "https://www.keaidian.com/uploads/allimg/190424/24110307_8.jpg",
				// 		realName: "张三",
				// 		sid: "222",
				// 		checked: false
				// 	}
				// ],
				list:[],
				sidListSize:0,
				sidList: [],
				sid: "",
			}
		},
		onLoad(options) {
			this.sid = options.sid
			this.type = options.type
			console.log('=======', options)
			console.log('=======', options.sid)
			console.log('=======', options.type)
			// 获取列表
			let _this = this
			_this.HTTP({
				url: 'aos/v1/aosUser/getPageListTeamMemberArea',
				paramsType: "JSON",
				method: "POST",
				data: {
					current: 1,
					size: 10,
					params: {
						sysUserSid: _this.sid,
						examineProgress: _this.type
					}
				},
				loading: true
			})
			.then((res) => {
				_this.list = res.data.records
			});
		},
		methods: {
			agreeJoin() {
				// 保存
				let _this = this
				_this.HTTP({
					url: 'aos/v1/aosUser/batchAgreeJoinMember',
					paramsType: "JSON",
					method: "POST",
					data: {
						teamSid: _this.sid,
						listMemberSid: _this.sidList,
					},
					loading: true
				})
				.then((res) => {
					uni.navigateBack({
						delta: 1
					})
				});
				
			},
			deleteMember() {
				let _this = this
				// 保存
				uni.showModal({
					title: '提示',
					content: '是否要删除选中的队员',
					success: function(res) {
						if (res.confirm) { 
							//这里是点击了确定以后
							// 保存
							
							_this.HTTP({
								url: 'aos/v1/aosUser/batchDelMember',
								paramsType: "JSON",
								method: "POST",
								data: {
									teamSid: _this.sid,
									listMemberSid: _this.sidList,
								},
								loading: true
							})
							.then((res) => {
								uni.navigateBack({
									delta: 1
								})
							});
						} else { //这里是点击了取消以后
							console.log('用户点击取消')
						}
					}
				})
			},
			checkboxChange(e, index) {
				console.log("index=====>" + index)
				// 切换选择
				this.list[index].checked = !this.list[index].checked
				
				if (this.list[index].checked) {
					// 添加Sid
					this.sidList.push(this.list[index].sid)
				} 
				else {
					// 删除当前的Sid
					let sss = this.list[index].sid
					console.log("sss>>>>" + sss)
					let pos = this.sidList.findIndex((x) => {

						console.log(">>>>" + x)

						return x == sss

					})
					console.log("pos=====>" + pos)
					this.sidList.splice(pos, 1)
				}
				this.sidListSize = this.sidList.length
				console.log("asdfasdfasdfsad=====>" , this.listSize)
				console.log("sidList=====>" + JSON.stringify(this.sidList))
			},

		}
	}
</script>

<style lang="scss">
	@import url("../../static/master.css");
	.line {
		height: 10rpx;
		background: #eee;
		width: 100%;
	}

	.top {
		display: flex;
		background: #fff;
		flex-direction: row;
		width: 100%;
		padding-top: 26rpx;
		padding-bottom: 26rpx;

		.top_lift {
			margin-left: 30rpx;
			font-weight: 550;
			font-family: sans-serif;
			flex: 1;
			color: #101010;
			font-size: 36rpx;
		}

		.top_right {
			margin-right: 30rpx;
			background-color: #F4CE98;
			color: #fff;
			font-size: 24rpx;
			padding: 10rpx 20rpx;
			text-align: right;
		}
	}

	.item {

		display: flex;
		flex-direction: column;

		.item_content {
			display: flex;
			align-items: center;
			background-color: #fff;
			padding: 20rpx 32rpx;
			flex-direction: row;

			.item_check {
				width: 32rpx;
				height: 32rpx;
			}

			.item_img {
				margin-left: 40rpx;
				width: 80rpx;
				height: 80rpx;
				border-radius: 10rpx;
			}

			.item_text {
				font-size: 28rpx;
				color: #101010;
				margin-left: 40rpx;
			}
		}

	}
</style>
