123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- 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 '<input type="checkbox" value="'+d.id+'" name="'+d.state+'" lay-skin="switch" lay-filter="switchTest" lay-text="|暂停">'
- break;
- case '1':
- return '<input type="checkbox" checked value="'+d.id+'" name="'+d.state+'" lay-skin="switch" lay-filter="switchTest" lay-text="使用|">'
- 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');
- })
- });
- });
|