housetype.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. //第一个实例
  8. table.render({
  9. elem: '#housetypelist'
  10. ,url: '/dictionary/housetypeform' //数据接口
  11. ,where:{token:csrfToken}
  12. ,method:'post'
  13. ,page: true //开启分页
  14. ,text:'数据加载中'
  15. ,id:'tablerReload'
  16. ,cols: [[ //表头
  17. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  18. {type:'numbers'},
  19. {field: 'huxing_name', title: '户型', align:'center'}
  20. ,{field: 'sort', title: '排序',width:200, event:'sortData',edit: 'text',align:'center',sort: true,templet:"#sortBox"}
  21. // ,{field: 'state', title: '地址', width:200,align:'center'}
  22. // ,{field: 'update_at', title: '更新时间', width:200,align:'center'}
  23. // ,{field: 'create_at', title: '添加时间', width:200,align:'center'}
  24. ,{field: 'state', title: '审核',align:'center',width:200, templet:function (d) {
  25. if(d.state == 2){
  26. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  27. } else {
  28. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  29. }
  30. }}
  31. ,{fixed: 'right',title:'操作', width: 180, align:'center', toolbar: '#operate'}
  32. ]]
  33. });
  34. table.reload('tablerReload'); //重新加载
  35. //监听指定开关
  36. form.on('switch(switchTest)', function(data){
  37. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  38. $.post('/dictionary/housetypestate',{id:data.value,type:'state'},function (data) {
  39. layer.msg(data.msg);
  40. table.reload('tablerReload');
  41. })
  42. },function (aa) {
  43. table.reload('tablerReload'); //重新加载
  44. })
  45. });
  46. //列表操作
  47. table.on('tool(housetypelist)', function(obj){
  48. var layEvent = obj.event,
  49. data = obj.data;
  50. if(layEvent === 'edit'){
  51. layer.open({
  52. type: 2,
  53. title: '修改户型',
  54. area: ['600px', '500px'],
  55. content:'/dictionary/housetypeedit?id='+data.id,
  56. end:function(){
  57. table.reload('tablerReload'); //重新加载
  58. }
  59. });
  60. } else if(layEvent === 'del') {
  61. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  62. $.post('/dictionary/hosttypedel',{'id':data.id},function (data) {
  63. if(data.code == 200)
  64. {
  65. layer.msg(data.msg);
  66. table.reload('tablerReload'); //重新加载
  67. } else if(data.code == 300 ) {
  68. layer.msg(data.msg);
  69. }
  70. })
  71. })
  72. }else if(layEvent === 'sortData'){ //修改排序
  73. table.on('edit(housetypelist)', function(obj){
  74. var data = obj.data;
  75. $.post('/dictionary/housetypesort',{id:data.id,type:'sort',sort:data.sort},function (data) {
  76. if(data.code == 200)
  77. {
  78. layer.msg(data.msg);
  79. } else if(data.code == 300 ) {
  80. layer.msg(data.msg);
  81. }
  82. })
  83. })
  84. }
  85. });
  86. var $ = layui.$, active = {
  87. addData: function(){ //获取选中数据
  88. layer.open({
  89. type: 2,
  90. title: '添加户型',
  91. area: ['600px', '500px'],
  92. content: '/dictionary/housetypeadd',
  93. end:function(){
  94. table.reload('tablerReload'); //重新加载
  95. }
  96. });
  97. // var checkStatus = table.checkStatus('idTest')
  98. // ,data = checkStatus.data;
  99. // layer.alert(JSON.stringify(data));
  100. }
  101. };
  102. $('.demoTable .layui-btn').on('click', function(){
  103. var type = $(this).data('type');
  104. active[type] ? active[type].call(this) : '';
  105. });
  106. //修改
  107. form.on('submit(edithousetype)', function(data){
  108. var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  109. $.post('/dictionary/housetypeeditform',{'data':data.field,'token':csrfToken},function (data) {
  110. top.layer.close(index); //关闭数据提交信息
  111. if(data.code == 200)
  112. {
  113. layer.msg(data.msg);
  114. // parent.layui.table.reload('housetypelist');
  115. // TableClose();
  116. } else if(data.code == 300 ) {
  117. layer.msg(data.msg);
  118. layer.msg(ReturnInfo(data.data));
  119. }
  120. })
  121. return false;
  122. });
  123. //添加
  124. form.on('submit(addhousetype)', function(data){
  125. var index = top.layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  126. $.post('/dictionary/housetypeaddform',{'data':data.field},function (data) {
  127. top.layer.close(index); //关闭数据提交信息
  128. if(data.code == 200)
  129. {
  130. layer.msg(data.msg);
  131. } else if(data.code == 300 ) {
  132. layer.msg(data.msg);
  133. layer.msg(ReturnInfo(data.data),{icon:5});
  134. }
  135. })
  136. return false;
  137. });
  138. });