<template>
	<div>
		<van-nav-bar title="注册" />
		<van-form @failed="onFailed" @submit="onSubmit">
			<van-cell-group inset>
				<van-field v-model="realname" label="姓名" placeholder="请输入姓名" />
				<van-field v-model="mobile" label="手机号" placeholder="请输入手机号" />
			</van-cell-group>
			<div style="margin: 16px;">
				<van-button round block type="primary" native-type="submit">
					注册
				</van-button>
			</div>
		</van-form>
	</div>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		showNotify,
		showDialog
	} from "vant";
	import {
		setToken,
		getToken,
		removeToken,
		setUserinfo,
		getUserinfo,
		setUsername,
		getReginfo,
		setReginfo,
		getUsername,
		setOpenid,
		getOpenid
	} from "../../utils/wxtools.js";

	import {
		EditUserInfoAPI,
		EditRegAPI,
	} from '../../services/index.js';

	import {
		useRouter
	} from "vue-router";
	const router = useRouter()

	const realname = ref('');
	const mobile = ref('');

	const onSubmit = (values) => {
		console.log('openid', getOpenid());
		console.log('reginfo', getReginfo());
		console.log('realname', realname);
		console.log('mobile', mobile);
		console.log('submit', values);
		let reg = getReginfo();
		EditRegAPI({
			id: reg.id,
			mobile: mobile.value
		}).then(response => {
		  if(response.success === true){
			  // router.push("/");
			  router.push("/check");
		  }else{
			  showNotify({
			  	message: res.message,
			  	type: "danger",
			  });
		  }
		});
		// EditUserInfoAPI({
		// 	id: user.id,
		// 	realname: realname.value,
		// 	mobile: mobile.value
		// }).then(response => {
		//   if(response.success === true){
		// 	  // router.push("/");
		// 	  router.push("/check");
		//   }else{
		// 	  showNotify({
		// 	  	message: res.message,
		// 	  	type: "danger",
		// 	  });
		//   }
  //       });
		
	};
</script>

<style lang="scss">
	.textbomcenter {
		text-align: center;
		// top: 20rpx;
		left: 0;
		right: 0;
		position: static;
		bottom: 15rpx;
		text-decoration: underline;
		font-weight: 400;
		color: cornflowerblue;
	}

	.goods-box {
		display: flex;
		flex-wrap: wrap;

		// 图片列表
		.imgList {
			position: relative;
			width: 180rpx;
			height: 180rpx;
			margin: 0 50rpx 30rpx 0;
		}

		// 删除图片
		.del {
			position: absolute;
			width: 60rpx;
			height: 60rpx;
			right: 0rpx;
			z-index: 999;
		}
	}
</style>