label.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 = 'laballist'; //表格ID
  8. var reloadId = 'tablerReload';
  9. //第一个实例
  10. var tableIns = table.render({
  11. elem: '#'+tableIds
  12. ,url: '/knowledge/labelform' //数据接口
  13. ,where:{token:csrfToken}
  14. ,method:'post'
  15. ,page: true //开启分页
  16. ,height:600
  17. ,text:'数据加载中'
  18. ,id:reloadId
  19. ,limit:20
  20. ,cols: [[ //表头
  21. {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  22. // {type:'numbers'},
  23. {field: 'label', title: '标签类型', align:'center'}
  24. ,{fixed: 'right',title:'操作', width: 180, align:'center', toolbar: '#operate'}
  25. ]]
  26. });
  27. table.reload('tablerReload'); //重新加载
  28. //列表操作
  29. table.on('tool('+tableIds+')', function(obj){
  30. var layEvent = obj.event,
  31. data = obj.data;
  32. if(layEvent === 'edit'){
  33. layer.open({
  34. type: 2,
  35. title: '修改标签',
  36. area: ['600px', '500px'],
  37. content: '/dictionarya/labeledit?id='+data.id, //iframe的url,no代表不显示滚动条
  38. end:function(){
  39. table.reload('tablerReload');
  40. }
  41. });
  42. } else if(layEvent === 'del') {
  43. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  44. $.post('/knowledge/labeldelshow',{'id':data.id},function (data) {
  45. if(data.code == 200)
  46. {
  47. layer.msg(data.msg);
  48. table.reload('tablerReload');
  49. } else if(data.code == 300 ) {
  50. layer.msg(data.msg);
  51. }
  52. })
  53. })
  54. }
  55. });
  56. var $ = layui.$, active = {
  57. addData: function(){ //获取选中数据
  58. layer.open({
  59. type: 2,
  60. title: '添加标签',
  61. area: ['600px', '500px'],
  62. content: '/knowledge/labeladd', //iframe的url,no代表不显示滚动条
  63. end:function(){
  64. table.reload('tablerReload');
  65. }
  66. });
  67. // var checkStatus = table.checkStatus('idTest')
  68. // ,data = checkStatus.data;
  69. // layer.alert(JSON.stringify(data));
  70. }
  71. };
  72. $('.demoTable .layui-btn').on('click', function(){
  73. var type = $(this).data('type');
  74. active[type] ? active[type].call(this) : '';
  75. });
  76. //修改
  77. form.on('submit(editlabel)', function(data){
  78. $.post('/dictionarya/labeleditform',{'data':data.field,'token':csrfToken},function (data) {
  79. if(data.code == 200)
  80. {
  81. layer.msg(data.msg);
  82. } else if(data.code == 300 ) {
  83. layer.msg(data.msg);
  84. }
  85. })
  86. return false;
  87. });
  88. //添加
  89. form.on('submit(addlabel)', function(data){
  90. var formData = new FormData($('form')[0]);
  91. // $.post('/knowledge/labeladdform',{data:formData},function (data) {
  92. // if(data.code == 200)
  93. // {
  94. // layer.msg(data.msg);
  95. // $("input[name='name']").val('');
  96. // } else if(data.code == 300 ) {
  97. // layer.msg(data.msg);
  98. // }
  99. // })
  100. // return false;
  101. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  102. $.ajax({
  103. cache : false,
  104. type : "post",
  105. url : "/knowledge/labeladdform",
  106. data : formData, // 你的formid
  107. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  108. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  109. error : function(request) {
  110. layer.close(index);
  111. layer.msg("请联系管理员");
  112. },
  113. success : function(data) {
  114. if(data.data != null){
  115. layer.msg(ReturnInfo(data.data),{icon:5});
  116. return ;
  117. }
  118. layer.msg(data.msg);
  119. }
  120. });
  121. return false;
  122. });
  123. });