label.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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: '/dictionarya/labelform' //数据接口
  13. ,where:{token:csrfToken}
  14. ,method:'post'
  15. ,page: true //开启分页
  16. ,text:'数据加载中'
  17. ,id:reloadId
  18. ,limit:20
  19. ,cols: [[ //表头
  20. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  21. {type:'numbers'},
  22. {field: 'name', title: '物业类型', align:'center'}
  23. ,{fixed: 'right',title:'操作', width: 180, align:'center', toolbar: '#operate'}
  24. ]]
  25. });
  26. table.reload('tablerReload'); //重新加载
  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. area: ['600px', '500px'],
  36. content: '/dictionarya/labeledit?id='+data.id, //iframe的url,no代表不显示滚动条
  37. end:function(){
  38. table.reload('tablerReload');
  39. }
  40. });
  41. } else if(layEvent === 'del') {
  42. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  43. $.post('/dictionarya/labeldel',{'id':data.id},function (data) {
  44. if(data.code == 200)
  45. {
  46. layer.msg(data.msg);
  47. table.reload('tablerReload');
  48. } else if(data.code == 300 ) {
  49. layer.msg(data.msg);
  50. }
  51. })
  52. })
  53. }
  54. });
  55. var $ = layui.$, active = {
  56. addData: function(){ //获取选中数据
  57. layer.open({
  58. type: 2,
  59. title: '添加标签',
  60. area: ['600px', '500px'],
  61. content: '/dictionarya/labeladd', //iframe的url,no代表不显示滚动条
  62. end:function(){
  63. table.reload('tablerReload');
  64. }
  65. });
  66. // var checkStatus = table.checkStatus('idTest')
  67. // ,data = checkStatus.data;
  68. // layer.alert(JSON.stringify(data));
  69. }
  70. };
  71. $('.demoTable .layui-btn').on('click', function(){
  72. var type = $(this).data('type');
  73. active[type] ? active[type].call(this) : '';
  74. });
  75. //修改
  76. form.on('submit(editlabel)', function(data){
  77. $.post('/dictionarya/labeleditform',{'data':data.field,'token':csrfToken},function (data) {
  78. if(data.code == 200)
  79. {
  80. layer.msg(data.msg);
  81. } else if(data.code == 300 ) {
  82. layer.msg(data.msg);
  83. }
  84. })
  85. return false;
  86. });
  87. //添加
  88. form.on('submit(addlabel)', function(data){
  89. $.post('/dictionarya/labeladdform',{'data':data.field,'token':csrfToken},function (data) {
  90. if(data.code == 200)
  91. {
  92. layer.msg(data.msg);
  93. $("input[name='name']").val('');
  94. } else if(data.code == 300 ) {
  95. layer.msg(data.msg);
  96. }
  97. })
  98. return false;
  99. });
  100. });