<template>
	<view class="content">
		<view class="container">
			<headers :titles="titles"><u-icon name="arrow-left" color="#fff" size="22"></u-icon></headers>
			<view class="bai-box">
				<view class="top-hang">会员信息</view>
				<view class="h-box">
					<view class="">会员姓名</view>
					<view class="r-input">
						<input type="text" v-model="dataForm.name" placeholder="请输入" />
					</view>

				</view>
				<view class="h-box">
					<view class="">手机号码</view>
					<view class="r-input">
						<input type="text" v-model="dataForm.mobile" placeholder="请输入" />
					</view>

				</view>
				<!-- 				<view class="h-box">
					<view class="">支付密码</view>
					<view class="r-input">
						<input type="text" placeholder="请输入" />
					</view>
				</view> -->
				<view class="h-box">
					<view class="">性别</view>
					<view class="d-s" @click="showXingbie = true">
						<view class="">{{sex}}</view>
						<u-icon name="arrow-right" color="#2979ff" size="18"></u-icon>
					</view>
				</view>
				<view class="h-box">
					<view class="">生日</view>
					<view class="d-s" @click="showTime= true">
						<view class="">{{dataForm.birthday?dataForm.birthday:"请选择"}}</view>
						<u-icon name="arrow-right" color="#2979ff" size="18"></u-icon>
					</view>
				</view>
				<view class="h-box">
					<view class="">会员等级</view>
					<view class="d-s" @click="showGrade = true">
						<view class="">{{gradeName}}</view>
						<u-icon name="arrow-right" color="#2979ff" size="18"></u-icon>
					</view>
				</view>
				<view class="h-box">
					<view class="">备注</view>
					<view class="r-input">
						<input type="text" v-model="dataForm.description" placeholder="请输入" />
					</view>
				</view>
			</view>

			<u-picker :show="showXingbie" :columns="xingbieList" keyName="name" @cancel="showXingbie = false"
				@confirm="chooseXingbie"></u-picker>

			<u-datetime-picker :show="showTime" v-model="dataForm.birthday" mode="date" @cancel="showTime = false"
				@confirm="chooseTime"></u-datetime-picker>

			<u-picker :show="showGrade" :columns="gradeList" keyName="name" @cancel="showGrade = false"
				@confirm="chooseGrade"></u-picker>



			<view class="p-bottom">
				<view class="anniu" @click="goback()">
					保存
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from "../../utils/request";
	import headers from '../../components/header/headers.vue'

	export default {
		data() {
			return {
				titles: "新增会员",
				showGrade: false,
				showXingbie: false,
				showTime: false,
				gradeList: [],
				xingbieList: [
					[{
						id: 1,
						name: "男"
					}, {
						id: 0,
						name: "女"
					}]
				],
				form: {},
				value1: '',
				sex: '请选择',
				gradeName: '请选择',

				dataForm: {
					address: "",
					birthday: "",
					cardBalance: 0,
					description: "",
					endTime: "",
					gradeId: "",
					id: "",
					idcard: "",
					literCard: "0",
					mobile: "",
					name: "",
					official: "",
					points: 0,
					refuelMoney: "0",
					sex: 1,
					startTime: "",
					status: "qy",
					userNo: ""
				}
			}
		},
		onShow() {
			this.getGradeList()
		},
		onPullDownRefresh() {
			console.log("刷新");
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			// this.show = true
			setTimeout(() => {
				console.log("加载执行");
			}, 2000)
		},
		components: {
			headers
		},
		methods: {
			// 获取等级接口
			getGradeList() {
				request({
					url: 'business/userManager/userGrade/list',
					method: 'get',
					params: this.form
				}).then((res) => {
					if (res.data) {
						this.gradeList = []
						this.gradeList.push(res.data.records)
						console.log(res.data.records)
					} else {
						uni.showToast({
							title: res.data,
							icon: "none"
						})
					}
				})
			},
			chooseGrade(e) {
				console.log(123123, e.value[0])
				const data = e.value[0]

				this.showGrade = false
				this.dataForm.gradeId = data.id
				this.gradeName = data.name
			},

			chooseXingbie(e) {
				console.log(123123, e.value[0])
				const data = e.value[0]
				this.showXingbie = false
				this.dataForm.sex = data.id
				this.sex = data.name
			},
			chooseTime(e) {
				console.log(123123, e)
				this.showTime = false
			},

			goback() {
				request({
					url: 'business/userManager/user',
					method: 'post',
					data: this.dataForm
				}).then((res) => {
					if (res.code == 200) {
						uni.showToast({
							title: '添加成功！',
							icon: "none"
						})
						uni.navigateBack()
					} else {
						uni.showToast({
							title: '添加失败，请重试',
							icon: "none"
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #F8F8F8;
		// background: linear-gradient(180deg, #B2D2FC 0%, #B2D2FC 14%, rgba(255, 255, 255, 0.84) 24%, rgba(255, 255, 255, 0.84) 100%);
		height: 100vh;
	}

	.container {
		width: 100%;
		background: #F8F8F8;
		box-sizing: border-box;
		padding-top: 88px;
	}

	.img-box {
		image {
			width: 100%;
			height: 100%;
		}
	}

	.p-bottom {
		width: 100%;
		height: 68px;
		background: #fff;
		position: fixed;
		bottom: 0px;
		left: 0px;
	}

	.anniu {
		height: 40px;
		background: #0864E9;
		width: 80%;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		border-radius: 50px;
		margin: 5px auto;
	}

	.bai-box {
		width: 95%;
		margin: 15px auto;
		box-sizing: border-box;
		padding: 15px;
		background: #fff;
	}

	.top-hang {
		font-weight: bold;
		font-size: 16px;
		color: #0864E9;
		box-sizing: border-box;
		padding-bottom: 10px;
		border-bottom: 1px solid #F0F0F0;

	}

	.h-box {
		border-bottom: 1px solid #F0F0F0;
		box-sizing: border-box;
		padding: 10px 0px;
		font-size: 14px;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.d-s {
		display: flex;
		align-items: center;
		color: #0864E9;
	}

	.r-input {
		text-align: right;
	}
</style>