housepeitao.js 8.9 KB

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