theme.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 = 'themelist'; //表格ID
  8. var reloadId = 'tablerReload';
  9. //第一个实例
  10. table.render({
  11. elem: '#'+tableIds
  12. ,url: '/dictionarya/themeform' //数据接口
  13. ,where:{token:csrfToken}
  14. ,method:'post'
  15. ,page: true //开启分页
  16. ,text:'数据加载中'
  17. ,id:reloadId
  18. ,cols: [[ //表头
  19. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  20. {type:'numbers'},
  21. {field: 'name', title: '特色主题',align:'center'}
  22. ,{field: 'update_at', title: '更新时间', width:150,align:'center'}
  23. ,{field: 'create_at', title: '添加时间', width:150,align:'center'}
  24. ,{fixed: 'right',title:'操作', width: 165, 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. closeBtn: 1, //不显示关闭按钮
  37. shade: [0],
  38. area: ['600px', '500px'],
  39. anim: 2,
  40. content: '/dictionarya/themeedit?id='+data.id, //iframe的url,no代表不显示滚动条
  41. end:function(){
  42. table.reload('tablerReload');
  43. }
  44. });
  45. } else if(layEvent === 'del') {
  46. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  47. $.post('/dictionarya/themedel',{'id':data.id},function (data) {
  48. if(data.code == 200)
  49. {
  50. layer.msg(data.msg);
  51. table.reload('tablerReload');
  52. } else if(data.code == 300 ) {
  53. layer.msg(data.msg);
  54. }
  55. })
  56. })
  57. }
  58. });
  59. var $ = layui.$, active = {
  60. addData: function(){ //获取选中数据
  61. layer.open({
  62. type: 2,
  63. title: '添加特色主题',
  64. area: ['600px', '500px'],
  65. content: '/dictionarya/themeadd', //iframe的url,no代表不显示滚动条
  66. end:function(){
  67. table.reload('tablerReload');
  68. }
  69. });
  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(edittheme)', function(data){
  78. $.post('/dictionarya/themeeditform',{'data':data.field},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(addtheme)', function(data){
  90. $.post('/dictionarya/themeaddform',{'data':data.field},function (data) {
  91. if(data.code == 200)
  92. {
  93. layer.msg(data.msg);
  94. $('input').val('');
  95. } else if(data.code == 300 ) {
  96. layer.msg(data.msg);
  97. }
  98. })
  99. return false;
  100. });
  101. });