label.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. ,height:600
  16. ,text:'数据加载中'
  17. ,id:'tablereload'
  18. ,cols: [[ //表头
  19. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  20. {field: 'name', title: '来源名称', align:'center'}
  21. ,{field: 'type', title: '来源设备', align:'center'}
  22. ,{field: 'source_id', title: '文档ID',align:'center'}
  23. ,{field: 'create_at', title: '添加时间', align:'center'}
  24. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  25. ]]
  26. });
  27. //列表操作
  28. table.on('tool('+tableIds+')', function(obj){
  29. var layEvent = obj.event,
  30. data = obj.data;
  31. if(layEvent === 'edit'){
  32. layer.open({
  33. type: 2,
  34. title: '编辑报名来源信息',
  35. closeBtn: 1, //不显示关闭按钮
  36. shade: [0],
  37. area: ['600px', '500px'],
  38. anim: 2,
  39. content: '/usersignup/labeledit?id='+data.id, //iframe的url,no代表不显示滚动条
  40. end:function () {
  41. table.reload('tablereload');
  42. }
  43. });
  44. } else if(layEvent === 'del') {
  45. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  46. data.del = 2;
  47. $.post('/usersignup/labeleditform',{data:data},function (data) {
  48. layer.msg(data.msg);
  49. table.reload('tablereload');
  50. })
  51. })
  52. }
  53. });
  54. var $ = layui.$, active = {
  55. addData: function(){ //获取选中数据
  56. layer.open({
  57. type: 2,
  58. title: '添加资讯分类',
  59. closeBtn: 1, //不显示关闭按钮
  60. shade: [0],
  61. area: ['600px', '500px'],
  62. anim: 2,
  63. content: '/usersignup/labeladd', //iframe的url,no代表不显示滚动条
  64. end:function () {
  65. table.reload('tablereload');
  66. }
  67. });
  68. // var checkStatus = table.checkStatus('idTest')
  69. // ,data = checkStatus.data;
  70. // layer.alert(JSON.stringify(data));
  71. },
  72. reload:function () {
  73. var form = pfgs_serialize($('form'));
  74. var name = '';
  75. var id = '';
  76. if(form.input_house == 'name'){
  77. name = form.input_house_text;
  78. } else if(form.input_house == 'id'){
  79. id = form.input_house_text;
  80. }
  81. table.reload('tablereload',{
  82. where:{
  83. type:form.type,
  84. name:name,
  85. source_id:id
  86. },
  87. page:{
  88. curr:1
  89. }
  90. })
  91. }
  92. };
  93. $('.demoTable .layui-btn').on('click', function(){
  94. var type = $(this).data('type');
  95. active[type] ? active[type].call(this) : '';
  96. });
  97. //修改
  98. form.on('submit(editnews)', function(data){
  99. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8});
  100. $.post('/usersignup/labeleditform',{'data':data.field,'token':csrfToken},function (data) {
  101. if(data.data != null){
  102. layer.msg(ReturnInfo(data.data),{icon:5});
  103. return ;
  104. }
  105. layer.msg(data.msg);
  106. TableClose();
  107. })
  108. return false;
  109. });
  110. //添加
  111. form.on('submit(addnews)', function(data){
  112. layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8});
  113. $.post('/usersignup/labeladdform',{'data':data.field,'token':csrfToken},function (data) {
  114. if(data.data != null){
  115. layer.msg(ReturnInfo(data.data),{icon:5});
  116. return ;
  117. }
  118. layer.msg(data.msg);
  119. TableClose();
  120. })
  121. return false;
  122. });
  123. });