search.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. function getParams(url) {
  2. var theRequest = new Object();
  3. if (!url)
  4. url = location.href;
  5. if (url.indexOf("?") !== -1)
  6. {
  7. var str = url.substr(url.indexOf("?") + 1) + "&";
  8. var strs = str.split("&");
  9. for (var i = 0; i < strs.length - 1; i++)
  10. {
  11. var key = strs[i].substring(0, strs[i].indexOf("="));
  12. var val = strs[i].substring(strs[i].indexOf("=") + 1);
  13. theRequest[key] = val;
  14. }
  15. }
  16. return theRequest;
  17. }
  18. var objUrl = {}; //获取get参数
  19. var url = window.location.href;
  20. var searchParams = ''; //最后拼接的参数
  21. var urlParams = '';
  22. // 页数 进入页面php渲染了10条数据,分页从1开始,请求的时候 page++ 就是从第二页开始请求
  23. var page = 1;
  24. // 每页展示10个
  25. var size = 10;
  26. var Wxdata = new Object(); // 用于处理选中问题
  27. var params = getParams(url); //获取get请求的参数
  28. if(!$.isEmptyObject(params)){
  29. $.each(params,function(key,val){
  30. if(key == 'city') feng_cityTel = val;
  31. objUrl[key] = val;
  32. urlParams += key+'='+val+'&';
  33. })
  34. urlParams = urlParams.substring(0,urlParams.length - 1);
  35. searchParams = '&'+ urlParams;
  36. }
  37. // 为了解决选中问题
  38. if(!$.isEmptyObject(params)){
  39. $.each(params,function(k,v){
  40. if(k != 'price' && k !='py'){
  41. $('.y_qylist_cnet a[name="'+k+'"][value="'+v+'"]').addClass('ki');
  42. }
  43. })
  44. }
  45. function AlertMsg(msg){
  46. var vir ='<div class="main">';
  47. vir +='<div class="slice">';
  48. vir +='<div data-loader="circle"></div>';
  49. vir +='<div>'+msg+'</div>';
  50. vir +='</div>';
  51. vir +='</div>';
  52. $('body').append(vir);
  53. }
  54. function AlertMsgDel(clearTime = 1000)
  55. {
  56. if($('.main')){
  57. setTimeout(function(){
  58. $('.main').remove(); //删除加载转圈
  59. },clearTime);
  60. }
  61. }
  62. $(function(){
  63. $('.y_homelist_list').dropload({
  64. scrollArea : window,
  65. domDown : {
  66. domClass : 'dropload-down',
  67. domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
  68. domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
  69. domNoData : '<div class="dropload-noData">我也是有底线的...</div>'
  70. },
  71. loadDownFn : function(me,da){
  72. page++;
  73. // 拼接HTML
  74. var result = '';
  75. $.ajax({
  76. type: 'GET',
  77. url: '/housech/searchdata?page='+page+'&limit='+size+searchParams,
  78. dataType: 'json',
  79. // async:false, //去掉同步,要不然会出来卡的感觉
  80. beforeSend:function(){
  81. // AlertMsg('数据加载中...');
  82. },
  83. success: function(data){
  84. var lpsun = data.count;
  85. // 2019-5-8 删除加载转圈效果
  86. // AlertMsgDel(500);
  87. if(data.code == 200){
  88. var data = data.data;
  89. if(data != null){
  90. $.each(data,function (key,val) {
  91. var randomX = 300;
  92. var randomY = 800;
  93. var randvalue = parseInt(Math.random() * (randomX - randomY + 1) + randomY);
  94. result += '<li>'
  95. result +='<a href="/housech/'+val.id+'/">'
  96. result +='<div class="sell_img">'
  97. result +='<img class="m_list_img" src="'+val.thumb+'/same" alt="">'
  98. result +='<i class="sell_img_i">'+val.city_name+'</i>'
  99. result +='<div class="m_tblist c">'
  100. if(val.video !=0 && val.video !='' && val.video != null && val.video != undefined){
  101. result +='<i><img src="/image/video/sp1.png" alt=""></i>'
  102. }
  103. if(val.panorama !=0 && val.panorama !='' && val.panorama != null && val.panorama != undefined){
  104. result +='<i><img src="/image/video/vr1.png" alt=""></i>'
  105. }
  106. if(val.albumCount !=0 && val.albumCount !='' && val.albumCount != null && val.albumCount != undefined){
  107. result +='<i><img src="/image/video/xc1.png" alt=""></i>'
  108. }
  109. result +='</div>'
  110. result +='</div>'
  111. result +='<div class="sell_conter_right">'
  112. result +='<p class="title">'+val.name+'</p>'
  113. if(val.sale_price != 0 && val.sale_price != null && val.sale_price != ''){
  114. result += '<p class="jg_ing jg_ingdd" style="margin-top:9px"><span><em>'+ val.sale_price +'</em>'+val.price_unit+'</span></p>';
  115. }else{
  116. result += '<p class="jg_ing jg_ingdd" style="margin-top:9px"><span><em>待定</em></span></p>';
  117. }
  118. result += '<p class="jg_ing" style="margin-top:8px">有效期:'+whtmltime+'</p>'
  119. result +='</div>'
  120. result +='<div class="m_gzlx">'
  121. result +='<p class="attention">已有 <span>'+randvalue+'</span> 人关注</p>'
  122. result +='<div class="m_gzlx_style">'
  123. if(val.characteristic){
  124. $.each(val.characteristic,function(k,v){
  125. result +='<i>'+v+'</i>';
  126. })
  127. }
  128. result += '</div>'
  129. result +='</div>'
  130. result +='</a>'
  131. if(val.is_tel != null && val.is_tel != ''){
  132. result +='<div class="cal_price"><a href="tel:'+val.is_tel+'"><img src="/image/index/tel_calltu.png"></a></div>'
  133. }else{
  134. result +='<div class="cal_price"><a href="tel:'+val.citytel+'"><img src="/image/index/tel_calltu.png"></a></div>'
  135. }
  136. result +='</li>'
  137. })
  138. $('.y_homelist_list ul').append(result);
  139. // 每次数据插入,必须重置
  140. // me.resetload();
  141. // 如果没有数据
  142. }
  143. }else{
  144. // 锁定
  145. me.lock();
  146. // 无数据
  147. me.noData();
  148. }
  149. me.resetload(); //重置
  150. },
  151. error: function(xhr, type){
  152. // AlertMsgDel(500);
  153. // alert('Ajax error!');
  154. // 即使加载出错,也得重置
  155. me.resetload();
  156. }
  157. });
  158. },
  159. threshold :80 //升高底部触发加载的距离;
  160. });
  161. });
  162. $.each($('.m_nav_qy').find('a'),function(){
  163. var each_name = $(this).attr('name');
  164. var each_val = $(this).attr('value');
  165. if(each_val == objUrl[each_name]){
  166. $(this).attr('id','nav');
  167. }
  168. })
  169. //
  170. $(".y_qylist_cnet_ind").on('click','a.link-item',function(){
  171. var _this = $(this);
  172. _this.addClass('on');
  173. _this.siblings().removeClass('on');
  174. $('.three_area').show();
  175. // _this.show();
  176. $.post('/housech/soncity',{pid:_this.attr('value')},function(data){
  177. $(".three_area").html('');
  178. if(data.code == 200){
  179. var str = '';
  180. // str += '<a class="link_click" name="city" value="'+_this.attr('value')+'" href="javascript:;">全部</a>';
  181. str += '<a class="link_click" name="city" pinyin="'+_this.attr('pinyin')+'" value="'+_this.attr('value')+'" href="javascript:;">'+_this.find('span').html()+'</a>';
  182. $.each(data.data,function (k,v) {
  183. str += '<a class="link_click" name="city" pinyin="'+v.pinyin+'" value="'+v.id+'" href="javascript:;"><span>'+v.city_name+'</span></a>';
  184. })
  185. }
  186. $(".three_area").append(str);
  187. // 为了解决AJAX请求数据选中
  188. if(!$.isEmptyObject(params)){
  189. $.each(params,function(k,v){
  190. if(k != 'price' && k !='py'){
  191. $('.y_qylist_cnet a[name="'+k+'"][value="'+v+'"]').addClass('ki');
  192. }
  193. })
  194. }
  195. })
  196. $(".three_area").animate({left:"110px"});
  197. })
  198. $(".y_qylist_cnet_ind").on('click','a.actived-item',function(){
  199. $(".three_area").animate({left:"100%"});
  200. })
  201. function waptab(name1,name2,name3){
  202. $(name1).on('click',function(){
  203. $(name2).hide();
  204. var Idoption = $(this).attr(name3);
  205. if($(this).hasClass('on')){ //判断css on 是否存在
  206. $(name2+'['+name3+''+'='+ Idoption +']').hide();
  207. $(this).removeClass('on');
  208. }else{
  209. $(this).addClass('on').siblings().removeClass('on');
  210. $(name2+'['+name3+''+'='+ Idoption +']').show();
  211. }
  212. })
  213. }
  214. waptab('.y_qylist_hoe .y_qylist_con','.y_qylist_cnet_ind','data-id');
  215. var mySwiper1= new Swiper(".swiper-container1",{
  216. loop : true,
  217. loopedSlides:4,
  218. autoplay:5500,
  219. autoplayDisableOnInteraction : false,
  220. // 如果需要分页器
  221. pagination: '.swiper-pagination',
  222. slidesPerView :"auto"
  223. });
  224. // 处理资讯详情页面的底部一个月的有效日期
  225. var myDate = new Date;
  226. var year = myDate.getFullYear(); //获取当前时间年份
  227. var yue = myDate.getMonth()+1;//获取当前时间月份
  228. if (yue<10) {
  229. yue= '0' + yue;
  230. }else if(yue == 13){
  231. yue = '01';
  232. };
  233. // 返回下个月有多少天数
  234. function mGetDate(yue){     
  235. var date = new Date();     
  236. var year = date.getFullYear();     
  237. var d = new Date(year,parseInt(yue), 0);
  238. return d.getDate();
  239. }
  240. var whtmltimes = year + '/'+ yue + '/' + mGetDate(yue);
  241. var whtmltime = year + '/'+ yue + '/' +'01'+'-'+ year + '/'+ yue + '/' + mGetDate(yue);
  242. // 处理选中价格
  243. function price_deal(subject){
  244. switch(subject){
  245. case '8000-10000元':
  246. subject = '8千-1万';
  247. break;
  248. case '6000-8000元':
  249. subject = '6-8千';
  250. break;
  251. case '4000-6000元':
  252. subject = '4-6千';
  253. break;
  254. case '4000元以下':
  255. subject = '4千以下';
  256. break;
  257. default:
  258. subject = 1;
  259. break;
  260. }
  261. return subject;
  262. }
  263. // 处理跳转过来选中价格
  264. var textspan=$('.y_qylist_con p.feng_price span').text();
  265. $('.y_qylist_con p.feng_price span').text(price_deal2(textspan))
  266. function price_deal2(subject2){
  267. switch(subject2){
  268. case '8000-10000元':
  269. subject2 = '8千-1万';
  270. break;
  271. case '6000-8000元':
  272. subject2 = '6-8千';
  273. break;
  274. case '4000-6000元':
  275. subject2 = '4-6千';
  276. break;
  277. case '4000元以下':
  278. subject2 = '4千以下';
  279. break;
  280. }
  281. return subject2;
  282. }
  283. function Qalert(num = 0) {
  284. var M = {};
  285. if(M.dialog1){
  286. return M.dialog1.show();
  287. }
  288. M.dialog1 = jqueryAlert({
  289. 'content' : '已为您找到<span style="color:#FF6926;font-size: 1.0rem;"> '+num+' </span>套房源',
  290. 'closeTime' : 4000,
  291. })
  292. }
  293. var house_total = $('.feng_house_total').html();
  294. if(house_total){
  295. Qalert(house_total);
  296. }
  297. $(function(){
  298. //转换价格格式
  299. $('.wx_btn a').each(function(){
  300. var _this = $(this);
  301. var txt = _this.text();
  302. _this.html(price_deal2(txt));
  303. })
  304. // 筛选确定按钮
  305. $('.wx_confirm').on('click',function(){
  306. var _this = $(this);
  307. var oi = _this.attr('data-id');
  308. var pthis = $('.y_qylist_cnet_ind[data-id="'+oi+'"]');
  309. if(pthis.find('a.in').attr('name') == 'city'){
  310. objUrl['py'] = pthis.find('a.in').attr('pinyin');
  311. }
  312. var ParamsArr = ['city','type','characteristic','price','py']; //搜索字段
  313. var atrName = pthis.find('a.in').attr('name');
  314. var _val =pthis.find('a.in').attr('value');
  315. var urlParams = '';
  316. for (var k in ParamsArr){
  317. if(ParamsArr[k] == atrName){
  318. objUrl[atrName] = _val;
  319. delete objUrl.page;
  320. delete objUrl.name;
  321. //数据存储
  322. }
  323. // if(atrName == 'price'){ //处理价格
  324. // Wxdata[atrName] = _val; //楼盘名称存储格式
  325. // var odata = JSON.stringify(Wxdata); //对象转换为字符串
  326. // window.localStorage.setItem("data",odata);
  327. // }
  328. }
  329. $.each(objUrl,function(key,val){
  330. if(key == 'py') return true; //跳出当前循环
  331. urlParams += key+'='+val+'&';
  332. })
  333. var cityUrl = '';
  334. urlParams = urlParams.substring(0,urlParams.length - 1);
  335. if(typeof objUrl.py == 'string'){
  336. cityUrl = 'py='+objUrl.py+'&';
  337. }
  338. if(urlParams == '' && cityUrl != '')
  339. {
  340. cityUrl = cityUrl.substring(0,cityUrl.length - 1);
  341. }
  342. window.location.href = '/housech/search?'+ cityUrl+urlParams;
  343. })
  344. // 筛选取消按钮
  345. $('.wx_cls').on('click',function(){
  346. $('.w_barrier').fadeOut();
  347. $('.wx_screen_box').animate({bottom:'-500px'});
  348. p()
  349. })
  350. // 筛选框展示
  351. var condition = ['区域','价格','特色','户型'];
  352. $('.y_qylist_con').on('click',function(){
  353. var oi = $(this).attr('data-id');
  354. $('.wx_screen_box').animate({bottom:'0'});
  355. $('.wx_screen_btn').find('i').html(condition[oi-1]);
  356. $('.wx_screen_btn .wx_confirm').attr('data-id',oi);
  357. $('.w_barrier').fadeIn();
  358. $('.y_qylist_cnet .y_qylist_cnet_ind[data-id="'+oi+'"]').show();
  359. s();
  360. if(oi == 2){
  361. /*用于处理选中问题*/
  362. var txt = $(this).find('span').text();
  363. if(txt != condition[oi-1]){
  364. $('.wx_btn[data-id="2"] a').each(function(){
  365. var _this = $(this)
  366. if(txt == _this.text()){
  367. _this.addClass('ki');
  368. }
  369. })
  370. }
  371. }
  372. })
  373. // 点击遮层隐藏
  374. $('.w_barrier').on('click',function(){
  375. $('.wx_screen_box').animate({bottom:'-500px'});
  376. $('.w_barrier').fadeOut();
  377. p()
  378. })
  379. // 点击选中
  380. $('.wx_sreen_con').on('click','a.link_click',function(){
  381. $(this).addClass('in').siblings().removeClass('in');
  382. $(this).siblings().removeClass('ki');
  383. })
  384. $('.link_click_a').on('click',function(){
  385. $(this).attr('id','on')
  386. $('.link-item').removeClass('on');
  387. $('.three_area').html('');
  388. })
  389. $(document).bind("click",function(e){
  390. var target = $(e.target);
  391. if(target.closest(".link_click_a").length == 0){ //点击 .inputxz 之外的地方触发
  392. $('.link_click_a').attr('id','');
  393. }
  394. })
  395. })
  396. // 以下两个方法为了隐藏/显示商务通
  397. function s(){
  398. clearInterval(time)
  399. stime=setInterval(function(){
  400. $('#LXB_CONTAINER_SHOW').hide();
  401. $('#LRMINIBar').hide();
  402. },80);
  403. }
  404. function p(){
  405. clearInterval(stime)
  406. time=setInterval(function(){
  407. $('#LXB_CONTAINER_SHOW').show();
  408. $('#LRMINIBar').show();
  409. },80);
  410. }
  411. /*
  412. * 获取 DOC 超出可视区域的高度
  413. */
  414. $(window).scroll(function (){
  415. var ster = $(this).scrollTop();
  416. var _hasClass = $('.y_qylist_hoe .y_qylist_con').hasClass('on');
  417. if (ster < 180 && _hasClass == false) {
  418. _hide()
  419. }else{
  420. _show();
  421. }
  422. });
  423. function _show(){
  424. $('.m_top').css('background','#FFF');
  425. $('.header_menu img').attr('src','/image/indexv2_19.png');
  426. $('.header_back img').attr('src','/image/indexv2_17.png');
  427. $('.header_menu').attr('id','header_menu');
  428. $('.header_back').attr('id','header_back');
  429. $('.xm_v2logo').show();
  430. }
  431. function _hide(){
  432. $('.m_top').css('background','rgba(0,0,0,0)');
  433. $('.header_menu img').attr('src','/image/indexv2_18.png');
  434. $('.header_back img').attr('src','/image/menu_a02.png');
  435. $('.header_menu').attr('id','');
  436. $('.header_back').attr('id','');
  437. $('.xm_v2logo').hide();
  438. }