housepeitao.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // var delFiles = []; //用于删除图片
  2. // var filesContainer= {}; //存储最终要上传的图片
  3. // var files ; //存储选择图片的数量
  4. var trNum = [];
  5. var trIndex;
  6. var delNum = [];
  7. var dataId = new Array();
  8. layui.use(['form', 'layer', 'upload', 'table'], function () {
  9. var form = layui.form,
  10. // layer = parent.layer === undefined ? layui.layer : top.layer,
  11. layer = layui.layer,
  12. table = layui.table,
  13. $ = layui.jquery;
  14. var inputId = $('input[name="hid"]').val();
  15. var inputName = $('input[name="name"]').val();
  16. var longitude_latitude = $('input[name="longitude_latitude"]').val();
  17. //楼盘列表
  18. var indexTtable = table.render({
  19. elem: '#housepeitaolist',
  20. url: '/house/peitaoform',
  21. where: {hid: inputId},
  22. method: 'post',
  23. id: 'tablerReload',
  24. cols: [[
  25. // {type: "checkbox", fixed:"left", width:50},
  26. {type: 'numbers'},
  27. {field: 'name', title: '配套类目', align: "center", sort: true},
  28. {field: 'num', title: '数量', align: "center", sort: true, width: 100},
  29. {title: '操作', width: 200, templet: '#housesalbumListBar', fixed: "right", align: "center"}
  30. ]]
  31. });
  32. indexTtable.reload('tablerReload'); //重新加载
  33. // var onerange = getRandom(99);
  34. //配套设施修改
  35. var inputFid = $('input[name="fid"]').val();
  36. var editTable = table.render({
  37. elem: '#facilitysss',
  38. url: '/house/peitaoedit',
  39. method: 'post',
  40. cellMinWidth: 98,
  41. where: {fid: inputFid, hid: inputId},
  42. id: "facility",
  43. cols: [[
  44. {
  45. type: "", fixed: "left", width: 50, event: 'del', templet: function (d) {
  46. return '<i class="layui-icon" style="font-size: 30px; color: #1E9FFF;">&#xe640;</i>'
  47. }
  48. },
  49. {
  50. field: "id", title: "ID", width: 100, display: "none", align: "center", templet: function (d) {
  51. return '<input type="text" style="display: none;" name="edit_id" value="' + d.id + '" autocomplete="off" class="layui-input" >'
  52. }
  53. },
  54. {
  55. field: "name", title: "配套名称", width: 250, align: "center", templet: function (d) {
  56. return '<input type="text" name="matingName[' + d.id + ']" value="' + d.name + '" autocomplete="off" class="layui-input" >'
  57. }
  58. },
  59. {
  60. field: "distance", title: "距离", width: 150, align: "center", templet: function (d) {
  61. return '<input type="text" name="distance[' + d.id + ']" value="' + d.distance + '" autocomplete="off" class="layui-input" >'
  62. }
  63. },
  64. {
  65. field: "latitude_longitude",
  66. title: "经纬度",
  67. width: 200,
  68. align: "center",
  69. sort: true,
  70. templet: function (d) {
  71. return '<input type="text" id="jwd' + d.id + '" name="longitude[' + d.id + ']" value="' + d.latitude_longitude + '" autocomplete="off" class="layui-input" >';
  72. }
  73. }
  74. ]], done: function (res, curr, count) {
  75. $("[data-field='id']").css('display', 'none');
  76. }
  77. })
  78. //修改的工具条
  79. table.on('tool(facilitysss)', function (obj) {
  80. var data = obj.data;
  81. var _this = $(this);
  82. if (obj.event === 'del') {
  83. layer.confirm('确定删除数据?', function (index) {
  84. if (data.id > 0) {
  85. dataId.push(data.id);
  86. }
  87. if (typeof data.id == 'undefined') {
  88. _this.parents('tr').remove();
  89. }
  90. obj.del();
  91. layer.close(index);
  92. });
  93. }
  94. });
  95. //监听工具条
  96. table.on('tool(housepeitaolist)', function (obj) {
  97. var data = obj.data;
  98. if (obj.event === 'edit') {
  99. var index = parent.layui.layer.open({
  100. title: '<span style="color:red" >[' + inputName + ']</span> 楼盘周边配套修改',
  101. type: 2,
  102. maxmin: true,
  103. area: ['', '100%'],
  104. content: "/house/peitaoedit?id=" + inputId + '&fid=' + data.fid + '&name=' + data.name + '&ll=' + longitude_latitude,
  105. end: function () {
  106. layui.table.reload('tablerReload');
  107. }
  108. })
  109. parent.layui.layer.full(index);
  110. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  111. $(window).on("resize", function () {
  112. parent.layui.layer.full(index);
  113. })
  114. } else if (obj.event === 'del') {
  115. var index = layui.layer.confirm('确定要删除吗?', {btn: ['确定', '取消']}, function () {
  116. $.post('/house/peitaodel', {hid: inputId, type_id: data.fid}, function (data) {
  117. if (data.code == 200) {
  118. layer.msg(data.msg);
  119. table.reload('tablerReload');
  120. } else if (data.code == 300) {
  121. layer.msg(data.msg);
  122. }
  123. })
  124. })
  125. }
  126. });
  127. $('.layui_map .layui_close').on('click', function () {
  128. location.reload(); // 父页面刷新
  129. })
  130. /*
  131. * 弹出添加配套页面
  132. * */
  133. function addAlbum(edit) {
  134. var index = parent.layui.layer.open({
  135. title: '<span style="color:red" >[' + inputName + ']</span> 楼盘添加周边配套',
  136. type: 2,
  137. maxmin: true,
  138. area: ['', '100%'],
  139. content: "/house/peitaoadd?id=" + inputId + '&name=' + inputName + '&ll=' + longitude_latitude,
  140. end: function () {
  141. layui.table.reload('tablerReload');
  142. }
  143. })
  144. parent.layui.layer.full(index);
  145. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  146. $(window).on("resize", function () {
  147. parent.layui.layer.full(index);
  148. })
  149. }
  150. //添加配套
  151. $("#add-album").click(function () {
  152. addAlbum()
  153. });
  154. // 添加页面提交
  155. form.on('submit(add_load_mating)', function (data) {
  156. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  157. var form = pfgs_serialize($('#peitao_form'));
  158. var trArry = $('.layui-input-block table.layui-table tbody tr');
  159. var dataObj = [{}];
  160. var dataArry = new Array();
  161. $.each(trArry, function (key, val) {
  162. var _title = $(this).find('input[name="matingName"]').val();
  163. var _rout = $(this).find('input[name="distance"]').val();
  164. var _point = $(this).find('input[name="longitude"]').val();
  165. dataObj[key] = {title: _title, rout: _rout, point: _point} //把数据以数组对象的方式保存
  166. dataArry.push(dataObj[key])
  167. })
  168. $.post("/house/peitaoaddform", {data: dataArry, hid: inputId, type_id: form.city}, function (data) {
  169. if (data.code == 200) {
  170. layer.msg(data.msg);
  171. indexTtable.reload('tablerReload');
  172. TableClose();
  173. } else if (data.code == 300) {
  174. layer.msg(data.msg);
  175. if (data.data.length > 0) {
  176. layer.msg(ReturnInfo(data.data), {icon: 5});
  177. }
  178. }
  179. })
  180. return false;
  181. })
  182. // 修改提交
  183. form.on('submit(edit_load_mating)', function (data) {
  184. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  185. var form = pfgs_serialize($('#peitao_form'));
  186. var trArry = $('.layui-table-main table.layui-table tbody tr');
  187. var dataObj = [{}];
  188. var dataArry = new Array();
  189. $.each(trArry, function (key, val) {
  190. var _title = $(this).find('input[name="matingName"]').val();
  191. var _rout = $(this).find('input[name="distance"]').val();
  192. var _point = $(this).find('input[name="longitude"]').val();
  193. dataObj[key] = {title: _title, rout: _rout, point: _point} //把数据以数组对象的方式保存
  194. dataArry.push(dataObj[key])
  195. })
  196. $.post("/house/peitaoeditform", {
  197. data: dataArry,
  198. dataId: dataId,
  199. hid: inputId,
  200. type_id: form.fid
  201. }, function (data) {
  202. layer.msg(data.msg);
  203. // if (data.code == 200) {
  204. // layer.msg(data.msg);
  205. // indexTtable.reload('tablerReload');
  206. //
  207. // } else if(data.code == 300){
  208. // layer.msg(data.msg);
  209. // if(data.data.length > 0){
  210. // layer.msg(ReturnInfo(data.data),{icon:5});
  211. // }
  212. // }
  213. })
  214. return false;
  215. })
  216. });
  217. //生产随机数
  218. // function getRandom(n) {
  219. // return Math.floor(Math.random() * n + 1)
  220. // }
  221. //
  222. // function uniqueidArr(arr) {
  223. // var newArr = {};
  224. // console.log(newArr);
  225. // if(arr.length >0){
  226. // $.each(arr,function (k,v) {
  227. // newArr[v] = v;
  228. // })
  229. // return newArr;
  230. // }
  231. //
  232. // }