<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-form layui-form-pane layui-card-header layuiadmin-card-header-auto" lay-filter="reportlist-search">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">招聘信息</label>
					<div class="layui-input-block">
						<select name="comjobsid" lay-search>
							<option value="">全部招聘信息（可搜索）</option>
							{volist name="comjobslist" id="vo"}
							<option value="{$vo['id']}">{$vo['title']}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">代理门店</label>
					<div class="layui-input-block">
						<select name="agentid" lay-search>
							<option value="">全部代理门店（可搜索）</option>
							<option value="0">未报备</option>
							{volist name="agentlist" id="vo"}
							<option value="{$vo['id']}">{$vo['title']}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">状态</label>
					<div class="layui-input-block">
						<select name="status">
							<option value="">全部状态</option>
							{volist name="statusarr" id="vo" key="k"}
							<option value="{$k}">{$vo}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">日期范围</label>
						<div class="layui-input-inline">
							<input type="text" class="layui-input" id="test6"  placeholder=" ~ ">
						</div>
					</div>
				<div class="layui-inline">
					<button class="layui-btn" lay-submit lay-filter="reportlist-search-btn">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
					<button class="layui-btn" lay-submit lay-filter="reportlist-export-btn">
						导出
					</button>
<!--					<button class="layui-btn" lay-submit lay-filter="reportlist-repeat-btn">-->
<!--						重复-->
<!--					</button>-->
				</div>
			</div>
		</div>

		<div class="layui-card-body">
			<div class="layui-form layui-form-pane" lay-filter="reportlist-setstatus" style="padding-bottom: 0px;">
				<div class="layui-form-item">
					<div class="layui-inline" id="refundbox"> </div>
					<div class="layui-inline">
						<label class="layui-form-label">状态</label>
						<div class="layui-input-inline">
							<select name="setstatus" lay-filter="setstatus">
								<option value="">选择状态</option>
								{volist name="statusarr" id="vo" key="k"}
								<option value="{$k}">{$vo}</option>
								{/volist}
							</select>
						</div>
					</div>
				</div>
			</div>
			<table id="reportlist-table" lay-filter="reportlist-table"></table>
			<script type="text/html" id="statusTpl">
				{{#  if(d.status_text === '待审核'){ }}
				<span style="background: #F581B1;">{{ d.status_text }}</span>
				{{#  } else { }}
				{{ d.status_text }}
				{{#  } }}
			</script>

			<script type="text/html" id="tabletoolbar">
				<div class="layui-btn-container">
					<button class="layui-btn layui-btn-sm" lay-event="batchdel">批量删除</button>
					<button class="layui-btn layui-btn-sm" lay-event="setstatus">批量修改状态</button>
					<button class="layui-btn layui-btn-sm" lay-event="add">添加报备信息</button>
				</div>
			</script>
			<script type="text/html" id="setTpl">
				<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			</script>
		</div>
	</div>
</div>

<script> 
	layui.config({
		base: '/static/echoui/' //静态资源所在路径
	}).extend({
		index: 'lib/index' //主入口模块
	}).use(['index', 'form', 'set', 'table', 'selectN', 'selectM','laydate'], function() {
		var $ = layui.$,
			setter = layui.setter,
			admin = layui.admin,
			form = layui.form,
			table = layui.table,
			selectN = layui.selectN,
			selectM = layui.selectM;
		var laydate = layui.laydate;
		var date6;
		form.render();

		//日期范围
		laydate.render({
			elem: '#test6'
			,range: '~'
			,done: function(value, date, endDate){
				date6 = value;
			}
		});

		table.render({
			elem: '#reportlist-table',
			url: setter.baseAdminUrl + 'comjobsreport/listreport',
			height: 'full-20',
			cols: [
				[
					{ type: 'checkbox', fixed: 'left' },
					{ field: 'id', width: 80, title: '表ID', sort: true },
					{ field: 'status_text', title: '状态', minWidth: 100 ,templet: '#statusTpl',},
					{ field: 'realname', title: '姓名', minWidth: 100 },
					{ field: 'mobile', title: '手机号', minWidth: 120 },
					{ field: 'idcard', title: '身份证号', minWidth: 200 },
					{ field: 'arrivetime', title: '预计到达时间', minWidth: 170 },
					{ field: 'remark', title: '报名备注', minWidth: 170, hide: true },

					{ field: 'comjobsid', title: '招聘订单', minWidth: 200, toolbar: '<div>{{d.comjobs!=null ? d.comjobs.title : ""}}</div>' },
					{ field: 'comjobsid', title: '招聘企业', minWidth: 200, hide: true, toolbar: '<div>{{d.comjobs.company!=null ? d.comjobs.company.title : ""}}</div>' },
					{ field: 'agenttitle', title: '代理门店', minWidth: 200, templet: '<div>{{d.agent!=null ? d.agent.title : ""}}</div>' },
					{ field: 'brokerid', title: '经纪人', width: 150, templet: '<div>{{d.broker!=null ? d.broker.title : ""}}</div>', hide: true },
					{ field: 'createtime', title: '报备时间', width: 170 },
					{ title: '操作', width: 230, align: 'center', fixed: 'right', toolbar: '#setTpl' }
				]
			],
			page: true,
			limit: 50,
			toolbar: '#tabletoolbar',
			cellMinWidth: 200,
			text: '对不起，加载出现异常！'
		});
		
		// 批量设置
		var comjobslist = {$comjobslist|raw};
		var comjobsid = 0;
		var comtype = "";
		var comprice = "";
		var comremark = "";
		var setstatus = "";
		form.on('select(setstatus)', function(data){
			setstatus = data.value;
		});
		form.on('select(comjobsid)', function(data){
			$('#retdetailsbox').html("");
			for(var i=0;i<comjobslist.length;i++){
				if (data.value==comjobslist[i].id){
					var refund = comjobslist[i].comjobsRefund;
					var html = ""
					for(var reti=0;reti<refund.length;reti++){
						html += '<input type="radio" lay-filter="reportrefund" name="reportrefund" data-type="'+refund[reti].reftype+'" data-price="'+refund[reti].refprice+'" data-remark="'+refund[reti].refremark+'" value="'+reti+'" title="'+refund[reti].reftype +"【"+ refund[reti].agentGroups.title+'】" />';
					}
					$('#refundbox').html(html);
				}
			}
			comjobsid = data.value;
			comtype = "";
			comprice = "";
			comremark = "";
			form.render();
		});
		form.on('radio(reportrefund)',function (obj) {
			comtype = $(this).data('type');
			comprice = $(this).data('price');
			comremark = $(this).data('remark');
		});

		form.on('submit(reportlist-search-btn)', function(data) {
			table.reload('reportlist-table', {
				where: data.field,
				page: {
					curr: 1
				}
			});
		});
		form.on('submit(reportlist-export-btn)', function(data) {
			var url = setter.baseAdminUrl + 'comjobsreport/exportreport?';
			for (var item in data.field) {
				url = url + '&' + item + '=' + data.field[item];
			}
			window.location.href = url;
		});

		form.on('submit(reportlist-repeat-btn)', function(data) {
			table.reload('reportlist-table', {
				where: {date6:date6,repeat:1},
				page: {
					curr: 1
				}
			});
		});


		//头工具栏事件
		table.on('toolbar(reportlist-table)', function(obj) {
			var checkStatus = table.checkStatus(obj.config.id);
			switch (obj.event) {
				case 'batchdel':
					var checkData = checkStatus.data;
					if (checkData.length === 0) {
						return layer.msg('请选择数据');
					}
					var idarr = [];
					for (var i = 0; i < checkData.length; i++) {
						idarr.push(checkData[i].id);
					}
					layer.confirm('删除后不可恢复，确定删除此报备记录吗？', function(index) {
						admin.req({
							url: setter.baseAdminUrl + 'comjobsreport/delreport',
							data: {
								idarr: idarr
							},
							done: function(res) {
								table.reload('reportlist-table');
								layer.msg('已删除');
							}
						});
					});
					break;
				case 'setcomtype':
					if (comjobsid==0 || comtype==""){
						return layer.msg('请选择返费模式');
					}
					var checkData = checkStatus.data;
					if (checkData.length === 0) {
						return layer.msg('请选择数据');
					}
					var idarr = [];
					for (var i = 0; i < checkData.length; i++) {
						idarr.push(checkData[i].id);
					}
					layer.confirm('确定要批量修改所选报备记录返费模式吗？', function(index) {
						admin.req({
							url: setter.baseAdminUrl + 'comjobsreport/setComtype',
							data: {
								idarr: idarr,
								comjobsid: comjobsid,
								comtype: comtype,
								comprice: comprice,
								comremark: comremark
							},
							done: function(res) {
								table.reload('reportlist-table');
								layer.msg('已批量修改');
							}
						});
					});
					break;
				case 'setstatus':
					if (setstatus==""){
						return layer.msg('请选择状态');
					}
					var checkData = checkStatus.data;
					if (checkData.length === 0) {
						return layer.msg('请选择数据');
					}
					var idarr = [];
					for (var i = 0; i < checkData.length; i++) {
						idarr.push(checkData[i].id);
					}
					layer.confirm('确定要批量修改所选报备记录状态吗？', function(index) {
						admin.req({
							url: setter.baseAdminUrl + 'comjobsreport/setStatus',
							data: {
								idarr: idarr,
								status: setstatus
							},
							done: function(res) {
								table.reload('reportlist-table');
								layer.msg('已批量修改');
							}
						});
					});
					break;
				case 'add':
					var index = layer.open({
						type: 2,
						title: '添加报备信息',
						content: 'reportform.html?id=0',
						maxmin: true,
						area: ['550px', '550px']
					});
					layer.full(index);
					break;
				case 'batch':
					var index = layer.open({
						type: 2,
						title: '批量导入报备信息',
						content: 'reportimport.html',
						maxmin: true,
						area: ['550px', '550px']
					});
					layer.full(index);
					break;
			};
		});


		table.on('tool(reportlist-table)', function(obj) {
			var data = obj.data;
			if (obj.event === 'del') {
				layer.confirm('确定删除此报备记录吗？', function(index) {
					admin.req({
						url: setter.baseAdminUrl + 'comjobsreport/delreport',
						data: {
							idarr: [data.id]
						},
						done: function(res) {
							obj.del();
							layer.msg('已删除');
						}
					});
					layer.close(index);
				});
			} else if (obj.event === 'edit') {
				var index = layer.open({
					type: 2,
					title: '编辑报备信息',
					content: 'reportform.html?id=' + data.id,
					maxmin: true,
					area: ['750px', '480px']
				});
				layer.full(index);
			}
		});
	});
</script>
