<template>
	<mobile-frame>
		<view class="info">
			<view class="one">
				<uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
					<uni-forms-item label="头像" name="logo">
						<upload :list="logo" name="logo" :count="1" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
					</uni-forms-item>
					<uni-forms-item label="真实姓名" name="name">
						<uni-easyinput type="text" v-model="form.name" placeholder="请输入真实姓名" />
					</uni-forms-item>
					<uni-forms-item label="性别" name="gender">
						<picker @change="genderChange" name="gender" :value="form.gender" :range="genderList"
							range-key="label">
							<view class="uni-input">{{form.zhGender||'请选择性别'}}</view>
						</picker>
					</uni-forms-item>
					<uni-forms-item label="生日" name="date">
						<picker mode="date" :value="form.date" name="date" :start="startDate" :end="endDate"
							@change="bindDateChange">
							<view class="uni-input">{{form.date||'请选择日期'}}</view>
						</picker>
					</uni-forms-item>
					<uni-forms-item label="QQ号" name="QQ">
						<uni-easyinput type="text" v-model="form.qq" placeholder="请输入QQ号" />
					</uni-forms-item>
					<uni-forms-item label="昵称" name="Nname">
						<uni-easyinput type="text" v-model="form.Nname" placeholder="请输入昵称" />
					</uni-forms-item>
				</uni-forms>
				<view class="btn">
					<button type="primary" @click="onSubmit('form')" size="small">提交</button>
					<view class="name">提示：为了您的账户安全，建议定期修改密码</view>
				</view>
			</view>
		</view>

	</mobile-frame>
</template>

<script>
	import upload from '@/components/upload/index.vue';
	export default {
		components: {
			upload
		},
		data() {
			return {
				frameStyle: {
					useBar: false
				},
				form: {},
				rules: {
					name: {
						rules: [{
							required: true,
							errorMessage: '请输入真实姓名',
						}]
					},
					num: {
						rules: [{
							required: true,
							errorMessage: '请输入邮箱验证码',
						}]
					},
				},
				genderList: [{
						label: '保密',
						value: '0'
					},
					{
						label: '男',
						value: '1'
					},
					{
						label: '女',
						value: '2'
					},
				],
				logo: []
			};
		},
		onLoad: function(e) {

		},
		onShow: function() {},
		methods: {
			toPath(e) {
				if (e && e.route) uni.redirectTo({
					url: `/${e.route}`
				})
			},
			// 图片上传
			uplSuc(e) {
				const that = this;
				console.log(e);
				that.$set(that, `${e.name}`, [...that[e.name], e.data]);
			},
			// 图片删除
			uplDel(e) {
				const that = this;
				console.log(e);
				let data = that[e.name];
				let arr = data.filter((i, index) => index != e.data.index);
				that.$set(that, `${e.name}`, arr)
			},
			// 选择性别
			genderChange(e) {
				const that = this;
				let data = that.genderList[e.detail.value];
				if (data) {
					that.$set(that.form, `gender`, data.value);
					that.$set(that.form, `zhGender`, data.label);
				}
			},
			// 选择日期
			bindDateChange(e) {
				// this.date = e.detail.value
				const that = this;
				that.$set(that.form, `date`, e.detail.value);
			},
			// 提交保存
			onSubmit() {
				const that = this;
				let data = that.form;
				data.logo = that.logo;
				console.log(data);
				// this.$refs.form.validate().then(async (res) => {
				// let arr;
				// if (data._id) {
				// 	arr = await that.$api(``, 'POST', data)
				// } else {
				// 	arr = await that.$api(``, 'POST', data)
				// }
				// if (arr.errcode == '0') {
				// 	uni.showToast({
				// 		title: `维护信息成功`,
				// 		icon: 'success',
				// 		duration: 2000
				// 	});
				// 	that.back()
				// } else {
				// 	uni.showToast({
				// 		title: arr.errmsg,
				// 		icon: 'error',
				// 		duration: 2000
				// 	})
				// }
				// })
			},
		}
	}
</script>

<style lang="scss">
	.info {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;

		.one {
			padding: 2vw;

			.uni-input {
				border: #f1f1ff 1px solid;
				padding: 2vw 2vw;
				border-radius: 1vw;
			}

			.btn {
				text-align: center;

				button {
					margin: 0 2vw 2vw 2vw;
					background-color: var(--ff0Color);
					color: var(--fffColor);
				}

				.name {
					color: var(--f85Color);
					font-size: var(--font14Size);
				}
			}
		}
	}

	.uni-forms-item {
		margin-bottom: 6vw !important;
		display: flex;
		flex-direction: row;
	}
</style>
