house.js 5.6 KB

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