hainanville.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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: '#hainanvillelist',
  8. url: '/zt/hainanvilleform',
  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: '#hainanvillefunc', 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/hainanvilleadd',
  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/hainanvillestate', {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(hainanvillelist)', function (obj) {
  72. var data = obj.data;
  73. $.post('/zt/hainanvillesort', {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(hainanvillelist)', function (obj) {
  83. var data = obj.data;
  84. var id = data.id;
  85. if (obj.event === 'del') { //删除操作
  86. layer.confirm('确定要删除吗?', {btn: ['确定', '取消']}, function () {
  87. $.post('/zt/hainanvilledel', {id: id}, function (data) {
  88. if (data.code == 200) {
  89. layer.msg(data.msg);
  90. table.reload('tablerReload');
  91. } else if (data.code == 300) {
  92. layer.msg(data.msg);
  93. }
  94. })
  95. })
  96. } else if (obj.event === 'edit') {//修改排序
  97. var index = layui.layer.open({
  98. title: "添加导航地区",
  99. type: 2,
  100. area: ['70%', '50%'],
  101. content: '/zt/hainanvilleedit?id='+id,
  102. })
  103. }else if(obj.event === 'gl'){
  104. var index = layui.layer.open({
  105. title: "关联楼盘",
  106. type: 2,
  107. area: ['100%', '100%'],
  108. content: '/zt/hainanvillegl?id='+id,
  109. })
  110. parent.layui.layer.full(index);
  111. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  112. $(window).on("resize",function(){
  113. parent.layui.layer.full(indexOpen);
  114. })
  115. }
  116. })
  117. $('.The_house').focus(function(){
  118. indexOpen = parent.layui.layer.open({
  119. type: 2,
  120. title: '选择需要添加的区域',
  121. area: ['','100%'],
  122. content: '/publicuse/cncity?type=1',
  123. success:function (layero, index) {
  124. },
  125. end:function(){
  126. }
  127. });
  128. parent.layui.layer.full(indexOpen);
  129. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  130. $(window).on("resize",function(){
  131. parent.layui.layer.full(indexOpen);
  132. })
  133. })
  134. form.on('submit(add_hainanville)', function (data) {
  135. $.post('/zt/tohainanvilleadd', {'data': data.field}, function (data) {
  136. if (data.code == 200) {
  137. layer.msg(data.msg);
  138. var index = parent.layer.getFrameIndex(window.name);
  139. parent.layer.close(index);
  140. window.parent.location.reload();
  141. }
  142. })
  143. return false;
  144. });
  145. form.on('submit(edit_hainanville)', function (data) {
  146. $.post('/zt/tohainanvilleedit', {'data': data.field}, function (data) {
  147. if (data.code == 200) {
  148. layer.msg(data.msg);
  149. var index = parent.layer.getFrameIndex(window.name);
  150. parent.layer.close(index);
  151. window.parent.location.reload();
  152. }
  153. })
  154. return false;
  155. });
  156. })