theme.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. ,height : 600
  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. ,{field: 'update_at', title: '更新时间', width:150,align:'center'}
  25. ,{field: 'create_at', title: '添加时间', width:150,align:'center'}
  26. ,{field: 'is_view', title: '审核',width:100, align:'center', templet:"#Toexamine",templet:function(d){
  27. switch (d.is_show){
  28. case '2':
  29. return '<input type="checkbox" value="'+d.id+'" name="'+d.is_show+'" house="'+d.name+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  30. break;
  31. case '1':
  32. return '<input type="checkbox" checked value="'+d.id+'" name="'+d.is_show+'" house="'+d.name+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  33. break;
  34. }
  35. }}
  36. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  37. ]]
  38. });
  39. table.reload('tablerReload'); //重新加载
  40. //列表操作
  41. table.on('tool('+tableIds+')', function(obj){
  42. var layEvent = obj.event,
  43. data = obj.data;
  44. if(layEvent === 'edit'){
  45. layer.open({
  46. type: 2,
  47. title: '修改特色主题',
  48. closeBtn: 1, //不显示关闭按钮
  49. shade: [0],
  50. area: ['600px', '500px'],
  51. anim: 2,
  52. content: '/dictionarya/themeedit?id='+data.id, //iframe的url,no代表不显示滚动条
  53. end:function(){
  54. table.reload('tablerReload');
  55. }
  56. });
  57. } else if(layEvent === 'del') {
  58. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  59. $.post('/dictionarya/themedel',{'id':data.id},function (data) {
  60. if(data.code == 200)
  61. {
  62. layer.msg(data.msg);
  63. table.reload('tablerReload');
  64. } else if(data.code == 300 ) {
  65. layer.msg(data.msg);
  66. }
  67. })
  68. })
  69. }
  70. });
  71. var $ = layui.$, active = {
  72. addData: function(){ //获取选中数据
  73. layer.open({
  74. type: 2,
  75. title: '添加特色主题',
  76. area: ['600px', '500px'],
  77. content: '/dictionarya/themeadd', //iframe的url,no代表不显示滚动条
  78. end:function(){
  79. table.reload('tablerReload');
  80. }
  81. });
  82. }
  83. };
  84. $('.demoTable .layui-btn').on('click', function(){
  85. var type = $(this).data('type');
  86. active[type] ? active[type].call(this) : '';
  87. });
  88. //修改
  89. form.on('submit(edittheme)', function(data){
  90. $.post('/dictionarya/themeeditform',{'data':data.field},function (data) {
  91. if(data.code == 200)
  92. {
  93. layer.msg(data.msg);
  94. } else if(data.code == 300 ) {
  95. layer.msg(data.msg);
  96. }
  97. })
  98. return false;
  99. });
  100. //添加
  101. form.on('submit(addtheme)', function(data){
  102. $.post('/dictionarya/themeaddform',{'data':data.field},function (data) {
  103. if(data.code == 200)
  104. {
  105. layer.msg(data.msg);
  106. $('input').val('');
  107. } else if(data.code == 300 ) {
  108. layer.msg(data.msg);
  109. }
  110. })
  111. return false;
  112. });
  113. //显示或隐藏
  114. form.on('switch(switchTest)', function(data){
  115. var state = '';
  116. if(data.elem.name == 1){
  117. state = 2;
  118. }else if(data.elem.name == 2){
  119. state = 1;
  120. }
  121. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  122. $.post('/dictionarya/themeshow',{id:data.value,state:state},function (data) {
  123. if(data.data != null){
  124. layer.msg(ReturnInfo(data.data),{icon:5});
  125. return false;
  126. }
  127. layer.msg(data.msg);
  128. renderTable();
  129. })
  130. },function (aa) {
  131. renderTable();
  132. })
  133. });
  134. });