<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-form layui-form-pane layui-card-header layuiadmin-card-header-auto" lay-filter="LAY-demand-demandlist-search">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">抢单者</label>
					<div class="layui-input-block">
						<select name="workerid" lay-search>
							<option value="">全部企业（可搜索）</option>
							{volist name="workerlist" 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>
							<option value="1">待审核</option>
							<option value="2">审核通过</option>
							<option value="3">已完成</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn" lay-submit lay-filter="LAY-demand-demandlist-btn">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
				</div>
			</div>
		</div>

		<div class="layui-card-body">
			<table id="LAY-demand-demandlist-table" lay-filter="LAY-demand-demandlist-table"></table>
			<script type="text/html" id="selectStatus">
				<select name="status" lay-filter="status" data-value=""></select>
			</script>
			<script type="text/html" id="setTpl">
				{{# if(d.status == 1){ }}
					<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="checkpass"><i class="layui-icon layui-icon-edit"></i>审核通过</a>
					<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="checkreject"><i class="layui-icon layui-icon-delete"></i>审核不通过</a>
				{{# } }}
				{{# if(d.status == 2){ }}
					<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="reportlog"><i class="layui-icon layui-icon-edit"></i>报备记录</a>
				{{# } }}
				<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon layui-icon-read"></i>订单详情</a>
			</script>
		</div>
	</div>
</div>

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

		form.render();

		table.render({
			elem: '#LAY-demand-demandlist-table',
			height: 'full-20',
			url: setter.baseAdminUrl + 'demand/snatchlist',
			cols: [
				[
					{ field: 'id', width: 80, title: '表ID', sort: true },
					{ field: 'worker', title: '抢单者', width: 200, toolbar: '<div>{{d.worker.title}}</div>'  },
					{ field: 'worker', title: '发单者', width: 200, toolbar: '<div>{{d.demand.worker.title}}</div>'  },
					{ field: 'demand', title: '岗位标题', minWidth: 200, toolbar: '<div>{{d.demand.title}}</div>' },
					{ field: 'demand', title: '联系电话', width: 120, toolbar: '<div>{{d.demand.telephone}}</div>' },
					{ field: 'num', title: '招聘人数', width: 100 },
					{ field: 'status_text', title: '状态', width: 100 },
					{ field: 'createtime', title: '接单时间', width: 180 },
					{ title: '操作', width: 300, align: 'center', fixed: 'right', toolbar: '#setTpl' }
				]
			],
			page: true,
			limit: 50,
			toolbar: true,
			cellMinWidth: 150,
			text: '对不起，加载出现异常！'
		});

		form.on('submit(LAY-demand-demandlist-btn)', function(data) {
			table.reload('LAY-demand-demandlist-table', {
				where: data.field,
				page: {
					curr: 1
				}
			});
		});

		table.on('tool(LAY-demand-demandlist-table)', function(obj) {
			var data = obj.data;
			if (obj.event === 'detail') {
				var index = layer.open({
					type: 2,
					title: '订单信息',
					content: 'demanddetail.html?id=' + data.demand_id,
					maxmin: true,
					area: ['750px', '480px']
				});
				layer.full(index);
			} else if (obj.event === 'checkpass') {
				layer.confirm('确定审核通过此订单信息吗？', function(index) {
					admin.req({
						url: setter.baseAdminUrl + 'demand/snatchstatus',
						data: {
							id: data.id,
							status: 2,
						},
						done: function(res) {
							obj.del();
							layer.msg('审核成功');
						}
					});
					table.reload('LAY-demand-demandlist-table');
				});
			} else if (obj.event === 'checkreject') {
				layer.confirm('确定拒绝此订单信息吗？', function(index) {
					admin.req({
						url: setter.baseAdminUrl + 'demand/snatchstatus',
						data: {
							id: data.id,
							status: 3,
						},
						done: function(res) {
							obj.del();
							layer.msg('审核成功');
						}
					});
					table.reload('LAY-demand-demandlist-table');
				});
			}  else if (obj.event === 'reportlog') {
				let index = layer.open({
					type: 2,
					title: '编辑其他订单信息',
					content: 'reportLog.html?id=' + data.id,
					maxmin: true,
					area: ['750px', '480px']
				});
				layer.full(index);
			}
		});

	});
</script>
