boutiquevilla.js 5.7 KB

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