<%@ page language="java" contentType="text/html;charset=UTF-8" trimDirectiveWhitespaces="true"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fastboot" prefix="fb"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro"%>
<fb:ui src="base/main">

	<fb:property name="title">机构管理</fb:property>

	<fb:css href="${base}/static/js/city-picker/city-picker.css"></fb:css>

	<fb:script src="${base}/static/js/city-picker/city-picker.data.js"></fb:script>

	<fb:script type="text/javascript">
		<script>
			layui.use([ 'tool', 'form', 'city' ], function() {
				//
				var table_obj;
				// 操作对象
				var $ = layui.$, tool = layui.tool, form = layui.form;

				//
				var options = {
					url : '${base}/organ/page',
					toolbar : '#toolbar',
					limit : 20,
					cols : [ [ {
						type : 'checkbox',
					}, {
						field : 'id',
						title : 'ID',
						align : 'center',
						width : 100
					}, {
						field : 'company',
						title : '公司',
						width : 250,
						templet : '#company'
					}, {
						field : 'contacts',
						title : '联系人',
						width : 150,
					},{
						field : 'cityName',
						title : '区县'
					},{
						field : 'address',
						title : '地址'
					}, {
						field : 'updateDate',
						title : '更新时间',
						align : 'center',
						width : 150,
					}, {
						toolbar : '#tool',
						title : '操作',
						align : 'center',
						width : 120
					} ] ],
					search : function() {
						var keyword = $('#keyword').val();
						//执行重载
						table_obj.reload({
							page : {
								curr : 1
							},
							where : {
								keyword : keyword,
							}
						});
					},
					add : function() {
						tool.dialog('${base}/organ/form?id=-1', '80%', this.search);
					},
					del : function() {
						tool.remove('${base}/organ/delete');
					},
					info : function(data) {
						tool.dialog('${base}/organ/form?id=' + data.id, '80%');
					}
				};
				// 分页
				table_obj = tool.page(options);
				// 切换
				form.on('checkbox(isAgreement)', function(obj) {
					var data = new Object();
					data.isAgreement = obj.elem.checked ? "0" : "1";
					data.id = $(this).attr('mid');
					tool.post("${base}/organ/updateAgreement", data);
				});
				// 切换
				form.on('checkbox(isEnable)', function(obj) {
					var data = new Object();
					data.isEnable = obj.elem.checked ? "0" : "1";
					data.id = $(this).attr('mid');
					tool.post("${base}/organ/updateEnable", data);
				});

			});
		</script>
	</fb:script>

	<fb:layout>

		<script type="text/html" id="tel">
 		 	{{#
				var phone = function(){
    				return d.tel.substr(0,3)+'****'+d.tel.substr(7);
  				}; 
			 }}
			{{ phone() }}
		</script>

		<script type="text/html" id="company">
 			<a href="{{d.shareQrcode}}" target="_blank">{{d.company}}</a>
		</script>

		<script type="text/html" id="isAgreement">
			<input type="checkbox" name="isAgreement" value={{d.isAgreement}} lay-skin="primary" mid={{d.id}}  lay-filter="isAgreement" {{ d.isAgreement == '0' ? 'checked' : '' }}>
		</script>

		<script type="text/html" id="isEnable">
			<input type="checkbox" name="isEnable" value={{d.isEnable}} lay-skin="primary" mid={{d.id}}  lay-filter="isEnable" {{ d.isEnable == '0' ? 'checked' : '' }}>
		</script>

		<script type="text/html" id="tool">
			<a class="layui-btn layui-btn-xs" lay-event="info">编辑</a>
		</script>

		<script type="text/html" id="toolbar">
 		 	<div class="layui-btn-container">
				<button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="search">搜索</button>
    			<button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="add">添加</button>
    			<button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="del">删除</button>
  			</div>
		</script>

		<div class="layui-form">
			<div class="layui-inline">
				<div class="layui-input-inline" style="width: 300px;">
					<input type="text" id="keyword" placeholder="ID、公司、联系人" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>

		<div class="layui-card">
			<table id="table" class="layui-hide" lay-filter="table" />
		</div>
	</fb:layout>
</fb:ui>