<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-header">用户授权信息</div>
		<div class="layui-card-body" lay-filter="LAY-user-authslist-list">

			<table id="LAY-user-authslist-table" lay-filter="LAY-user-authslist-table"></table>
			<script type="text/html" id="authssetTpl">
				{{#  if(d.identitytype == 'mobile'){ }}
					<a class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>
				{{#  } else { }}
					<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="authsdel"><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'], function() {
		var $ = layui.$,
			setter = layui.setter,
			admin = layui.admin,
			form = layui.form,
			table = layui.table;
		form.render();

		table.render({
			elem: '#LAY-user-authslist-table',
			url: setter.baseWorkerUrl + 'user/listauths?userid={$userid}',
			cols: [
				[
					{ field: 'identitytype_text', width: 80, title: '类型' },
					{ field: 'identifier', title: '唯一标识' },
					{ field: 'logintime', title: '最近一次登录时间' },
					{ field: 'loginip', title: '最近一次登录IP' },
					{ title: '操作', width: 100, align: 'center', fixed: 'right', toolbar: '#authssetTpl' }
				]
			],
			text: '对不起，加载出现异常！'
		});

		table.on('tool(LAY-user-authslist-table)', function(obj) {
			var data = obj.data;
			if (obj.event === 'authsdel') {
				layer.confirm('确定删除此授权吗？', function(index) {
					admin.req({
						url: setter.baseWorkerUrl + 'user/delauths',
						data: {
							id: data.id
						},
						done: function(res) {
							obj.del();
							layer.msg('已删除');
						}
					});
					layer.close(index);
				});
			}
		});

	});
</script>
