<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>私塾家</title>
<script th:include="sys/common/metaCSS" th:remove="tag"></script> 
<script th:include="sys/common/metaJS" th:remove="tag"></script> 
<script src="sys/js/My97DatePicker/WdatePicker.js" th:src="@{/static/sys/js/My97DatePicker/WdatePicker.js}"></script>
</head>
<style>
	.tablelink{margin-right:10px;}
	.stylecss{
	      color: red;
	}
	.select_width{
	     width: 220px;
	}
	.date_width{
	     width: 83px;
	}
</style>
<body>
<div class="place">
	<span>位置：</span>
	<ul class="placeul">
		<li><a href="#">首页</a></li>
		<li><a href="#">学校地址</a></li>
	</ul>
</div>
<div class="rightinfo">
	<form id="seachform" th:action="@{/sys/problem/cnArealist.html}" method="post">
	<ul class="seachform">
	<li>
			<label>学校名字</label>
			<input name="name" type="text" class="scinput" th:value="${search.get('name')}"/>
		</li>
		<li>
			<label>区域</label>
			<select name="province" id="province" class="select_width scinput" onchange="funcprovince()">
				<option data-type="1" value="" >选择省</option>
			</select>
		</li>
		<li>
			<select name="city" id="city" class="select_width scinput" onchange="funccity()">
				<option data-type="2" value="" >选择市</option>
			</select>
		</li>
		<li>
			<select name="area" id="area" class="select_width scinput" onchange="funcarea()">
				<option data-type="3" value="" >选择区</option>
			</select>
		</li>
		<li>
			<input type="button" class="scbtn" value="查询" />
		</li>
	<li>
				<ul class="toolbar">
		<a th:href="@{/sys/problem/addcnArea.html}"><li class="click"><span><img th:src="@{/static/sys/images/t01.png}" /></span>添加</li></a>
				</ul>
		</li>
		<li>
			<ul class="toolbar"  th:onclick="'cnArea()'">
				<li class="click"><span><img th:src="@{/static/sys/images/t01.png}" /></span>导入学校地址</li>
			</ul>
		</li>
		<li>
			<ul class="toolbar"  th:onclick="'exportCnArea()'">
				<li class="click"><span><img th:src="@{/static/sys/images/t01.png}" /></span>导出学校数据</li>
			</ul>
		</li>
	</ul>
	</form>
	<table class="tablelist">
		<thead>
		    <tr>
		        <th style="width: 50px;">序号</th>
		        <th>名称</th>
		        <th>类型</th>
		        <th>首字母拼音</th>
		        <th>是否热门城市</th>
		        <th>详细地址</th>
		        <th>学校经度</th>
		        <th>学校纬度</th>
		        <th>操作</th>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="cnArealist:${list}" >
				<td th:text="${cnArealistStat.count}" ></td>
				<td th:text="${cnArealist.get('name')}"></td>
				<td th:switch="${cnArealist.get('type')}" >
				    <span th:case="1">省</span>
				    <span th:case="2">市</span>
				    <span th:case="3">区(县)</span>
				    <span th:case="4">学校</span>
				</td>
				<td th:text="${cnArealist.get('py')}"></td>
				<td th:switch="${cnArealist.get('is_hotcity')}" >
				    <span th:case="0">不是</span>
				    <span th:case="1">是</span>
				</td>
				<td th:text="${cnArealist.get('school_address')}"></td>
				<td th:text="${cnArealist.get('school_lng')}"></td>
				<td th:text="${cnArealist.get('school_lat')}"></td>
				<td>
					<a th:href="@{/sys/problem/areaMerchantList.html(schoolAreaId=${cnArealist.get('id')})}" class="tablelink" >关联商户</a>
					<a th:href="@{/sys/problem/addcnArea.html(id=${cnArealist.get('id')})}" class="tablelink" >修改</a>
					<a href="javascript:;"  th:onclick="'deleteById(\''+${cnArealist.get('id')}+'\')'" class="tablelink" >删除</a>
				</td>
			</tr>
		</tbody>
	</table>
	<!-- 分页 -->
	<div class="pagin">
    	<div class="message">共<i class="blue">[[${page.rowCnt}]]</i>条记录，当前显示第&nbsp;<i class="blue">[[${page.pageNo }]]&nbsp;</i>页</div>
    	<div th:utext='${listNavigatHtml}' th:remove="tag" ></div>
   	</div>
</div>
<script type="text/javascript">
	var curLocation="[[${search.get('province')}]]";
	var curCity="[[${search.get('city')}]]";
	var curArea="[[${search.get('area')}]]";
	var areaUrl="[[${sysUrl}]]/sys/fx/areaList";
	$(function(){
		funcinitprovince();
	});
function deleteById(id){
	parent.layer.confirm("确定删除该学校？",
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/problem/cnAreaDelete',
			type: "post",
			data:{
				'id': id
			},
			dataType: "json",
			success:function(data){
					
					if(data.code='999'){
						parent.layer.msg("删除成功",{icon:1});
						setTimeout(function(){
				    		location.reload();
						},1000);
					}else{
						parent.layer.msg(data.meta.message,{icon:11});
					}
			}
		});
	});
}
function cnArea(){
	layer.open({
	    type: 2,
	    title: "导入学校地址",
	    closeBtn: 1, //不显示关闭按钮
	    shift: 0.8,
	    //offset: '100px',
	    area: ['55%', '82%'],
	    content: "[[${sysUrl}]]/sys/problem/cnAreaImport.html"
	});
}

function exportCnArea() {
	document.getElementById("seachform").action = "[[${sysUrl}]]/sys/problem/exportDetail";
	$("#seachform").submit();
	window.setTimeout(function(){
		document.getElementById("seachform").action = "[[${sysUrl}]]/sys/problem/cnArealist.html.html";
	},3000);
}
function funcinitprovince(){
	var val = 0;
	var type =1;

	$("#province").html("<option value='' >选择省</option>");

	var params ={ 'type' : type,'upId':val}
	$.post(areaUrl,params,function(data){
		if(data.meta.success){
			var html=[];
			for (var i = 0; i < data.data.length; i++) {
				html.push("<option "+((curLocation==data.data[i].id) ? 'selected' : '')+" data-type='"+data.data[i].type+"' value='"+data.data[i].id+"' >"+data.data[i].name+"</option>");
			}
			$("#province").append(html.join(""));
			funcprovince();
		}else{

		}
	});
}


function funcprovince(){
	var val = $('#province  option:selected').val();
	var type = $('#province  option:selected').data("type");

	$("#city").html("<option value='' >选择市</option>");

	var params ={ 'type' : (type+1),'upId':val}
	$.post(areaUrl,params,function(data){
		if(data.meta.success){
			var html=[];
			for (var i = 0; i < data.data.length; i++) {
				html.push("<option "+((curCity==data.data[i].id) ? 'selected' : '')+" data-type='"+data.data[i].type+"' value='"+data.data[i].id+"' >"+data.data[i].name+"</option>");
			}
			$("#city").append(html.join(""));
			funccity();
		}else{

		}
	});
}

function funccity(){
	var val = $('#city  option:selected').val();
	var type = $('#city  option:selected').data("type");

	$("#area").html("<option value='' >选择区</option>");

	var params ={ 'type' : (type+1),'upId':val}
	$.post(areaUrl,params,function(data){
		if(data.meta.success){
			var html=[];
			for (var i = 0; i < data.data.length; i++) {
				html.push("<option "+((curArea==data.data[i].id) ? 'selected' : '')+" data-type='"+data.data[i].type+"' value='"+data.data[i].id+"' >"+data.data[i].name+"</option>");
			}
			$("#area").append(html.join(""));
		}else{

		}
	});
}
</script>