hainanvillegl.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. layui.use(['layer', 'table', 'element', 'form'], function () {
  2. var $ = layui.jquery
  3. , layer = layui.layer //弹层
  4. , table = layui.table //表格
  5. , form = layui.form
  6. var previd = $('#previd').val();
  7. var tableIns = table.render({
  8. elem: '#hainanvillelist',
  9. url: '/zt/hainanvilleglform?previd='+previd,
  10. method: 'get',
  11. page: false,
  12. id: 'tablerReload',
  13. cols: [[
  14. {type: 'numbers', title: '序号'},
  15. {field: 'title', title: '湾区', width: 400, align: "center"},
  16. {field: 'name', title: '楼盘名称', width: 400, align: "center"},
  17. {
  18. field: 'sort',
  19. title: '排序',
  20. width: 100,
  21. event: 'sortData',
  22. edit: 'text',
  23. align: 'center',
  24. sort: true,
  25. templet: "#sortBox"
  26. },
  27. {
  28. field: 'state', title: '状态', align: 'center', templet: function (d) {
  29. if (d.state == 1) {
  30. return '<input type="checkbox" checked value="' + d.id + '" data-state="2" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  31. } else {
  32. return '<input type="checkbox" value="' + d.id + '" data-state="1" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  33. }
  34. }
  35. },
  36. {title: '操作', templet: '#hainanvillefunc', fixed: "right", align: "center"}
  37. ]]
  38. });
  39. table.reload('tablerReload'); //重新加载
  40. //表格头部操作菜单
  41. var $ = layui.$, active = {
  42. addData: function () {
  43. var index = layui.layer.open({
  44. title: "添加关联楼盘",
  45. type: 2,
  46. area: ['70%', '50%'],
  47. content: '/zt/hainanvillegladd?previd='+ previd,
  48. })
  49. },
  50. };
  51. $('.demoTable .layui-btn').on('click', function () {
  52. var type = $(this).data('type');
  53. active[type] ? active[type].call(this) : '';
  54. });
  55. //监听指定开关
  56. form.on('switch(switchTest)', function (data) {
  57. var id = $(this).val();
  58. var state = $(this).data('state');
  59. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  60. $.post('/zt/gulfcityglstate', {id: id, state: state}, function (data) {
  61. if (data.code == 200) {
  62. layer.msg(data.msg);
  63. table.reload('tablerReload');
  64. } else if (data.code == 300) {
  65. layer.msg(data.msg);
  66. }
  67. })
  68. }, function (aa) {
  69. table.reload('tablerReload'); //重新加载
  70. })
  71. });
  72. //排序
  73. table.on('edit(hainanvillelist)', function (obj) {
  74. var data = obj.data;
  75. $.post('/zt/gulfcityglsort', {id: data.id, sort: data.sort}, function (data) {
  76. if (data.code == 200) {
  77. layer.msg(data.msg);
  78. } else if (data.code == 300) {
  79. layer.msg(data.msg);
  80. }
  81. })
  82. })
  83. //表格右边操作栏目
  84. table.on('tool(hainanvillelist)', function (obj) {
  85. var data = obj.data;
  86. var id = data.id;
  87. if (obj.event === 'del') { //删除操作
  88. layer.confirm('确定要删除吗?', {btn: ['确定', '取消']}, function () {
  89. $.post('/zt/gulfcitygldel', {id: id}, function (data) {
  90. if (data.code == 200) {
  91. layer.msg(data.msg);
  92. table.reload('tablerReload');
  93. } else if (data.code == 300) {
  94. layer.msg(data.msg);
  95. }
  96. })
  97. })
  98. } else if (obj.event === 'edit') {//修改排序
  99. var index = layui.layer.open({
  100. title: "编辑楼盘",
  101. type: 2,
  102. area: ['70%', '50%'],
  103. content: '/zt/gulfcitygledit?id='+id,
  104. })
  105. }
  106. })
  107. $('.The_house').focus(function(){
  108. indexOpen = parent.layui.layer.open({
  109. type: 2,
  110. title: '选择需要添加的楼盘',
  111. area: ['','100%'],
  112. content: '/publicuse/housenamecn?type=1',
  113. success:function (layero, index) {
  114. },
  115. end:function(){
  116. }
  117. });
  118. parent.layui.layer.full(indexOpen);
  119. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  120. $(window).on("resize",function(){
  121. parent.layui.layer.full(indexOpen);
  122. })
  123. })
  124. form.on('submit(add_hainanville)', function (data) {
  125. $.post('/zt/hainanvillegladdto', {'data': data.field}, function (data) {
  126. if (data.code == 200) {
  127. layer.msg(data.msg);
  128. var index = parent.layer.getFrameIndex(window.name);
  129. parent.layer.close(index);
  130. window.parent.location.reload();
  131. }
  132. })
  133. return false;
  134. });
  135. form.on('submit(edit_hainanville)', function (data) {
  136. $.post('/zt/hainanvillegleditto', {'data': data.field}, function (data) {
  137. if (data.code == 200) {
  138. console.log(data.msg)
  139. layer.msg(data.msg);
  140. var index = parent.layer.getFrameIndex(window.name);
  141. parent.layer.close(index);
  142. window.parent.location.reload();
  143. }
  144. })
  145. return false;
  146. });
  147. })