gulfcitygl.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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').data('id');
  7. var tableIns = table.render({
  8. elem: '#gulfcitygllist',
  9. url: '/zt/gulfcityglform?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: '#gulfcityglfunc', fixed: "right", align: "center"}
  37. ]]
  38. });
  39. table.reload('tablerReload'); //重新加载
  40. //表格头部操作菜单
  41. var $ = layui.$, active = {
  42. addData: function () {
  43. var id = $(this).data('id');
  44. var index = layui.layer.open({
  45. title: "添加湾区导航",
  46. type: 2,
  47. area: ['70%', '50%'],
  48. content: '/zt/gulfcitygladd?id='+id,
  49. })
  50. },
  51. };
  52. $('.demoTable .layui-btn').on('click', function () {
  53. var type = $(this).data('type');
  54. active[type] ? active[type].call(this) : '';
  55. });
  56. //监听指定开关
  57. form.on('switch(switchTest)', function (data) {
  58. var id = $(this).val();
  59. var state = $(this).data('state');
  60. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  61. $.post('/zt/gulfcityglstate', {id: id, state: state}, function (data) {
  62. if (data.code == 200) {
  63. layer.msg(data.msg);
  64. table.reload('tablerReload');
  65. } else if (data.code == 300) {
  66. layer.msg(data.msg);
  67. }
  68. })
  69. }, function (aa) {
  70. table.reload('tablerReload'); //重新加载
  71. })
  72. });
  73. //排序
  74. table.on('edit(gulfcitygllist)', function (obj) {
  75. var data = obj.data;
  76. $.post('/zt/gulfcityglsort', {id: data.id, sort: data.sort}, function (data) {
  77. if (data.code == 200) {
  78. layer.msg(data.msg);
  79. } else if (data.code == 300) {
  80. layer.msg(data.msg);
  81. }
  82. })
  83. })
  84. //表格右边操作栏目
  85. table.on('tool(gulfcitygllist)', function (obj) {
  86. var data = obj.data;
  87. var id = data.id;
  88. if (obj.event === 'del') { //删除操作
  89. layer.confirm('确定要删除吗?', {btn: ['确定', '取消']}, function () {
  90. $.post('/zt/gulfcitygldel', {id: id}, function (data) {
  91. if (data.code == 200) {
  92. layer.msg(data.msg);
  93. table.reload('tablerReload');
  94. } else if (data.code == 300) {
  95. layer.msg(data.msg);
  96. }
  97. })
  98. })
  99. } else if (obj.event === 'edit') {//修改排序
  100. var index = layui.layer.open({
  101. title: "添加湾区导航",
  102. type: 2,
  103. area: ['70%', '50%'],
  104. content: '/zt/gulfcitygledit?id='+id,
  105. })
  106. }
  107. })
  108. $('.The_house').focus(function(){
  109. indexOpen = parent.layui.layer.open({
  110. type: 2,
  111. title: '选择需要添加的楼盘',
  112. area: ['','100%'],
  113. content: '/publicuse/housenamecn?type=1',
  114. success:function (layero, index) {
  115. },
  116. end:function(){
  117. }
  118. });
  119. parent.layui.layer.full(indexOpen);
  120. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  121. $(window).on("resize",function(){
  122. parent.layui.layer.full(indexOpen);
  123. })
  124. })
  125. form.on('submit(add_hainanville)', function (data) {
  126. $.post('/zt/gulfcitygladdto', {'data': data.field}, function (data) {
  127. if (data.code == 200) {
  128. layer.msg(data.msg);
  129. var index = parent.layer.getFrameIndex(window.name);
  130. parent.layer.close(index);
  131. window.parent.location.reload();
  132. }
  133. })
  134. return false;
  135. });
  136. form.on('submit(edit_hainanville)', function (data) {
  137. $.post('/zt/gulfcitygleditto', {'data': data.field}, function (data) {
  138. if (data.code == 200) {
  139. console.log(data.msg)
  140. layer.msg(data.msg);
  141. var index = parent.layer.getFrameIndex(window.name);
  142. parent.layer.close(index);
  143. window.parent.location.reload();
  144. }
  145. })
  146. return false;
  147. });
  148. })