house.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload'], function(){
  2. var laypage = layui.laypage //分页
  3. ,$ = layui.jquery
  4. ,layer = layui.layer //弹层
  5. ,table = layui.table //表格
  6. ,element = layui.element //元素操作
  7. ,form = layui.form
  8. ,upload = layui.upload;
  9. var inputId = $('input[name="Bid"]').val();
  10. var tableIds = 'houselist'; //表格ID
  11. //第一个实例
  12. table.render({
  13. elem: '#'+tableIds
  14. ,url: '/brand/houseform' //数据接口
  15. ,where:{token:csrfToken,bid:inputId}
  16. ,method:'post'
  17. ,page: true //开启分页
  18. ,height:600
  19. ,text:'数据加载中'
  20. ,id:'tablerReload'
  21. ,limit:20
  22. ,cols: [[ //表头
  23. {type:'numbers',title:'序号',width:50},
  24. {field: 'city_name', title: '所属区域', width:180,align:'center'},
  25. {field: 'name', title: '楼盘名称',width:400,align:'center'},
  26. {field: 'developers', title: '开发商',align:'center'},
  27. {field: 'create_at', title: '添加时间',width:150, align:'center'},
  28. {field: 'is_show', title: '审核',align:'center',width:100, templet:function (d) {
  29. if(d.is_show == 2){
  30. return '<input type="checkbox" value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  31. } else {
  32. return '<input type="checkbox" checked value="'+d.id+'" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  33. }
  34. }},
  35. {fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  36. ]]
  37. });
  38. table.reload('tablerReload'); //重新加载
  39. //监听指定开关
  40. form.on('switch(switchTest)', function(data){
  41. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  42. $.post('/brand/sethouse',{id:data.value,type:'show'},function (data) {
  43. layer.msg(data.msg);
  44. table.reload('tablerReload');
  45. })
  46. },function (aa) {
  47. table.reload('tablerReload'); //重新加载
  48. })
  49. });
  50. //列表操作
  51. table.on('tool('+tableIds+')', function(obj){
  52. var layEvent = obj.event,
  53. data = obj.data;
  54. if(layEvent === 'del'){
  55. layer.confirm('您确定要删除该楼盘吗?',{btn: ['确定', '取消']},function () {
  56. $.post('/brand/sethouse',{id:data.id,type:'del'},function (data) {
  57. layer.msg(data.msg);
  58. table.reload('tablerReload');
  59. })
  60. })
  61. }
  62. });
  63. // 新增
  64. var $ = layui.$, active = {
  65. addData: function(){ //获取选中数据
  66. var index = layui.layer.open({
  67. type: 2,
  68. title: '新增品牌楼盘',
  69. closeBtn: 1, //不显示关闭按钮
  70. area: ['700px','500px'],
  71. content: '/brand/houseadd?bid='+inputId //iframe的url,no代表不显示滚动条
  72. ,success:function (layero, index) {
  73. },
  74. end:function () {
  75. table.reload('tablerReload');
  76. }
  77. });
  78. },
  79. reload:function(){//搜索
  80. var form = pfgs_serialize($('form'));
  81. table.reload('tablerReload',{
  82. where:{
  83. name:form.input_house_text,
  84. city:form.input_city,
  85. }
  86. })
  87. },
  88. };
  89. $('.demoTable .layui-btn').on('click', function(){
  90. var type = $(this).data('type');
  91. active[type] ? active[type].call(this) : '';
  92. });
  93. $('.The_house').focus(function(){
  94. indexOpen = parent.layui.layer.open({
  95. type: 2,
  96. title: '选择需要添加的楼盘',
  97. area: ['','100%'],
  98. content: '/publicuse/housename',
  99. success:function (layero, index) {
  100. },
  101. end:function(){
  102. }
  103. });
  104. parent.layui.layer.full(indexOpen);
  105. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  106. $(window).on("resize",function(){
  107. parent.layui.layer.full(indexOpen);
  108. })
  109. })
  110. //新增页面提交数据
  111. form.on('submit(add_house)', function(data){
  112. var formData = new FormData($('form')[0]);
  113. var index = layer.msg('数据提交中,请稍候',{icon: 16,time:false,shade:0.8}); //数据提交提示
  114. $.ajax({
  115. cache : false,
  116. type : "post",
  117. url : "/brand/houseaddform",
  118. data : formData, // 你的formid
  119. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  120. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  121. error : function(request) {
  122. layer.close(index);
  123. layer.msg("请联系管理员");
  124. },
  125. success : function(data) {
  126. if(data.data != null){
  127. layer.msg(ReturnInfo(data.data),{icon:5});
  128. return ;
  129. }
  130. layer.msg(data.msg);
  131. }
  132. });
  133. return false;
  134. });
  135. })