layui.use([ 'laypage', 'layer', 'table', 'element','form'], function(){ var laypage = layui.laypage //分页 ,layer = layui.layer //弹层 ,table = layui.table //表格 ,element = layui.element //元素操作 ,form = layui.form; var tableIds = 'newsCategoryList'; //第一个实例 table.render({ elem: '#'+tableIds ,url: '/usersignup/labelform' //数据接口 ,where:{token:csrfToken} ,method:'post' ,page: true //开启分页 ,text:'数据加载中' ,id:'tablereload' ,cols: [[ //表头 // {type:'numbers'}, // {field: 'id', title: 'ID',align:'center'}, {field: 'name', title: '来源名称', align:'center'} ,{field: 'type', title: '来源设备', align:'center',width:100} ,{field: 'source_id', title: '文档ID',align:'center',width:100} ,{field: 'remarks', title: '备注信息',align:'center'} ,{field: 'state', title: '状态',align:'center',width:150,templet:function (d) { switch (d.state){ case '2': return '' break; case '1': return '' break; } }} ,{field: 'create_at', title: '添加时间', align:'center',width:150} ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'} ]] }); //列表操作 table.on('tool('+tableIds+')', function(obj){ var layEvent = obj.event, data = obj.data; if(layEvent === 'edit'){ layer.open({ type: 2, title: '编辑报名来源信息', closeBtn: 1, //不显示关闭按钮 shade: [0], area: ['600px', '500px'], anim: 2, content: '/usersignup/labeledit?id='+data.id, //iframe的url,no代表不显示滚动条 end:function () { table.reload('tablereload'); } }); } else if(layEvent === 'del') { layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () { $.post('/dictionary/newsdel',{'id':data.id,'del':2},function (data) { table.reload('tablereload'); }) }) } }); var $ = layui.$, active = { addData: function(){ //获取选中数据 layer.open({ type: 2, title: '添加栏目', closeBtn: 1, //不显示关闭按钮 shade: [0], area: ['600px', '500px'], anim: 2, content: '/usersignup/labeladd', //iframe的url,no代表不显示滚动条 end:function () { table.reload('tablereload'); } }); // var checkStatus = table.checkStatus('idTest') // ,data = checkStatus.data; // layer.alert(JSON.stringify(data)); }, reload:function () { var form = pfgs_serialize($('form')); var name = ''; var source_id = ''; if(form.input_house == 'name'){ name = form.input_house_text; } else if(form.input_house == 'source_id'){ source_id = form.input_house_text; } table.reload('tablereload',{ where:{ source_id:source_id, name:name, type:form.type }, page:{ //重载分页 curr:1 } }) } }; $('.demoTable .layui-btn').on('click', function(){ var type = $(this).data('type'); active[type] ? active[type].call(this) : ''; }); //修改 form.on('submit(editnews)', function(data){ layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); $.post('/usersignup/labeleditform',{'data':data.field,'token':csrfToken},function (data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return ; } layer.msg(data.msg); TableClose(); }) return false; }); //添加 form.on('submit(addnews)', function(data){ layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); $.post('/usersignup/labeladdform',{'data':data.field,'token':csrfToken},function (data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return ; } layer.msg(data.msg); TableClose(); }) return false; }); //监听指定开关 form.on('switch(switchTest)', function(data){ console.log(data); var stateValue = data.elem.attributes.name.value; console.log(stateValue); layer.confirm('确定要删除吗?',{btn: ['确定', '取消']},function () { switch (stateValue) { case '1': stateValue = 2; break; case '2': stateValue = 1; break; } $.post('/usersignup/labeleditform',{'data':{'id':data.value ,'state':stateValue},'token':csrfToken},function (data) { if(data.data != null){ layer.msg(ReturnInfo(data.data),{icon:5}); return ; } layer.msg(data.msg); table.reload('tablereload'); }) },function () { table.reload('tablereload'); }) }); });