<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('用户统计列表')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
	<div class="ui-layout-center" id="app">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="user-form">
						<input type="hidden" id="deptId" name="deptId">
		                <input type="hidden" id="parentId" name="parentId">
						<div class="select-list">
							<ul>
								<li>
									<label>单位名称：</label>
									<input type="text" name="deptName"/>
								</li>
								<li>
									<label>所属市州：</label>
									<select id="City" name="framework" @change="getAreaList()" v-model="City">
										<option value="">请选择</option>
										<option v-for="option in CityList" :value="option.id" :key="option.id">
											{{ option.name }}
										</option>
									</select>
								</li>
								<li>
									<label>所属区县：</label>
									<select id="Area" name="area" v-model="Area">
										<option value="">请选择</option>
										<option v-for="option in AreaList" :value="option.id" :key="option.id">
											{{ option.name }}
										</option>
									</select>
								</li>
								<li>
									<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								    <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
								</li>
							</ul>
						</div>
					</form>
				</div>

		        <div class="btn-group-sm" id="toolbar" role="group">
		            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:usernum:export">
			            <i class="fa fa-download"></i> 导出
			        </a>
		        </div>
		        <div class="col-sm-12 select-table table-striped">
				    <table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>

	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
		var detailFlag = [[${@permission.hasPermi('system:usernum:detail')}]];
		var politics = [[${@dict.getType('sys_user_politics')}]];
		var shemichengdu = [[${@dict.getType('sys_user_shemi')}]];
		var examineState = [[${@dict.getType('sys_examine_state')}]];
		var prefix = ctx + "system/usernum";
		let datas = []
		$.ajax({
			url: ctx + "system/area/getAllList",
			type: 'GET',
			data:{parentId:''} ,
			success:((res)=>{
				datas = res.data
			}) ,
		});
		$(function() {
		    var panehHidden = false;
		    if ($(this).width() < 769) {
		        panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: 185 });
	     	// 回到顶部绑定
	    	if ($.fn.toTop !== undefined) {
	    		var opt = {
	    			win:$('.ui-layout-center'),
	    			doc:$('.ui-layout-center')
	    		};
	    		$('#scroll-up').toTop(opt);
	    	}
		    queryUserList();
		    queryDeptTree();
		});

		function queryUserList() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        detail: prefix + "/detail/{id}",
				print: prefix + "/print/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        modalName: "用户",
		        columns: [{
		            checkbox: true
		        },
				{
					field : 'dept.deptid',
					title : '编号',
					visible: false
				},
				{
					field: 'dept.framework',
					title: '所属市州',
					formatter: function(value, row, index) {
						return getCity(datas, value)
					}
				},
				{
					field: 'dept.area',
					title: '所属区县',
					formatter: function(value, row, index) {
						return getCity(datas, value)
					}
				},
				{
					field: 'dept.deptName',
					title: '所在单位'
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="print(\'' + row.deptId + '\')"><i class="fa fa-download"></i>打印</a> ');
						return actions.join('');		            }
		        }]
		    };
		    $.table.init(options);
		}

		$('#btnRefresh').click(function() {
			queryDeptTree();
		});

		/* 自定义重置-表单重置/隐藏框/树节点选择色/搜索 */
		function resetPre() {
			resetDate();
			$("#user-form")[0].reset();
			$("#deptId").val("");
			$("#parentId").val("");
			$(".curSelectedNode").removeClass("curSelectedNode");
			$.table.search();
		}
		var app = new Vue({
			el: '#app',
			data: {
				CityList: [],
				AreaList:[],
				City:'',
				Area:'',
				params:{
					parentId:'',
				}
			},
			mounted(){
				// 初始化地市列表
				this.getCityList();
				if (this.City){
					this.getAreaList()
				}
			},
			methods:{
				getCityList(){
					$.ajax({
						url: ctx + "system/area/getSysAreaList",
						type: 'GET',
						data:this.params ,
						success:((res)=>{
							this.CityList = res.data
						}) ,
					});
				},
				getAreaList(){
					this.params.parentId = this.City
					$.ajax({
						url: ctx + "system/area/getSysAreaList",
						type: 'GET',
						data:this.params,
						success:((res)=>{
							this.AreaList = res.data
						}) ,
					});
				}
			}
		})
		/* 用户管理-部门 */
		function dept() {
			var url = ctx + "system/dept";
			$.modal.openTab("部门管理", url);
		}
		function print(deptId) {
			var url = prefix + '/print/' + deptId;
			$.modal.openTab("打印界面", url);
		}

	</script>
</body>
</html>
