<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>报名</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/mui.picker.min.css" />
		<style>
			.mui-table-view {
				margin-top: 10px;
			}
			
			.span3 {
				color: #0193DF;
				margin: 10px;
				line-height: 38px;
			}
			
			.span2 {
				color: #c70f1a;
				font-size: 13px;
				line-height: 24px;
			}
			
			.mui-ellipsis {
				line-height: 30px;
			}
			
			.mui-content-padded {
				margin-top: 10px;
				text-align: center;
			}
			
			.mui-content {
				background-color: #FFFFFF;
			}
			
			.mui-btn-blue {
				background-color: #0193df;
				border: #0193DF;
				margin-top: 25px;
			}
			
			.mui-input-row {
				border-bottom: 1px #EEEEEE solid;
			}
			
			.mui-input-row .mui-btn {
				width: 65%;
				border: 1px #000000 solid;
				border: none;
				float: left;
			}
			
			.dj {
				font-size: 14px;
				color: #999999;
				padding: 10px;
			}
			
			.mui-btn-block {
				width: 65%;
				float: right;
				margin: 0px;
				height: 40px;
			}
			
			#info {
				float: left;
				margin: 0px;
			}
			
			#schooltext,
			#culturetext,
			#departtext {
				line-height: 40px;
				text-overflow: ellipsis;
				overflow: hidden;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">修改专业</h1>
		</header>
		<div class="mui-content">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell mui-media">
					<a>
						<div class="mui-media-body">
							<div class="mui-input-row">
								<label>姓&nbsp;&nbsp;&nbsp;名</label>
								<input id='username' type="text" class="mui-input-clear mui-input" readonly="readonly">
							</div>
							<div class="mui-input-row" id="selculture">
								<label>文化程度</label>
								<input type="hidden" id="cultureid" />
								<span id="culturetext">请选择</span><span class="mui-pull-right mui-navigate-right"></span>
							</div>
							<div class="mui-input-row" id="selschool">
								<label>报考校区</label>
								<input type="hidden" id="schoolid" />
								<span id="schooltext">请选择</span><span class="mui-pull-right mui-navigate-right"></span>
							</div>
							<div class="mui-input-row" id="seldepart">
								<label>报考专业</label>
								<input type="hidden" id="departid" />
								<span id="departtext">请选择</span><span class="mui-pull-right mui-navigate-right" id="sex"></span>
							</div>
						</div>
						<div class="mui-content-padded">
							<button type="button" class="mui-btn mui-btn-danger" id="reg">确认修改</button>
						</div>
					</a>
				</li>
			</ul>
		</div>
		<script src="js/mui.min.js "></script>
		<script src="js/serverurl.js"></script>
		<script src="js/tools.js"></script>
		<script src="js/userinfos.js"></script>
		<script src="js/mui.picker.min.js"></script>
		<script type="text/javascript">
			var userPickerculture, userPickerschool, userPickerdepart;

			function RefreshUserInfo() {
				mui.post(api + '/user/getStuByUserId', {
					data: users.ID
				}, function(des) {
					if (des.code == "200") {
						SetLogin(des.data)
						plus.nativeUI.toast("修改成功。");
						plus.webview.currentWebview().close();
						plus.webview.getWebviewById("apply.html").evalJS("RefreshBaoming();");
						plus.webview.getWebviewById("interact.html").evalJS("RefreshContactTeacher();");
					}
				}, 'json')
			}

			function OpenAndSetPicker(picker, field) {
				picker.show(function(items) {
					if (items[0].value != undefined && items[0].value != null && items[0].value != '') {
						document.getElementById(field + "text").innerText = items[0].text;
						document.getElementById(field + "id").value = items[0].value;
						if (field == "school") {
							var whcdid = document.getElementById("cultureid").value;
							if (whcdid == "") {
								plus.nativeUI.toast("请选择文化程度。");
								return;
							}
							GetDepartData(userPickerdepart, "" + items[0].value + "", "" + whcdid + "");
							document.getElementById("departid").value = "";
							document.getElementById("departtext").innerText = "";
						}
						if (field == "culture") {
							var whcdid = document.getElementById("cultureid").value;
							if (whcdid == "") {
								plus.nativeUI.toast("请选择文化程度。");
								return;
							}
							var xqid = document.getElementById("schoolid").value;
							if (xqid == "") {
								plus.nativeUI.toast("请选择校区。");
								return;
							}
							GetDepartData(userPickerdepart, "" + xqid + "", "" + whcdid + "");
							document.getElementById("schoolid").value = "";
							document.getElementById("schooltext").innerText = "";
							document.getElementById("departid").value = "";
							document.getElementById("departtext").innerText = "";
						}
					} else {
						plus.nativeUI.toast("当前校区暂无对应专业。");
						return false;
					}
				});
			}
			mui.plusReady(function() {
				
				CheckLogin();
				userPickerculture = new mui.PopPicker();
				userPickerschool = new mui.PopPicker();
				userPickerdepart = new mui.PopPicker();
				document.getElementById("selculture").addEventListener("tap", function() {
					OpenAndSetPicker(userPickerculture, "culture");
				});
				document.getElementById("selschool").addEventListener("tap", function() {
					OpenAndSetPicker(userPickerschool, "school");
				});
				document.getElementById("seldepart").addEventListener("tap", function() {
					OpenAndSetPicker(userPickerdepart, "depart");
				});
				document.getElementById("username").value = users.username;
				document.getElementById("cultureid").value = users.culture;
				document.getElementById("culturetext").innerText = users.culturename;
				document.getElementById("schoolid").value = users.school;
				document.getElementById("schooltext").innerText = users.schoolname;
				document.getElementById("departid").value = users.depart;
				document.getElementById("departtext").innerText = users.departname;
				GetDictionaryDataBySource(userPickerculture, "DegreeOfEducation"); //文化程度
				GetSchoolData(userPickerschool);
				GetDepartData(userPickerdepart, "" + users.school + "", "" + users.culture + "");
				document.getElementById("reg").addEventListener("tap", function() {
					if (users.ID != undefined && users.ID != null) {
						if (document.getElementById("cultureid").value == "" || document.getElementById("schoolid").value == "" ||
							document.getElementById("departid").value == "") {
							plus.nativeUI.toast("请填写完整表单!"); //
							return;
						}

						plus.nativeUI.showWaiting("加载中...");
						var param = {
							school: document.getElementById("schoolid").value,
							depart: document.getElementById("departid").value,
							culture: document.getElementById("cultureid").value,
							id: users.ID
						}

						mui.post(api + '/user/updateStuByStuTerminal', {
							data: JSON.stringify(param)
						}, function(res) {
							plus.nativeUI.closeWaiting();
							if (res.code == "200") {
								RefreshUserInfo()
								}
						}, 'json')
					}
				});
			});
		</script>
	</body>

</html>