<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-partjob-loglist-search">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">兼职信息</label>
					<div class="layui-input-block">
						<select name="agentid" lay-search>
							<option value="">全部兼职信息（可搜索）</option>
							{volist name="partjoblist" 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-partjob-loglist-search-btn">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
					<button class="layui-btn" lay-submit lay-filter="LAY-partjob-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-partjob-loglist-table" lay-filter="LAY-partjob-loglist-table"></table>
			<script type="text/html" id="useravatarTpl">
				<div id="pic{{d.id}}" lay-event="pic">
							<img style="width: 100%; height: 100%;" src="{{d.user.avatar}}" alt="{{d.user.nickname}}">
						</div>
					</script>
			<script type="text/html" id="usernicknameTpl">
				{{d.user.nickname}}
					</script>
			<script type="text/html" id="userrealnameTpl">
				{{d.user.realname}}
					</script>
			<script type="text/html" id="usermobileTpl">
				{{d.user.mobile}}
					</script>
			<script type="text/html" id="partjobtitleTpl">
				{{d.partjob.title}}
					</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();

		table.render({
			elem: '#LAY-partjob-loglist-table',
			url: setter.baseAgentUrl + 'partjob/listlog',
			cols: [
				[
					{ type: 'checkbox', fixed: 'left' },
					{ field: 'id', width: 80, title: '表ID', sort: true },
					{ field: 'useravatar', width: 60, title: '头像', templet: '#useravatarTpl' },
					{ field: 'usernickname', title: '昵称', templet: '#usernicknameTpl' },
					{ field: 'userrealname', title: '姓名', templet: '#userrealnameTpl' },
					{ field: 'usermobile', title: '手机号', templet: '#usermobileTpl' },
					{ field: 'partjobid', title: '招聘标题', width: 200, toolbar: '#partjobtitleTpl' },
					{ field: 'remark', title: '反馈备注（点击编辑）', width: 300, edit: 'text' },
					{ field: 'createtime', title: '创建时间', width: 170 },
					{ title: '操作', width: 100, align: 'center', fixed: 'right', toolbar: '#setTpl' }
				]
			],
			page: true,
			limit: 20,
			cellMinWidth: 200,
			height: 'full-200',
			text: '对不起，加载出现异常！'
		});

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

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

		var active = {
			batchdel: function() {
				var checkStatus = table.checkStatus('LAY-partjob-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.baseAgentUrl + 'partjob/dellog',
						data: {
							password: value,
							idarr: idarr
						},
						done: function(res) {
							obj.del();
							layer.msg('已删除');
						}
					});
					table.reload('LAY-partjob-loglist-table');
					layer.msg('已删除');
				});
			}
		};

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