officezt.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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: '#officeztlist',
  8. url: '/zt/officeztform',
  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: '#officeztfunc', 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/officeztadd',
  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(officeztlist)', 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(officeztlist)', 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 === 'edit') {
  98. var index = layui.layer.open({
  99. title: "专题地区修改",
  100. type: 2,
  101. area: ['70%', '50%'],
  102. content: '/zt/officeztedit?id='+id,
  103. })
  104. }else if (obj.event === 'gl') {
  105. var index = layui.layer.open({
  106. title: "<span style='color: red'>["+title+"]</span>相关楼盘",
  107. type: 2,
  108. area: ['100%', '100%'],
  109. content: '/zt/officeztgl?id='+id,
  110. })
  111. parent.layui.layer.full(index);
  112. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  113. $(window).on("resize",function(){
  114. parent.layui.layer.full(index);
  115. })
  116. }
  117. })
  118. $('.The_house').focus(function(){
  119. indexOpen = parent.layui.layer.open({
  120. type: 2,
  121. title: '选择需要添加的区域',
  122. area: ['','100%'],
  123. content: '/publicuse/cncity?type=1',
  124. success:function (layero, index) {
  125. },
  126. end:function(){
  127. }
  128. });
  129. parent.layui.layer.full(indexOpen);
  130. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  131. $(window).on("resize",function(){
  132. parent.layui.layer.full(indexOpen);
  133. })
  134. })
  135. form.on('submit(add_hainanville)', function (data) {
  136. $.post('/zt/officeztaddform', {'data': data.field}, function (data) {
  137. if (data.code == 200) {
  138. layer.msg(data.msg);
  139. var index = parent.layer.getFrameIndex(window.name);
  140. parent.layer.close(index);
  141. window.parent.location.reload();
  142. }else{
  143. layer.msg(data.msg);
  144. }
  145. })
  146. return false;
  147. });
  148. form.on('submit(edit_hainanville)', function (data) {
  149. $.post('/zt/tohainanvilleedit', {'data': data.field}, function (data) {
  150. if (data.code == 200) {
  151. console.log(data.msg)
  152. layer.msg(data.msg);
  153. var index = parent.layer.getFrameIndex(window.name);
  154. parent.layer.close(index);
  155. window.parent.location.reload();
  156. }
  157. })
  158. return false;
  159. });
  160. })