<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">

<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width,initial-scale=1,user-scalable=0">
<title>编辑用户信息</title>
<!-- 引入 WeUI -->
<link rel="stylesheet"
	href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui.min.css" />
<link rel="stylesheet"
	href="https://cdn.bootcss.com/jquery-weui/1.2.0/css/jquery-weui.css" />
<style type="text/css">
body, html {
	height: 100%;
	background-color: #f4f4f4;
	-webkit-tap-highlight-color: transparent;
}

.margin_top_30px {
	margin-top: 30px;
}

.basic-color {
	background-color: #1E88E5;
	color: #FFFFFF;
}

.basic-weui-btn {
	background-color: #1E88E5;
	color: #FFFFFF;
}

.basic-weui-btn:hover {
	background-color: #1E88E5;
	color: #FFFFFF;
}

.basic-weui-btn:active {
	background-color: #1E88E5 !important;
	color: #FFFFFF;
}

footer {
	text-align: center;
	font-size: 14px;
	padding: 20px;
}

.weui-loadmore_line {
	background-color: #f4f4f4;
}

footer a {
	color: #999;
	text-decoration: none;
}
</style>
</head>

<body ontouchstart="">
	<div class="weui-cells weui-cells_form margin_top_30px">
		<input class="site_user_id" type="hidden" th:attr="data=${siteUserId}">
		<div class="weui-cell">
			<div class="weui-cell__hd">
				<label class="weui-label">用户昵称</label>
			</div>
			<div class="weui-cell__bd">
				<input class="weui-input user_name" type="text" name="user_name"
					th:value="${userName}" placeholder="用户昵称" maxlength="16">
			</div>
		</div>

		<div class="weui-cell">
			<div class="weui-cell__hd">
				<label class="weui-label">站点账号</label>
			</div>
			<div class="weui-cell__bd">
				<input class="weui-input site_login_id" type="text"
					name="site_login_id" th:value="${siteLoginId}" placeholder="站点账号"
					maxlength="16">
			</div>
		</div>

		<div class="weui-cell">
			<div class="weui-cell__bd">
				<div class="weui-uploader">
					<div class="weui-uploader__hd">
						<p class="weui-uploader__title">图片上传</p>
						<div class="weui-uploader__info" th:if="${userPhoto}!=null">1/1</div>
						<div class="weui-uploader__info" th:unless="${userPhoto}!=null">0/1</div>
					</div>
					<div class="weui-uploader__bd">
						<ul class="weui-uploader__files" id="uploaderFiles">
							<li class="weui-uploader__file user_photo" id="user_photo"
								th:attr="user-photo=${userPhoto}" th:if="${userPhoto}!=null"></li>
						</ul>
						<div class="weui-uploader__input-box">
							<input id="uploaderInput"
								class="weui-uploader__input  uploaderInput" type="file"
								accept="image/*" multiple="">
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="weui-btn-area">
			<a
				class="weui-btn basic-weui-btn weui-btn_primary basic-color update_user_info"
				url-data="/user/updateProfile" href="javascript:"
				id="update_user_info">确定</a> 
				
			<a class="weui-btn basic-weui-btn weui-btn_primary basic-color site_manager"
				url-data="/user/setSiteManager" href="javascript:" id="site_manager"
				th:if="${managerState}==0" th:attr="managerState=${managerState}">设为管理员身份</a>
			<a class="weui-btn basic-weui-btn weui-btn_primary basic-color site_manager"
				url-data="/user/deleteSiteManager" href="javascript:"
				id="site_manager" th:if="${managerState}==1"
				th:attr="managerState=${managerState}">删除管理员身份</a> 
				
			<a class="weui-btn basic-weui-btn weui-btn_primary basic-color user_default"
				url-data="/user/setUserDefaultFriend" href="javascript:"
				id="user_default" th:if="${defaultState}==0"
				th:attr="defaultState=${defaultState}">设为新用户默认好友</a> <a
				class="weui-btn basic-weui-btn weui-btn_primary basic-color user_default"
				url-data="/user/deleteUserDefaultFriend" href="javascript:"
				id="user_default" th:if="${defaultState}==1"
				th:attr="defaultState=${defaultState}">取消新用户默认好友</a> 
				
				<a href="javascript:;" name='sealup-user' th:attr="data=${siteUserId},userStatus=${userStatus}"
				class="sealup-site-user weui-btn weui-btn_warn " url-data="/user/sealup" th:if="${userStatus}==0" >封禁用户</a> 
				<a href="javascript:;" name='sealup-user' th:attr="data=${siteUserId},userStatus=${userStatus}"
				class="sealup-site-user weui-btn weui-btn_warn" url-data="/user/sealup" th:if="${userStatus}==1">解封用户</a>

			<!-- 删除用户 -->
			<a class="weui-btn weui-btn_warn  delUser" url-data="/user/delUser"
				href="javascript:" id="delUser">删除用户</a>

		</div>
	</div>
	<script type="text/javascript"
		src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
	<script type="text/javascript"
		src="https://res.wx.qq.com/open/libs/weuijs/1.1.3/weui.min.js"></script>
	<script type="text/javascript"
		src="https://cdn.bootcss.com/jquery-weui/1.2.0/js/jquery-weui.js"></script>
	<script type="text/javascript">
		function getOsType() {
			var u = navigator.userAgent;
			if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1
					|| u.indexOf('Windows Phone') > -1) {
				return 'Android';
			} else if (u.indexOf('iPhone') > -1) {
				return 'IOS';
			} else {
				return 'PC';
			}
		}

		function reqUrl(reqUri, params, callbackName) {
			reqUri = "/akaxin" + reqUri;
			var type = getOsType();
			//console.log('utl' + type);

			if (type == 'Android') {
				Android.requestPost(reqUri, params, callbackName);
			} else if (type == 'IOS') {
				ios_requestPost(reqUri, params, callbackName);
			} else {
				$.toast('暂时不支持该设备');
			}
		}

		function reqHtml(reqUri, params) {
			reqUri = "/akaxin" + reqUri;
			var type = getOsType();
			if (type == 'Android') {
				Android.requestPage(reqUri, params)
			} else if (type == 'IOS') {
				ios_requestPage(reqUri, params);
			} else {
				$.toast('暂时不支持该设备');
			}
		}

		function reqImageUpload(callback) {
			var type = getOsType();
			if (type == 'Android') {
				Android.imageUpload(callback);
			} else if (type == 'IOS') {
				ios_imageUpload(callback);
			} else {
				$.toast('暂时不支持该设备');
			}
		}

		function reqImageDownload(imageid, callback) {
			var type = getOsType();
			if (type == 'Android') {
				Android.imageDownload(imageid, callback);
			} else if (type == 'IOS') {
				ios_imageDownload(imageid, callback);
			} else {
				$.toast('暂时不支持该设备');
			}
		}

		function toast(msg) {
			var type = getOsType();
			if (type == 'Android') {
				Android.showToast(msg);
			} else if (type == 'IOS') {
				$.toast(msg);
			} else {
				$.toast('暂时不支持该设备');
			}
		}

		$(document).on("click", ".sealup-site-user", function() {
			var siteUserId = $(this).attr('data');
			var url = $(this).attr('url-data');
			var userStatus = $(this).attr('userStatus');
			var confirmTitle = "确定要封禁用户？";
			var status = "1";
			if(userStatus==1){
				confirmTitle = "确认要解封用户？";
				status = "0";
			}
			
			$.confirm({
				title : confirmTitle,
				//text : confirmText,
				onOK : function() {
					var userInfo = {
						'site_user_id' : siteUserId,
						'user_status' : status
					};
					reqUrl(url, JSON.stringify(userInfo), "sealupSiteUser");
					$.closeModal();
				},
				onCancel : function() {
					toast('取消操作');
					$.closeModal();
				}
			});
		});

		function sealupSiteUser(results) {
			if (results == 'success') {
				var userStatus = $('.sealup-site-user').attr('userStatus');
				if(userStatus == 0){
					$('.sealup-site-user').attr('userStatus', '1');
                    $('.sealup-site-user').html('解封用户');
				}else if(userStatus == 1){
					$('.sealup-site-user').attr('userStatus', '0');
                    $('.sealup-site-user').html('封禁用户');
				}
				$.toast("操作成功");
			} else {
				$.toast("操作失败", "forbidden");
			}
		}


		$(document).on("click", ".update_user_info", function() {
			var userName = $('.user_name').val();
			var siteLoginId = $('.site_login_id').val();
			var siteUserId = $('.site_user_id').attr('data');
			var userPhoto = $('.user_photo').attr('user-photo');
			$('#edit_user_id').attr('user_name', userName);

			var userInfo = {
				"siteUserId" : siteUserId,
				"siteLoginId" : siteLoginId,
				"userName" : userName,
				"userPhoto" : userPhoto
			};
			var reqUri = $(this).attr('url-data');
			reqUrl(reqUri, JSON.stringify(userInfo), 'updateSiteUser');
		});

		function updateSiteUser(results) {
			if (results == 'success') {
				var userName = $('#edit_user_id').attr('user_name');
				$('.user_name').attr('value', userName);
				$.toast("操作成功");
			} else {
				$.toast("操作失败", "forbidden");
			}
		}

		$(document).on("click", ".site_manager", function() {
			var siteUserId = $('.site_user_id').attr('data');
			var userInfo = {
				"siteUserId" : siteUserId
			};
			var reqUri = $(this).attr('url-data');
			reqUrl(reqUri, JSON.stringify(userInfo), 'siteManagerResult');
		});

		function siteManagerResult(results) {
			if (results == 'success') {
				var managerStatus = $('.site_manager').attr('managerState');
				if(managerStatus==0){
					$('.site_manager').attr('managerState', '1');
                    $('.site_manager').attr('url-data', '/user/deleteSiteManager');
                    $('.site_manager').html('取消管理员身份');
				}else if(managerStatus==1){
					$('.site_manager').attr('managerState', '0');
                    $('.site_manager').attr('url-data', '/user/setSiteManager');
                    $('.site_manager').html('设为管理员身份');
				}
				$.toast("操作成功");
			} else {
				$.toast("操作失败", "forbidden");
			}
		}

		$(document).on("click", ".user_default", function() {
			var siteUserId = $('.site_user_id').attr('data');
			var userInfo = {
				"siteUserId" : siteUserId
			};
			var reqUri = $(this).attr('url-data');
			reqUrl(reqUri, JSON.stringify(userInfo), 'userDefaultResult');
		});

		function userDefaultResult(results) {
			if (results == 'success') {
				$.toast("操作成功");
				var attr = $('.user_default').attr('defaultState');
				if (attr == '0') {
					$('.user_default').attr('defaultState', '1');
					$('.user_default').attr('url-data', '/user/deleteUserDefaultFriend');
					$('.user_default').html('取消默认好友');
				} else {
					$('.user_default').attr('defaultState', '0');
					$('.user_default').attr('url-data', '/user/setUserDefaultFriend');
					$('.user_default').html('设为默认好友');
				}
			} else {
				$.toast("操作失败", "forbidden");
			}
		}

		$(document).on("click", ".delUser", function() {
			var siteUserId = $('.site_user_id').attr('data');
			var reqUri = $(this).attr('url-data');
			$.confirm({
				title : '删除用户',
				text : '删除后,用户将被从站点彻底抹除',
				onOK : function() {
					var userInfo = {
						"siteUserId" : siteUserId
					};
					reqUrl(reqUri, JSON.stringify(userInfo), 'delUserResult');
					$.closeModal();
				},
				onCancel : function() {
					console.log('cancle');
					toast('取消操作');
					$.closeModal();
				}
			});

		});

		function delUserResult(results) {
			if (results == 'success') {
				$.toast("操作成功");
			} else {
				$.toast("操作失败", "forbidden");
			}
		}

		$(document).on("click", '.uploaderInput', function() {
			reqImageUpload("jsimageUpload");
		});

		function jsimageUpload(result, imageId, imageLocalPath) {
			var type = getOsType();
			if (result == 1) {
				if (type == 'Android') {
					var img = '<li class="weui-uploader__file user_photo" user-photo="' + imageId + '"><img src="http://akaxin/img' + imageLocalPath + '" style="height:75px; width:75px;" /></li>';
				} else {
					var img = '<li class="weui-uploader__file user_photo" user-photo="' + imageId + '"><img src="' + imageLocalPath + '" style="height:75px; width:75px;" /></li>';
				}
				$('#uploaderFiles').html(img);
				$('.weui-uploader__info').html('1/1');
			} else {
				$.toast('上传图片失败', 'forbidden');
			}
		}

		$(window).load(function() {
			var imageid = $('.user_photo').attr('user-photo');
			reqImageDownload(imageid, "jsimageDownload");
		});

		function jsimageDownload(result, imageid, imageLocalPath) {
			var type = getOsType();
			if (type == 'Android') {
				var html = '<img src="http://akaxin/img' + imageLocalPath + '" style="height:75px; width:75px;" />';
			} else {
				var html = '<img src="' + imageLocalPath + '" style="height:75px; width:75px;" />';
			}
			$('#user_photo').html(html);
		}
	</script>
</body>

</html>