<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-comjobs-loglist-search">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">公司/招聘</label>
					<div class="layui-input-block" id="workercomjobs">
					</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>
							<option value="4">面试未通过</option>
							<option value="5">用户放弃</option>
							<option value="6">已入职</option>
							<option value="7">已离职</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn" lay-submit lay-filter="LAY-comjobs-loglist-search-btn">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
					<button class="layui-btn" lay-submit lay-filter="LAY-comjobs-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-comjobs-loglist-table" lay-filter="LAY-comjobs-loglist-table"></table>
			<script type="text/html" id="useravatarTpl">
				{{#  if(d.user!=null && d.user.avatar != ''){ }}
				<div id="pic{{d.id}}" lay-event="pic">
					<img style="width: 100%; height: 100%;" src="{{d.user.avatar}}">
				</div>
				{{#  } }}
			</script>
			<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();

		var workercomjobs = selectN({
			elem: '#workercomjobs',
			search: [true, true],
			tips: ["请选择劳务公司（可搜索）", "请选择招聘信息（可搜索）"],
			data: {$workerlist|raw},
			selected: [0, 0],
			field: { idName: 'id', titleName: 'title', childName: 'comjobs' }
		});

		table.render({
			elem: '#LAY-comjobs-loglist-table',
			url: setter.baseAdminUrl + 'comjobs/listlog',
			cols: [
				[
					{ type: 'checkbox', fixed: 'left' },
					{ field: 'id', width: 80, title: '表ID', sort: true },
					{ field: 'useravatar', width: 60, title: '头像', templet: '#useravatarTpl' },
					{ field: 'usernickname', title: '昵称', width: 150, templet: '<div>{{d.user.nickname||""}}</div>' },
					{ field: 'userrealname', title: '姓名', width: 150, templet: '<div>{{d.user.realname||""}}</div>' },
					{ field: 'usermobile', title: '手机号', width: 150, templet: '<div>{{d.user.mobile||""}}</div>' },
					{ field: 'workerid', title: '劳务公司', toolbar: '<div>{{d.worker.title||""}}</div>' },
					{ field: 'comjobsid', title: '招聘标题', width: 200, toolbar: '<div>{{d.comjobs.title||""}}</div>' },
					{ field: 'status_text', title: '公司反馈', minWidth: 150, align: 'center' },
					{ field: 'remark', title: '反馈备注（点击编辑）', width: 300, edit: 'text' },
					{ 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-comjobs-loglist-search-btn)', function(data) {
			table.reload('LAY-comjobs-loglist-table', {
				where: data.field,
				page: {
					curr: 1
				}
			});
		});
		form.on('submit(LAY-comjobs-loglist-export-btn)', function(data) {
			var url = setter.baseAdminUrl + 'comjobs/exportlog?';
			for (var item in data.field) {
				url = url + '&' + item + '=' + data.field[item];
			}
			window.location.href = url;
		});

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

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

		table.on('tool(LAY-comjobs-loglist-table)', function(obj) {
			var data = obj.data;
			if (obj.event === 'del') {
				layer.confirm('确定删除此报名记录吗？', function(index) {
					admin.req({
						url: setter.baseAdminUrl + 'comjobs/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>
