photoalbum.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 = 'photoalbumlist';
  8. //第一个实例
  9. table.render({
  10. elem: '#'+tableIds
  11. ,url: '/dictionary/photoalbumform' //数据接口
  12. ,where:{token:csrfToken}
  13. ,method:'post'
  14. ,page: true //开启分页
  15. ,text:'数据加载中'
  16. ,id:'tablerReload'
  17. ,cols: [[ //表头
  18. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  19. {type:'numbers'},
  20. {field: 'name', title: '相册分类名称', align:'center'}
  21. ,{field: 'sort', title: '排序',width:80, edit: 'text',align:'center',sort: true,templet:"#sortBox"}
  22. ,{field: 'is_show', title: '审核',width:100, align:'center', templet:"#Toexamine",templet:function(d){
  23. if(d.is_show == 2){
  24. return '<input type="checkbox" value="'+d.id+'" name="'+d.is_show+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  25. } else {
  26. return '<input type="checkbox" checked value="'+d.id+'" name="'+d.is_show+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  27. }
  28. }}
  29. ,{field: 'update_at', title: '更新时间', width:200,align:'center'}
  30. ,{field: 'create_at', title: '添加时间', width:200,align:'center'}
  31. ,{fixed: 'right',title:'操作', width: 180, align:'center', toolbar: '#operate'}
  32. ]]
  33. });
  34. table.reload('tablerReload'); //重新加载
  35. /* 列表操作 edit 修改后执行 */
  36. table.on('edit('+tableIds+')', function(obj){
  37. var data = obj.data;
  38. if(obj.field=="sort"){
  39. $.post('/dictionary/photoalbumdel',{id:data.id,sort:data.sort,type:'sort'},function (data) {
  40. if(data.code == 200)
  41. {
  42. layer.msg(data.msg);
  43. } else if(data.code == 300 ) {
  44. layer.msg(data.msg);
  45. }
  46. })
  47. }
  48. })
  49. //显示或隐藏
  50. form.on('switch(switchTest)', function(data){
  51. var state = '';
  52. if(data.elem.name == 1){
  53. state = 2;
  54. }else if(data.elem.name == 2){
  55. state = 1;
  56. }
  57. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  58. $.post('/dictionary/photoalbumdel',{id:data.value,type:'is_show',is_show:state},function (data) {
  59. if(data.data != null){
  60. layer.msg(data.msg);
  61. return false;
  62. }
  63. layer.msg(data.msg);
  64. table.reload('tablerReload');
  65. })
  66. },function (aa) {
  67. table.reload('tablerReload');
  68. })
  69. });
  70. //列表操作
  71. table.on('tool('+tableIds+')', function(obj){
  72. var layEvent = obj.event,
  73. data = obj.data;
  74. if(layEvent === 'edit'){
  75. layer.open({
  76. type: 2,
  77. title: '修改户型',
  78. closeBtn: 1, //不显示关闭按钮
  79. shade: [0],
  80. area: ['600px', '500px'],
  81. anim: 2,
  82. content: ['/dictionary/photoalbumedit?id='+data.id, 'yes'], //iframe的url,no代表不显示滚动条
  83. });
  84. } else if(layEvent === 'del') {
  85. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  86. $.post('/dictionary/photoalbumdel',{'id':data.id,type:'del'},function (data) {
  87. if(data.code == 200)
  88. {
  89. layer.msg(data.msg);
  90. table.reload('tablerReload');
  91. } else if(data.code == 300 ) {
  92. layer.msg(data.msg);
  93. }
  94. })
  95. })
  96. }
  97. });
  98. var $ = layui.$, active = {
  99. addData: function(){ //获取选中数据
  100. layer.open({
  101. type: 2,
  102. title: '添加相册分类',
  103. closeBtn: 1, //不显示关闭按钮
  104. shade: [0],
  105. area: ['600px', '500px'],
  106. anim: 2,
  107. content: ['/dictionary/photoalbumadd', 'yes'], //iframe的url,no代表不显示滚动条
  108. });
  109. // var checkStatus = table.checkStatus('idTest')
  110. // ,data = checkStatus.data;
  111. // layer.alert(JSON.stringify(data));
  112. }
  113. };
  114. $('.demoTable .layui-btn').on('click', function(){
  115. var type = $(this).data('type');
  116. active[type] ? active[type].call(this) : '';
  117. });
  118. //修改
  119. form.on('submit(editphotoalbum)', function(data){
  120. $.post('/dictionary/photoalbumeditform',{'data':data.field,'token':csrfToken},function (data) {
  121. if(data.code == 200)
  122. {
  123. layer.msg(data.msg);
  124. parent.layui.table.reload(tableIds);
  125. TableClose();
  126. } else if(data.code == 300 ) {
  127. layer.msg(data.msg);
  128. }
  129. })
  130. return false;
  131. });
  132. //添加
  133. form.on('submit(addphotoalbum)', function(data){
  134. $.post('/dictionary/photoalbumaddform',{'data':data.field,'token':csrfToken},function (data) {
  135. if(data.code == 200)
  136. {
  137. layer.msg(data.msg);
  138. parent.layui.table.reload(tableIds);
  139. } else if(data.code == 300 ) {
  140. layer.msg(data.msg);
  141. }
  142. })
  143. return false;
  144. });
  145. });