<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
		<title>资料修改-会员中心-<?php echo $cfg_webname;?></title>
		<link rel="stylesheet" href="<?php echo $cfg_cmsurl;?>/static/web/font/css/font-awesome.min.css">
		<link rel="stylesheet" href="<?php echo $cfg_cmsurl;?>/static/web/css/bootstrap.min.css">
		<link rel="stylesheet" href="<?php echo $cfg_cmsurl;?>/static/web/css/style.css">
		<script src="<?php echo $cfg_cmsurl;?>/static/web/js/jquery.min.js"></script>
	</head>
	<body class="body-bg">
		<?php pasterTempletDiy('top.htm');?>
		<main class="container py-3">
			<div class="row">
				<?php
				$_menu_edtex = true;
				$_menu_edtitem = 'base';
				?>
				<?php include(DEDEMEMBER."/templets/menu.htm");?>
				<div class="col-md-9">
					<div class="pannel-main-container shadow-sm rounded">
						<form action="edit_baseinfo.php" method="post" enctype="multipart/form-data" name="form2" onsubmit="return checkSubmit();">
							<input type="hidden" name="_csrf_token" value="<?php echo $GLOBALS['csrf_token'];?>">
							<input type="hidden" name="dopost" value="save">
							<input type="hidden" id="newface" name="newface" value="">
							<div class="form-group row">
								<div class="col-sm-12">
									<div class="alert alert-info mb-0">会员资料修改需要验证密码才能修改</div>
								</div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label">会员名：</label>
								<div class="col-sm-9 input-text"><?php echo $cfg_ml->M_LoginID;?></div>
							</div>
							<div class="form-group row">
								<label for="iptUname" class="col-sm-3 col-form-label">昵称：</label>
								<div class="col-sm-9"><input type="text" name="uname" class="form-control w-75" id="iptUname" value="<?php echo $row['uname'];?>" placeholder="企业会员为公司名，个人会员为昵称"></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label">头像：</label>
								<div class="col-sm-9">
									<input id="iptNewface" type="file" name="iptNewface" class="d-none">
									<img id="face" src="<?php echo empty($row['face'])? $cfg_staticurl.'/web/img/admin.png' : $row['face'];?>" class="user-img-sm mr-3">
									<span class="btn btn-success btn-sm" id="btnChangeFace">修改</span>
								</div>
							</div>
							<div class="form-group row">
								<label for="iptOldpwd" class="col-sm-3 col-form-label">密码：</label>
								<div class="col-sm-9"><input type="password" name="oldpwd" id="iptOldpwd" class="form-control w-75" placeholder="请输入密码"></div>
							</div>
							<div class="form-group row">
								<label for="iptUserpwd" class="col-sm-3 col-form-label">新密码：</label>
								<div class="col-sm-9"><input type="password" name="userpwd" id="iptUserpwd"	class="form-control w-75" placeholder="不修改密码请保留此项为空"></div>
							</div>
							<div class="form-group row">
								<label for="iptUserpwdok" class="col-sm-3 col-form-label">确认新密码：</label>
								<div class="col-sm-9"><input type="password" name="userpwdok" id="iptUserpwdok"	class="form-control w-75" placeholder="不修改密码请保留此项为空"></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label">原安全问题：</label>
								<div class="col-sm-9"><?php echo GetSafequestion($row['safequestion'],'safequestion');?></div>
							</div>
							<div class="form-group row">
								<label for="iptSafeanswer" class="col-sm-3 col-form-label">原问题答案：</label>
								<div class="col-sm-9"><input type="text" name="safeanswer" id="iptSafeanswer" class="form-control"></div>
							</div>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label">新安全问题：</label>
								<div class="col-sm-9"><?php echo GetSafequestion(0,'newsafequestion');?></div>
							</div>
							<div class="form-group row">
								<label for="iptNewsafeanswer" class="col-sm-3 col-form-label">新问题答案：</label>
								<div class="col-sm-9"><input type="text" name="newsafeanswer" id="iptNewsafeanswer" class="form-control"></div>
							</div>
							<div class="form-group row">
								<label for="iptEmail" class="col-sm-3 col-form-label">邮箱：</label>
								<div class="col-sm-9">
									<div id="spEmail">
										<span class="input-text"><?php echo HideEmail($row['email']);?></span>
										<span class="btn btn-success btn-sm ml-3" id="btnChangeEmail">修改</span>
									</div>
									<span id="iptEmail"></span>
								</div>
							</div>
							<div class="form-group row">
								<label for="iptEmail" class="col-sm-3 col-form-label">性别：</label>
								<div class="col-sm-9 input-text">
									<label><input type="radio" name="sex" value="男" <?php if ($row['sex']=='男') echo " checked='checked' " ;?>> 男</label>
									<label><input type="radio" name="sex" value="女" <?php if ($row['sex']=='女') echo " checked='checked' " ;?>> 女</label>
									<label><input type="radio" name="sex" value="保密" <?php if ($row['sex']=='保密') echo " checked='checked' " ;?>> 保密</label>
								</div>
							</div>
							<div class="text-center"><button type="submit" class="btn btn-success btn-sm">保存</button></div>
						</form>
					</div>
				</div>
			</div>
		</main>
		<?php pasterTempletDiy('foot.htm');?>
		<script>
			function checkSubmit() {
				if (document.form2.oldpwd.value == '') {
					document.form2.oldpwd.focus();
					ShowMsg("请您填写密码");
					return false;
				}
				if (document.form2.userpwdok.value != document.form2.userpwd.value) {
					document.form2.userpwdok.focus();
					ShowMsg("两次密码不一致");
					return false;
				}
				if (document.form2.email.value == "") {
					document.form2.email.focus();
					ShowMsg("请您填写邮箱");
					return false;
				}
				if (document.form2.uname.value == "") {
					document.form2.uname.focus();
					ShowMsg("请您填写昵称");
					return false;
				}
			}
		</script>
		<script>
			$(document).ready(function () {
				$("#btnChangeEmail").click(function () {
					if ($("#iptOldpwd").val() === "") {
						ShowMsg("请您填写密码");
						return false;
					}
					$.post("<?php echo $cfg_cmsurl;?>/user/api.php?action=get_old_email", { oldpwd: $("#iptOldpwd").val() }, function (result) {
						if (result.code === 0) {
							$("#spEmail").hide();
							$("#iptEmail").html(`<input value="${result.data.email}" type="email" name="email" id="iptEmail" class="form-control">`);
							$("#iptEmail").show();
						} else {
							ShowMsg(result.msg);
						}
					});
				})
				$("#btnChangeFace").click(function () {
					$("#iptNewface").click();
				})
				$("#iptNewface").change(function (val) {
					var formData = new FormData();
					var fileData = $('#iptNewface')[0].files[0];
					formData.append('file', fileData);
					$.ajax({
						url: '<?php echo $cfg_cmsurl;?>/user/api.php?action=upload&type=face',
						type: 'POST',
						data: formData,
						processData: false,
						contentType: false,
						success: function (result) {
							if (result.code === 0) {
								$("#face").attr('src', result.data);
								$("#newface").val(result.data);
							} else {
								ShowMsg(result.msg);
							}
						},
						error: function (xhr, status, error) {
							alert(error); //处理上传失败后的回调
						}
					});
				});
			});
		</script>
	</body>
</html>