label.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form'], function(){
  2. var laypage = layui.laypage //分页
  3. ,layer = layui.layer //弹层
  4. ,table = layui.table //表格
  5. ,element = layui.element //元素操作
  6. ,form = layui.form;
  7. var tableIds = 'newsCategoryList';
  8. //第一个实例
  9. table.render({
  10. elem: '#'+tableIds
  11. ,url: '/usersignup/labelform' //数据接口
  12. ,where:{token:csrfToken}
  13. ,method:'post'
  14. ,page: true //开启分页
  15. ,text:'数据加载中'
  16. ,id:'tablereload'
  17. ,cols: [[ //表头
  18. // {type:'numbers'},
  19. // {field: 'id', title: 'ID',align:'center'},
  20. {field: 'name', title: '来源名称', align:'center'}
  21. ,{field: 'type', title: '来源设备', align:'center',width:100}
  22. ,{field: 'source_id', title: '文档ID',align:'center',width:100}
  23. ,{field: 'remarks', title: '备注信息',align:'center'}
  24. ,{field: 'state', title: '状态',align:'center',width:150,templet:function (d) {
  25. switch (d.state){
  26. case '2':
  27. return '<input type="checkbox" value="'+d.id+'" name="'+d.state+'" lay-skin="switch" lay-filter="switchTest" lay-text="|暂停">'
  28. break;
  29. case '1':
  30. return '<input type="checkbox" checked value="'+d.id+'" name="'+d.state+'" lay-skin="switch" lay-filter="switchTest" lay-text="使用|">'
  31. break;
  32. }
  33. }}
  34. ,{field: 'create_at', title: '添加时间', align:'center',width:150}
  35. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  36. ]]
  37. });
  38. //列表操作
  39. table.on('tool('+tableIds+')', function(obj){
  40. var layEvent = obj.event,
  41. data = obj.data;
  42. if(layEvent === 'edit'){
  43. layer.open({
  44. type: 2,
  45. title: '编辑报名来源信息',
  46. closeBtn: 1, //不显示关闭按钮
  47. shade: [0],
  48. area: ['600px', '500px'],
  49. anim: 2,
  50. content: '/usersignup/labeledit?id='+data.id, //iframe的url,no代表不显示滚动条
  51. end:function () {
  52. table.reload('tablereload');
  53. }
  54. });
  55. } else if(layEvent === 'del') {
  56. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  57. $.post('/dictionary/newsdel',{'id':data.id,'del':2},function (data) {
  58. table.reload('tablereload');
  59. })
  60. })
  61. }
  62. });
  63. var $ = layui.$, active = {
  64. addData: function(){ //获取选中数据
  65. layer.open({
  66. type: 2,
  67. title: '添加栏目',
  68. closeBtn: 1, //不显示关闭按钮
  69. shade: [0],
  70. area: ['600px', '500px'],
  71. anim: 2,
  72. content: '/usersignup/labeladd', //iframe的url,no代表不显示滚动条
  73. end:function () {
  74. table.reload('tablereload');
  75. }
  76. });
  77. // var checkStatus = table.checkStatus('idTest')
  78. // ,data = checkStatus.data;
  79. // layer.alert(JSON.stringify(data));
  80. }, reload:function () {
  81. var form = pfgs_serialize($('form'));
  82. var name = '';
  83. var source_id = '';
  84. if(form.input_house == 'name'){
  85. name = form.input_house_text;
  86. } else if(form.input_house == 'source_id'){
  87. source_id = form.input_house_text;
  88. }
  89. table.reload('tablereload',{
  90. where:{
  91. source_id:source_id,
  92. name:name,
  93. type:form.type
  94. },
  95. page:{ //重载分页
  96. curr:1
  97. }
  98. })
  99. }
  100. };
  101. $('.demoTable .layui-btn').on('click', function(){
  102. var type = $(this).data('type');
  103. active[type] ? active[type].call(this) : '';
  104. });
  105. //修改
  106. form.on('submit(editnews)', function(data){
  107. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8});
  108. $.post('/usersignup/labeleditform',{'data':data.field,'token':csrfToken},function (data) {
  109. if(data.data != null){
  110. layer.msg(ReturnInfo(data.data),{icon:5});
  111. return ;
  112. }
  113. layer.msg(data.msg);
  114. TableClose();
  115. })
  116. return false;
  117. });
  118. //添加
  119. form.on('submit(addnews)', function(data){
  120. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8});
  121. $.post('/usersignup/labeladdform',{'data':data.field,'token':csrfToken},function (data) {
  122. if(data.data != null){
  123. layer.msg(ReturnInfo(data.data),{icon:5});
  124. return ;
  125. }
  126. layer.msg(data.msg);
  127. TableClose();
  128. })
  129. return false;
  130. });
  131. //监听指定开关
  132. form.on('switch(switchTest)', function(data){
  133. console.log(data);
  134. var stateValue = data.elem.attributes.name.value;
  135. console.log(stateValue);
  136. layer.confirm('确定要删除吗?',{btn: ['确定', '取消']},function () {
  137. switch (stateValue) {
  138. case '1':
  139. stateValue = 2;
  140. break;
  141. case '2':
  142. stateValue = 1;
  143. break;
  144. }
  145. $.post('/usersignup/labeleditform',{'data':{'id':data.value
  146. ,'state':stateValue},'token':csrfToken},function (data) {
  147. if(data.data != null){
  148. layer.msg(ReturnInfo(data.data),{icon:5});
  149. return ;
  150. }
  151. layer.msg(data.msg);
  152. table.reload('tablereload');
  153. })
  154. },function () {
  155. table.reload('tablereload');
  156. })
  157. });
  158. });