<template>
	<view class="">
		<view class="search-user flex-y-center ">
			<view class="search-content flex-y-center">
				<icon type="search" size="18" />
				<input confirm-type="search" v-model="seTval" @confirm="confirm" @input="getSearch" class="flex-grow-1"
					type="text" placeholder-style="font-size:26rpx" placeholder="请输入用户id" />
				<view class="flex-center" style="margin-left: 10rpx;" @click.stop="onDel" v-if="seTval">
					<icon type="clear" size="18" />
				</view>
			</view>
			<view class="search-btn" @click="search">
				搜索
			</view>
		</view>
		
		<view class="header-hg100"></view>
		
		<view class="goodsList border-b flex-y-center box-pack-between" v-for="(item,index) of list"
			@click="choice(index)" :key='index'>
			
			<view>
				<view class="ft28" style="padding-bottom: 10rpx;">用户id:{{item.user_id}}</view>
				<view v-if="item.nickname" class="ft28 flex-y-center" style="padding-bottom: 10rpx;">
					<image style="width: 40rpx;height: 40rpx;margin-right: 10rpx;border-radius: 100px;" :src="item.avatar"></image>
					<text>{{item.nickname}}</text> 
			   </view>
				<view v-if="item.mobile" class="ft28">手机:{{item.mobile}}</view>
			</view>

			<view class="rund flex-center">
				<block v-if="item.checked">
					<icon type="success_no_circle" size="13"></icon>
				</block>
			</view>
		</view>

		<view class="pof flex-center">
			<button type="default" @click="choiceBtn">选择({{goodStudentTypelength}})</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				keywords: "",
				list: [],
				admin_id: '',
				goodStudentType: [],
				goodStudentTypelength: 0
			}
		},

		onLoad(e) {
			this.admin_id = uni.getStorageSync("admin_id");
			this.getData(1);
		},

		onReachBottom() {
			if (!this.is_bottom) {
				this.getData(this.page + 1)
			}
		},

		methods: {

			choice(index) {
				this.list[index].checked = !this.list[index].checked;
				this.goodStudentType = this.list.filter((v, i) => v.checked == true);
				this.goodStudentTypelength = this.goodStudentType.length;
			},
			
			choiceBtn(){
				uni.setStorageSync("goodStudentType",this.goodStudentType);
				uni.navigateBack();
			},

			getSearch(e) {
				if (!e.detail.value) {
					this.list = [];
					this.keywords = "";
					this.getData(1);
				}
				this.keywords = e.detail.value;
			},

			onDel() {
				this.seTval = '';
				this.list = [];
				this.keywords = "";
				this.getData(1);
			},
			
			confirm(e) {
				this.list = [];
				this.keywords = e.detail.value;
				this.getData(1);
			},
			
			search(e) {
				this.list = [];
				this.getData(1);
			},
			
			getData(page) {
				if (page == 1) {
					this.list = []
					this.page = 1
					this.is_bottom = false
				}
				this.request({
					url: 'Smdcshop/coupon_user_id',
					data: {
						admin_id: this.admin_id,
						page,
						keyword: this.keywords,
						limit: 20,
					}
				}).then(res => {
					if (res.code == 200 && res.data.length) {
						for (let i of res.data) {
							i.checked = false;
						}
						this.list = this.list.concat(res.data)
						this.page = page;
						this.goodStudentType=[];
						this.goodStudentTypelength=0;
					} else {
						this.is_bottom = true
					}
				})
			}

		}
	}
</script>

<style>
	page {
		background: #F9F9F9;
	}

	.pof {
		position: fixed;
		bottom: 20px;
		width: 100%;
	}

	.pof button {
		width: 60%;
		background-color: #007AFF;
		font-size: 28rpx;
		text-align: center;
		color: #FFFFFF;
		height: 80rpx;

	}

	.goodsList {
		padding: 20rpx;
	}

	.rund {
		width: 45rpx;
		height: 45rpx;
		border: 1px solid #ccc;
		margin-right: 20rpx;
	}


	.search-user {
		z-index: 999;
		position: fixed;
		left: 0;
		width: 100%;
		height: 100rpx;
		background: #FFFFFF;
		margin-left: 15rpx;
	}

	.search-user .search-content {
		width: 83%;
		height: 70rpx;
		background: #F1F1F1;
		border-radius: 100rpx;
		padding: 0 20rpx;

	}

	.search-user .search-content icon {
		margin-right: 10rpx;
	}

	.search-user .search-btn {
		margin-left: 20rpx;
		font-size: 28rpx;
	}

	.header-hg100 {
		height: 100rpx;
	}
</style>
