<template>
	<view class="content">
		<view class="search">
			<u-search placeholder="请输入信息搜索会员" v-model="name" @custom="getData" @change="getData"></u-search>
		</view>

		<view class="card" v-for="(item,index) in dataList" :key="index">
			<view class="row">
				<view class="row half">
					<view class="name">
						昵称
					</view>
					<view class="text">
						{{item.nickname}}
					</view>
				</view>
				<view class="row half">
					<view class="name">
						手机号
					</view>
					<view class="text">
						{{item.mobile}}
					</view>
				</view>
			</view>
			<view class="row">
				<view class="row half">
					<view class="name">
						会员等级
					</view>
					<view class="text">
						{{item.level_text}}
					</view>
				</view>
				<view class="row half" @click="eidt(item.id)">
					<view class="btn">
						编辑
					</view>
				</view>
			</view>
		</view>


		<!-- 会员等级选择 -->
		<u-picker mode="selector" v-model="show" :range="level" range-key="cateName" title="设置会员等级" @confirm="set" @cancel="cancel"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				level: [{
						cateName: '普通会员',
						id: 0
					},
					{
						cateName: '黄金会员',
						id: 1
					},
					{
						cateName: '铂金会员',
						id: 10
					},
					{
						cateName: '钻石会员',
						id: 20
					},
				],
				dataList:[],
				name:"",
				userId:'',
			}
		},
		onLoad(){
			this.getData()
		},
		methods: {
			// 设置会员等级
			set(e){
				console.log(e,1111)
				let level = 0;
				if(e[0]=== 0){
					level = 0;
				}
				if(e[0]=== 1){
					level = 1;
				}
				if(e[0]=== 2){
					level = 10;
				}
				if(e[0]=== 3){
					level = 20;
				}
				this.request("/admin_user/setLevel",{user_id:this.userId,level:level},"GET").then(res=>{
					console.log(res)
					if(res.code === 1){
						this.$u.toast('操作成功')
						this.getData()
					}else{
						this.$u.toast(res.msg)
					}
				})
			},
			// 取消设置会员等级
			cancel(){
				this.userId = ""
			},
			// 获取数据列表
			getData(){
				this.request("/admin_user/list",{keyword:this.name},"GET").then(res=>{
					if(res.code === 1){
						this.dataList = res.data.data
					}
				})
			},
			// 点击编辑
			eidt(id) {
				this.show = true
				this .userId = id;
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding-top: 120rpx;
	}

	.search {
		padding: 30rpx;
		background-color: #FFFFFF;
		position: fixed;
		top: 0;
		width: 100vw;
	}

	.card {
		background-color: #FFFFFF;
		width: 93%;
		margin: 0 auto;
		margin-top: 40rpx;
		padding: 30rpx;
		border-radius: 30rpx;
		height: 150rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-between;

		.half {
			width: 50%;
			justify-content: flex-start;

			.name {
				color: #999;
			}

			.text {
				text-indent: 1em;
			}

			.btn {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: flex-end;
			}
		}
	}
</style>
