<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-worder-loglist-search">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">招聘订单</label>
					<div class="layui-input-block">
						<select name="worderid" lay-search>
							<option value="">全部订单（可搜索）</option>
							{volist name="worderlist" id="vo"}
							<option value="{$vo['id']}">{$vo['title']}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn" lay-submit lay-filter="LAY-worder-loglist-search-btn">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
					<button class="layui-btn" lay-submit lay-filter="LAY-worder-loglist-export-btn">
						导出
					</button>
				</div>
			</div>
		</div>

		<div class="layui-card-body">
			<div style="padding-bottom: 10px;">
				<button class="layui-btn layuiadmin-btn" data-type="batchdel">删除</button>
			</div>

			<table id="LAY-worder-loglist-table" lay-filter="LAY-worder-loglist-table"></table>
			<script type="text/html" id="setTpl">
				<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'], function() {
		var $ = layui.$,
			setter = layui.setter,
			admin = layui.admin,
			form = layui.form,
			table = layui.table,
			selectN = layui.selectN,
			selectM = layui.selectM;
		form.render();

		table.render({
			elem: '#LAY-worder-loglist-table',
			url: setter.baseWorkerUrl + 'worder/listlog', 
			cols: [
				[
					{ type: 'checkbox', fixed: 'left' },
					{ field: 'id', width: 80, title: '表ID', sort: true },
					{ field: 'wordertitle', title: '订单标题', templet: '<div>{{d.worder.title||""}}</div>' },
					{ field: 'getworkertitle', title: '接单公司', templet: '<div>{{d.getWorker.title||""}}</div>' },
					{ field: 'getworkerrealname', title: '负责人', templet: '<div>{{d.getWorker.realname||""}}</div>' },
					{ field: 'getworkertitle', title: '负责人电话', templet: '<div>{{d.getWorker.mobile||""}}</div>' },
					{ field: 'createtime', title: '接单时间', width: 170 },
					{ title: '操作', width: 100, align: 'center', fixed: 'right', toolbar: '#setTpl' }
				]
			],
			page: true,
			limit: 50,
			cellMinWidth: 200,
			text: '对不起，加载出现异常！'
		});

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

		table.on('edit(LAY-worder-loglist-table)', function(obj) {
			var id = obj.data.id,
				field = obj.field,
				value = obj.value;
			admin.req({
				url: setter.baseWorkerUrl + 'worder/fieldlog',
				data: { id: id, field: field, value: value },
				done: function(res) {
					layer.msg('修改成功');
					layui.table.reload('LAY-worder-loglist-table');
				}
			});
		});

		var active = {
			batchdel: function() {
				var checkStatus = table.checkStatus('LAY-worder-loglist-table'),
					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.baseWorkerUrl + 'worder/dellog',
						data: {
							idarr: idarr
						},
						done: function(res) {
							table.reload('LAY-worder-loglist-table');
							layer.msg('已删除');
						}
					});
					layer.close(index);
				});
			}
		};

		table.on('tool(LAY-worder-loglist-table)', function(obj) {
			var data = obj.data;
			if (obj.event === 'del') {
				layer.confirm('确定删除此报名记录吗？', function(index) {
					admin.req({
						url: setter.baseWorkerUrl + 'worder/dellog',
						data: {
							idarr: [data.id]
						},
						done: function(res) {
							obj.del();
							layer.msg('已删除');
						}
					});
					layer.close(index);
				});
			} else if (obj.event === 'pic') {
				layer.photos({
					photos: '#pic' + data.id,
					anim: 5,
				});
			}
		});

		$('.layui-btn.layuiadmin-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

	});
</script>
