label.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. ,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: 'name', 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('/dictionarya/labeldel',{'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: '/dictionarya/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. $.post('/dictionarya/labeladdform',{'data':data.field,'token':csrfToken},function (data) {
  91. if(data.code == 200)
  92. {
  93. layer.msg(data.msg);
  94. $("input[name='name']").val('');
  95. } else if(data.code == 300 ) {
  96. layer.msg(data.msg);
  97. }
  98. })
  99. return false;
  100. });
  101. });