<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="请输入昵称或手机号" />
				<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 style="height: 100rpx;"></view>
		<view class="list">
			<view class="item" style="border: none;" @click="back(item)" v-for="(item,index) in list" :key="index">
				<view class="box-pack-between">
					<view class="name box-pack-between flex-grow-1">
						<text>id:{{item.id}}</text>
						<text><block v-if="item.mobile">({{item.type==1?'微信':'支付宝'}}{{item.mobile}})</block> {{item.level_name||'未知'}}   </text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				is_bottom: false,
				keywords: '',
				admin_id: '',
			}
		},

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

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

		methods: {
			getSearch(e) {
				if (!e.detail.value) {
					this.page = 1;
					this.list = [];
					this.keywords = "";
					this.getData(1);
				}
				this.keywords = e.detail.value;
			},
			back(item) {
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				prevPage.$vm.user_id = item.id; //修改上一页data里面的sh参数值为100
				prevPage.$vm.user_name = item.level_name;
				uni.navigateBack({
					delta: 1
				})
			},

			onDel() {
				this.seTval = '';
				this.page = 1;
				this.list = [];
				this.keywords = "";
				this.getData(1);
			},

			confirm(e) {
				this.page = 1;
				this.list = [];
				this.keywords = e.detail.value;
				this.getData(1);
			},

			search(e) {
				this.page = 1;
				this.list = [];
				this.getData(1);
			},
			getData(page) {
				if (page == 1) {
					this.list = []
					this.page = 1
					this.is_bottom = false
				}
				this.request({
					url: 'smdcshop/user_list',
					data: {
						level_name: "",
						limit: 40,
						page,
						type: 0,
						serch: this.keywords,
						admin_id: this.admin_id,
					}
				}).then(res => {
					if (res.code == 200 && res.data.length) {
						this.list = this.list.concat(res.data)
						this.page = page
					} else {
						this.is_bottom = true
					}
				})
			}
		}
	}
</script>

<style>
	.item {
		padding: 20rpx;
		border-bottom: 1rpx solid #1f1f1f;
	}

	.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;
	}
</style>
