<template>
	<!-- 个人资料 -->
	<view class="Userinformation">
		<view class="list">
			<view class="sm-list">
				<text>姓名</text>
				<text>{{stu_name}}</text>
			</view>
			<view class="sm-list">
				<text>性别</text>
				<text>{{gender}}</text>
			</view>
			<view class="sm-list">
				<text>学号</text>
				<text>{{stu_no}}</text>
			</view>
			<view class="sm-list">
				<text>身份证号</text>
				<text>{{sfzh}}</text>
			</view>
			<view class="sm-list">
				<text>手机号</text>
				<text>{{sjh}}</text>
			</view>
			<view class="sm-list">
				<text>专业</text>
				<text>{{zy}}</text>
			</view>
			<view class="sm-list">
				<text>宿舍</text>
				<text>{{room}}</text>
			</view>
			<view class="sm-list">
				<text>密码</text>
				<view @click="doResetPwd" class="password">
					<text>**********</text>
					<u-icon name="edit-pen" color="#494949" size="28"></u-icon>
				</view>
			</view>
		</view>
		<!-- <button @click="toGo" style="margin-top: 2rem;">继续流程</button> -->

		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose" mode="input" title="重置密码" :value="reset_pwd" placeholder="请输入新密码"
				@confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>
		<u-toast ref="uToast"></u-toast>
		<FloatBall />
	</view>
</template>

<script>
	import middleware from "@/middleware/index.js";
	import {
		getUserInfo,
		changePwd
	} from "@/api/validApi.js";
	import {
		isEmpty
	} from "@/api/helpFunc.js";
	import {
		getOwnRoomInfo
	} from "@/api/dormApi.js";
	import FloatBall from "@/pages/compoents/FloatBall.vue";
	export default {
		components: {
			FloatBall
		},
		data() {
			return {
				reset_pwd: "",
				stu_name: "",
				gender: "",
				stu_no: "",
				sfzh: "",
				sjh: "",
				zy: "",
				room: "暂无",
			}
		},
		async created() {
			await middleware()
			this.getOwnInfo()
		},
		methods: {
			toGo() {
				uni.redirectTo({
					url: "/pages/newindex/newindex"
				})
			},
			async dialogInputConfirm(val) {
				if (val.length < 6) {
					this.$refs.uToast.show({
						type: "error",
						message: "密码长度不能小于6位",
						duration: 1500,
					})
				} else {
					let sdata = {
						pwd: val
					}
					let res = await changePwd(sdata);
					if (res.code == 200) {
						this.$refs.uToast.show({
							type: "success",
							message: res.msg,
							duration: 1500,
							complete: () => {
								uni.navigateTo({
									url: "/pages/login/index"
								})
							}
						})
					} else {
						this.$refs.uToast.show({
							type: "error",
							message: res.msg,
							duration: 1500,
						})
					}
				}
			},

			doResetPwd() {
				this.$refs.inputDialog.open()
			},
			async getOwnInfo() {
				let res = await getUserInfo();
				if (res.code == 200) {
					let data = {
						...res.data
					};
					console.log(res.data);
					if (!isEmpty(data.xsxm)) {
						this.stu_name = data.xsxm;
						this.stu_no = data.xh;
						this.gender = data.xb;
						this.sfzh = data.sfzh;
						this.sjh = data.sjh;
						this.zy = data.zy;
					}
				}
				let res2 = await getOwnRoomInfo();
				if (res2.code == 200) {
					let data = res2.data;
					if (!isEmpty(data.BuildingName)) {
						let park = data.ParkName == "default" ? "" : data.ParkName + "-";
						let building = data.BuildingName == "default" ? "" : data.BuildingName + "-";
						this.room = park + building + data.UnitName + "-" + data.RoomNo;
					}
				}

			},
		}
	}
</script>

<style lang="less" scoped>
	.Userinformation {
		margin-bottom: 10rpx;

		.list {

			display: flex;
			align-items: center;
			flex-direction: column;
			width: 100%;



			.sm-list {
				display: flex;
				justify-content: space-between;
				align-items: center;

				margin-top: 10px;
				width: 722rpx;
				height: 60rpx;
				border-bottom: 1px solid #EFEFEF;

				text:nth-child(1) {
					margin-top: 10px;
					color: #0F0F0F;
				}

				text:nth-child(2) {
					margin-top: 10px;
					color: #575757;
				}

				.password {
					display: flex;
					align-items: center;
					justify-content: flex-end;
					width: 200rpx;
				}
			}
		}
	}
</style>