housenumber.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. layui.use(['laypage', 'layer', 'table', 'element', 'form', 'treetable', 'upload'], function () {
  2. var laypage = layui.laypage //分页
  3. , $ = layui.jquery
  4. , layer = layui.layer //弹层
  5. , table = layui.table //表格
  6. , element = layui.element //元素操作
  7. , form = layui.form
  8. , treetable = layui.treetable
  9. , upload = layui.upload;
  10. $('#feng_houseall').on('click', '.feng_houseallnamedel a', function () {
  11. var _this = $(this);
  12. _this.parent().parent().remove();
  13. })
  14. //第一个实例
  15. table.render({
  16. elem: '#menulist'
  17. , url: '/housenumber/indexform' //数据接口
  18. , where: {token: csrfToken}
  19. , method: 'post'
  20. , page: true //开启分页
  21. , id: 'tablerReload'
  22. , limit: 20
  23. , text: '数据加载中'
  24. , cols: [[ //表头
  25. , {field: 'id', width: 50, title: 'ID', align: 'center'}
  26. , {field: 'number', title: '楼盘号码', align: 'center'}
  27. , {field: 'explain', title: '号码说明', align: 'center'}
  28. , {field: 'hids', title: '楼盘ID', align: 'center'}
  29. , {field: 'create_at', width: 180, title: '添加时间', align: 'center'}
  30. , {
  31. field: 'is_show', title: '审核', align: 'center', width: 100, templet: function (d) {
  32. if (d.is_show == 2) {
  33. return '<input type="checkbox" value="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  34. } else {
  35. return '<input type="checkbox" checked value="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  36. }
  37. }
  38. }
  39. , {title: '操作', width: 200, align: 'center', toolbar: '#operate'}
  40. ]]
  41. });
  42. table.reload('tablerReload'); //重新加载
  43. //监听指定开关
  44. form.on('switch(switchTest)', function (data) {
  45. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  46. $.post('/housenumber/setnumber', {id: data.value, type: 'show'}, function (data) {
  47. layer.msg(data.msg);
  48. table.reload('tablerReload');
  49. })
  50. }, function (aa) {
  51. table.reload('tablerReload'); //重新加载
  52. })
  53. });
  54. //列表操作
  55. table.on('tool(menulist)', function (obj) {
  56. var layEvent = obj.event,
  57. data = obj.data;
  58. if (layEvent === 'edit') {
  59. layer.open({
  60. type: 2,
  61. title: '修改楼盘号码',
  62. closeBtn: 1, //不显示关闭按钮
  63. shade: [0],
  64. area: ['50%', '50%'],
  65. anim: 2,
  66. content: '/housenumber/edit?id=' + data.id,
  67. end: function () {
  68. table.reload('tablerReload');
  69. }
  70. });
  71. } else if (layEvent === 'del') {
  72. layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
  73. $.post('/housenumber/setnumber', {id: data.id, type: 'del'}, function (data) {
  74. layer.msg(data.msg);
  75. table.reload('tablerReload');
  76. })
  77. })
  78. }
  79. });
  80. $('.The_house').click(function () {
  81. indexOpen = parent.layui.layer.open({
  82. type: 2,
  83. title: '选择需要添加的楼盘',
  84. area: ['', '100%'],
  85. content: '/publicuse/housename',
  86. success: function (layero, index) {
  87. },
  88. end: function () {
  89. }
  90. });
  91. parent.layui.layer.full(indexOpen);
  92. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  93. $(window).on("resize", function () {
  94. parent.layui.layer.full(indexOpen);
  95. })
  96. })
  97. var $ = layui.$, active = {
  98. addData: function () { //获取选中数据
  99. layer.open({
  100. type: 2,
  101. title: '添加楼盘号码',
  102. closeBtn: 1, //不显示关闭按钮
  103. shade: [0.3],
  104. area: ['40%', '70%'],
  105. anim: 2,
  106. content: '/housenumber/add', //iframe的url,no代表不显示滚动条
  107. end: function () { //此处用于演示
  108. table.reload('tablerReload');
  109. }
  110. });
  111. },
  112. reloadb: function () {
  113. var form = pfgs_serialize($('form'));
  114. var city = '';
  115. var name = '';
  116. if (form.province != '') {
  117. city = form.province;
  118. }
  119. if (form.name != '') {
  120. name = form.name;
  121. }
  122. renderTable({id: city, name: name});
  123. }
  124. };
  125. $('.demoTable .layui-btn').on('click', function () {
  126. var type = $(this).data('type');
  127. active[type] ? active[type].call(this) : '';
  128. });
  129. form.on('submit(edittel)', function (data) {
  130. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  131. var formData = new FormData($('form')[0]);
  132. console.log(formData);
  133. $.ajax({
  134. cache: false,
  135. type: "post",
  136. url: "/housenumber/editform",
  137. data: formData, // 你的formid
  138. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  139. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  140. error: function (request) {
  141. layer.close(index);
  142. layer.msg("请联系管理员");
  143. },
  144. success: function (data) {
  145. if (data.data != null) {
  146. layer.msg(ReturnInfo(data.data), {icon: 5});
  147. return;
  148. }
  149. layer.msg(data.msg);
  150. parent.layer.close(oindex); //再执行关闭
  151. }
  152. });
  153. return false;
  154. });
  155. form.on('submit(tijiao)', function (data) {
  156. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  157. var formData = new FormData($('form')[0]);
  158. console.log(formData);
  159. $.ajax({
  160. cache: false,
  161. type: "post",
  162. url: "/housenumber/addform",
  163. data: formData, // 你的formid
  164. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  165. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  166. error: function (request) {
  167. layer.close(index);
  168. layer.msg("请联系管理员");
  169. },
  170. success: function (data) {
  171. if (data.data != null) {
  172. layer.msg(ReturnInfo(data.data), {icon: 5});
  173. return;
  174. }
  175. layer.msg(data.msg);
  176. parent.layer.close(oindex); //再执行关闭
  177. }
  178. });
  179. return false;
  180. });
  181. });