<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('选择所属客户')" />
</head>

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-10 search-collapse">
				<form id="role-form">
					
					<div class="select-list">
						<ul>
							<li>客户名称：<input type="text" name="customerName" />
							</li>
							<li>手机号码：<input type="text" name="mobile" />
							</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="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var customerTypeDatas = [[${@dict.getType('crm_customer_type')}]];
		var prefix = ctx + "crm/customer";

		$(function() {
			var options = {
		        url: prefix + "/listAll",
		        queryParams: queryParams,
		        modalName: "客户",
		        showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
		        clickToSelect: true,
		        sortName: "createTime",
		        sortOrder: "desc",
		        columns: [
		        {
		        	radio: true
		        },
                {
                    field : 'customerId', 
                    title : 'ID',
                    visible: false
                },
                {
                    field : 'customerName', 
                    title : '客户名称',
		            sortable: true
                },
                {
                    field : 'nameShort', 
                    title : '客户简称',
		            sortable: true
                },
                {
                    field : 'customerType', 
                    title : '客户类型',
		            sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(customerTypeDatas, value);
                     }
                },
                {
                    field : 'leader', 
                    title : '负责人',
		            sortable: true
                },
                {
                    field : 'telephone', 
                    title : '固定电话',
		            sortable: true
                },
                {
                    field : 'mobile', 
                    title : '手机',
		            sortable: true
                },
		        {
		            field: 'createTime',
		            title: '录入时间',
		            sortable: true,
                    visible: false
		        }]
		    };
		    $.table.init(options);
		});
		
		function queryParams(params) {
			var search = $.table.queryParams(params);
			return search;
		}
		
		/* 添加用户-选择用户-提交 */
		function submitHandler() {
			var id = $.table.selectFirstColumns();
			var name = $.table.selectColumns("customerName");
			if (id.length == 0) {
       			$.modal.alertWarning("请选择一条记录");
       			return;
       		}
			$.modal.close();
			// 父页面的方法
			// parent.selectUsers();
			// 父页面的变量
			parent.$('#customerId').val();
			parent.$('#customerName').val();
			parent.$('#customerId').val(id);
			parent.$('#customerName').val(name);
		}
	</script>
</body>
</html>