search.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. function getParams(url) {
  2. var theRequest = new Object();
  3. if (!url)
  4. url = location.href;
  5. if (url.indexOf("?") !== -1) {
  6. var str = url.substr(url.indexOf("?") + 1) + "&";
  7. var strs = str.split("&");
  8. for (var i = 0; i < strs.length - 1; i++) {
  9. var key = strs[i].substring(0, strs[i].indexOf("="));
  10. var val = strs[i].substring(strs[i].indexOf("=") + 1);
  11. theRequest[key] = val;
  12. }
  13. }
  14. return theRequest;
  15. }
  16. var objUrl = {}; //获取get参数
  17. var url = window.location.href;
  18. var searchParams = ''; //最后拼接的参数
  19. var urlParams = '';
  20. // 页数 进入页面php渲染了10条数据,分页从1开始,请求的时候 page++ 就是从第二页开始请求
  21. var page = 1;
  22. // 每页展示10个
  23. var size = 10;
  24. var Wxdata = new Object(); // 用于处理选中问题
  25. var params = getParams(url); //获取get请求的参数
  26. if (!$.isEmptyObject(params)) {
  27. $.each(params, function (key, val) {
  28. if (key == 'city') feng_cityTel = val;
  29. objUrl[key] = val;
  30. urlParams += key + '=' + val + '&';
  31. })
  32. urlParams = urlParams.substring(0, urlParams.length - 1);
  33. searchParams = '&' + urlParams;
  34. }
  35. // 为了解决选中问题
  36. if (!$.isEmptyObject(params)) {
  37. $.each(params, function (k, v) {
  38. if (k != 'price' && k != 'py') {
  39. $('.y_qylist_cnet a[name="' + k + '"][value="' + v + '"]').addClass('ki');
  40. }
  41. })
  42. }
  43. function AlertMsg(msg) {
  44. var vir = '<div class="main">';
  45. vir += '<div class="slice">';
  46. vir += '<div data-loader="circle"></div>';
  47. vir += '<div>' + msg + '</div>';
  48. vir += '</div>';
  49. vir += '</div>';
  50. $('body').append(vir);
  51. }
  52. function AlertMsgDel(clearTime = 1000) {
  53. if ($('.main')) {
  54. setTimeout(function () {
  55. $('.main').remove(); //删除加载转圈
  56. }, clearTime);
  57. }
  58. }
  59. $(function () {
  60. $('.y_homelist_list').dropload({
  61. scrollArea: window,
  62. domDown: {
  63. domClass: 'dropload-down',
  64. domRefresh: '<div class="dropload-refresh">↑上拉加载更多</div>',
  65. domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
  66. domNoData: '<div class="dropload-noData">我也是有底线的...</div>'
  67. },
  68. loadDownFn: function (me, da) {
  69. page++;
  70. // 拼接HTML
  71. var result = '';
  72. $.ajax({
  73. type: 'GET',
  74. url: '/json/searchdata?page=' + page + '&limit=' + size + searchParams,
  75. dataType: 'json',
  76. // async:false, //去掉同步,要不然会出来卡的感觉
  77. beforeSend: function () {
  78. // AlertMsg('数据加载中...');
  79. },
  80. success: function (data) {
  81. var lpsun = data.count;
  82. // 2019-5-8 删除加载转圈效果
  83. // AlertMsgDel(500);
  84. if (data.code == 200) {
  85. var data = data.data;
  86. if (data != null) {
  87. $.each(data, function (key, val) {
  88. var randomX = 300;
  89. var randomY = 800;
  90. var randvalue = parseInt(Math.random() * (randomX - randomY + 1) + randomY);
  91. result += '<li>';
  92. result += '<div class="sell_conterBox">';
  93. result += '<a href="/house/' + val.id + '">';
  94. result += '<div class="sell_conterBox_l">';
  95. result += '<p class="img"><img src="' + val.thumb + '/same" alt=""></p>';
  96. result += '<p class="city">' + val.city_name + '</p>';
  97. result += '<div class="sdin">';
  98. if (val.vr_path != 0 && val.vr_path != '' && val.vr_path != null && val.vr_path != undefined) {
  99. result += '<div class="vvid_pic_ico vr-animation-forever"></div>';
  100. }
  101. if(val.video_url != 0 && val.video_url != '' && val.video_url != null && val.video_url != undefined){
  102. result += '<p class="vid_ico"><img src="/overseas/img/v2image/v2_ico5.png" alt=""></p>';
  103. }
  104. result += '</div>';
  105. if (val.panorama != 0 && val.panorama != '' && val.panorama != null && val.panorama != undefined) {
  106. result += '<p class="hangpai">航拍实景</p>';
  107. }
  108. result += '</div>';
  109. result += '<div class="sell_conterBox_r">';
  110. result += '<h2 class="title">' + val.name + '</h2>';
  111. if (val.sale_price != 0 && val.sale_price != null && val.sale_price != '') {
  112. result += '<p class="pric"><span>' + val.sale_price + '</span>' + val.price_unit + '</p>';
  113. } else {
  114. result += '<p class="pric"><span>待定</span></p>';
  115. }
  116. result += '<p class="time">有效期至:'+htmltime+'</p>';
  117. result += '<p class="style">';
  118. result += '<i>'+val.state+'</i>';
  119. if (val.characteristic) {
  120. $.each(val.characteristic, function (k, v) {
  121. if(k<2){
  122. result += '<span>' + v + '</span>';
  123. }
  124. })
  125. }
  126. result += '</p>';
  127. result += '</div>';
  128. result += '</a>';
  129. if(val.preferential){
  130. result += '<div class="lp_zk">';
  131. result += '<span>';
  132. result += '<img src="/overseas/img/v2image/v2_ico6.png" alt="">';
  133. result += '<b>优惠活动</b>';
  134. result += '<i>|</i>';
  135. var zhTxt= val.preferential;
  136. var maxwidth=21;
  137. if(zhTxt.length>maxwidth){
  138. result += '<em>'+zhTxt.substring(0,maxwidth)+'...</em>';
  139. }else{
  140. result += '<em>'+zhTxt+'</em>';
  141. }
  142. result += '</span>';
  143. result += '</div>';
  144. }
  145. result += '</div>';
  146. result += '<div class="lp_tell">';
  147. if (val.is_tel != null && val.is_tel != '') {
  148. result += '<a href="tel:' + val.is_tel + '"><img src="/overseas/img/pulic_ico3.png" alt="">免费电话</a>';
  149. } else {
  150. result += '<a href="tel:' + val.citytel + '"><img src="/overseas/img/pulic_ico3.png" alt="">免费电话</a>';
  151. }
  152. result += '</div>';
  153. result += '</li>';
  154. })
  155. $('.y_homelist_list ul').append(result);
  156. // 每次数据插入,必须重置
  157. // me.resetload();
  158. // 如果没有数据
  159. }
  160. } else {
  161. // 锁定
  162. me.lock();
  163. // 无数据
  164. me.noData();
  165. }
  166. me.resetload(); //重置
  167. },
  168. error: function (xhr, type) {
  169. // AlertMsgDel(500);
  170. // alert('Ajax error!');
  171. // 即使加载出错,也得重置
  172. me.resetload();
  173. }
  174. });
  175. },
  176. threshold: 80 //升高底部触发加载的距离;
  177. });
  178. });
  179. $.each($('.m_nav_qy').find('a'), function () {
  180. var each_name = $(this).attr('name');
  181. var each_val = $(this).attr('value');
  182. if (each_val == objUrl[each_name]) {
  183. $(this).attr('id', 'nav');
  184. }
  185. })
  186. //
  187. $(".y_qylist_cnet_ind").on('click', 'a.link-item', function () {
  188. var _this = $(this);
  189. _this.addClass('on');
  190. _this.siblings().removeClass('on');
  191. $('.three_area').show();
  192. // _this.show();
  193. // $.post('/house/soncity',{pid:_this.attr('value')},function(data){
  194. $.post('/json/soncity', {pid: _this.attr('value')}, function (data) {
  195. $(".three_area").html('');
  196. if (data.code == 200) {
  197. var str = '';
  198. // str += '<a class="link_click" name="city" value="'+_this.attr('value')+'" href="javascript:;">全部</a>';
  199. str += '<a class="link_click" name="city" pinyin="' + _this.attr('pinyin') + '" value="' + _this.attr('value') + '" href="javascript:;">' + _this.find('span').html() + '</a>';
  200. $.each(data.data, function (k, v) {
  201. str += '<a class="link_click" name="city" pinyin="' + v.pinyin + '" value="' + v.id + '" href="javascript:;"><span>' + v.city_name + '</span></a>';
  202. })
  203. }
  204. $(".three_area").append(str);
  205. // 为了解决AJAX请求数据选中
  206. if (!$.isEmptyObject(params)) {
  207. $.each(params, function (k, v) {
  208. if (k != 'price' && k != 'py') {
  209. $('.y_qylist_cnet a[name="' + k + '"][value="' + v + '"]').addClass('ki');
  210. }
  211. })
  212. }
  213. })
  214. $(".three_area").animate({left: "110px"});
  215. })
  216. $('.y_qylist_cnet_ind[data-id="1"] a').eq(1).click();
  217. $(".y_qylist_cnet_ind").on('click', 'a.actived-item', function () {
  218. $(".three_area").animate({left: "100%"});
  219. })
  220. function waptab(name1, name2, name3) {
  221. $(name1).on('click', function () {
  222. $(name2).hide();
  223. var Idoption = $(this).attr(name3);
  224. if ($(this).hasClass('on')) { //判断css on 是否存在
  225. $(name2 + '[' + name3 + '' + '=' + Idoption + ']').hide();
  226. $(this).removeClass('on');
  227. } else {
  228. $(this).addClass('on').siblings().removeClass('on');
  229. $(name2 + '[' + name3 + '' + '=' + Idoption + ']').show();
  230. }
  231. })
  232. }
  233. waptab('.y_qylist_hoe .y_qylist_con', '.y_qylist_cnet_ind', 'data-id');
  234. var mySwiper1 = new Swiper(".swiper-container1", {
  235. loop: true,
  236. loopedSlides: 4,
  237. autoplay: 5500,
  238. autoplayDisableOnInteraction: false,
  239. // 如果需要分页器
  240. pagination: '.swiper-pagination',
  241. slidesPerView: "auto"
  242. });
  243. // 处理资讯详情页面的底部一个月的有效日期
  244. var myDate = new Date;
  245. var year = myDate.getFullYear(); //获取当前时间年份
  246. var yue = myDate.getMonth() + 1;//获取当前时间月份
  247. if (yue < 10) {
  248. yue = '0' + yue;
  249. } else if (yue == 13) {
  250. yue = '01';
  251. }
  252. ;
  253. // 返回下个月有多少天数
  254. function mGetDate(yue) {
  255. var date = new Date();
  256. var year = date.getFullYear();
  257. var d = new Date(year, parseInt(yue), 0);
  258. return d.getDate();
  259. }
  260. var htmltime = year + '.' + yue + '.' + mGetDate(yue);
  261. $('.js_time').html('有效期至:' + htmltime + ''); //有效期
  262. // 处理选中价格
  263. function price_deal(subject) {
  264. switch (subject) {
  265. case '8000-10000元':
  266. subject = '8千-1万';
  267. break;
  268. case '6000-8000元':
  269. subject = '6-8千';
  270. break;
  271. case '4000-6000元':
  272. subject = '4-6千';
  273. break;
  274. case '4000元以下':
  275. subject = '4千以下';
  276. break;
  277. default:
  278. subject = 1;
  279. break;
  280. }
  281. return subject;
  282. }
  283. // 处理跳转过来选中价格
  284. var textspan = $('.y_qylist_con p.feng_price span').text();
  285. $('.y_qylist_con p.feng_price span').text(price_deal2(textspan))
  286. function price_deal2(subject2) {
  287. switch (subject2) {
  288. case '8000-10000元':
  289. subject2 = '8千-1万';
  290. break;
  291. case '6000-8000元':
  292. subject2 = '6-8千';
  293. break;
  294. case '4000-6000元':
  295. subject2 = '4-6千';
  296. break;
  297. case '4000元以下':
  298. subject2 = '4千以下';
  299. break;
  300. }
  301. return subject2;
  302. }
  303. function Qalert(num = 0) {
  304. var M = {};
  305. if (M.dialog1) {
  306. return M.dialog1.show();
  307. }
  308. M.dialog1 = jqueryAlert({
  309. 'content': '已为您找到<span style="color:#FF6926;font-size: 1.0rem;"> ' + num + ' </span>套房源',
  310. 'closeTime': 4000,
  311. })
  312. }
  313. var house_total = $('.feng_house_total').html();
  314. if (house_total) {
  315. Qalert(house_total);
  316. }
  317. var SearchParams = {};
  318. SearchParams=urlParams;
  319. $(function () {
  320. //转换价格格式
  321. $('.wx_btn a').each(function () {
  322. var _this = $(this);
  323. var txt = _this.text();
  324. _this.html(price_deal2(txt));
  325. })
  326. // 筛选确定按钮
  327. $('.wx_confirm').on('click', function () {
  328. var _this = $(this);
  329. var oi = _this.attr('data-id');
  330. var pthis = $('.y_qylist_cnet_ind[data-id="' + oi + '"]');
  331. if (pthis.find('a.in').attr('name') == 'city') {
  332. objUrl['py'] = pthis.find('a.in').attr('pinyin');
  333. }
  334. var ParamsArr = ['city', 'type', 'brand', 'characteristic', 'price', 'py']; //搜索字段
  335. var atrName = pthis.find('a.in').attr('name');
  336. var _val = pthis.find('a.in').attr('value');
  337. var urlParams = '';
  338. for (var k in ParamsArr) {
  339. if (ParamsArr[k] == atrName) {
  340. objUrl[atrName] = _val;
  341. delete objUrl.page;
  342. delete objUrl.name;
  343. //数据存储
  344. }
  345. // if(atrName == 'price'){ //处理价格
  346. // Wxdata[atrName] = _val; //楼盘名称存储格式
  347. // var odata = JSON.stringify(Wxdata); //对象转换为字符串
  348. // window.localStorage.setItem("data",odata);
  349. // }
  350. }
  351. $.each(objUrl, function (key, val) {
  352. if (key == 'py') return true; //跳出当前循环
  353. urlParams += key + '=' + val + '&';
  354. })
  355. var cityUrl = '';
  356. urlParams = urlParams.substring(0, urlParams.length - 1);
  357. if (typeof objUrl.py == 'string') {
  358. cityUrl = 'py=' + objUrl.py + '&';
  359. }
  360. if (urlParams == '' && cityUrl != '') {
  361. cityUrl = cityUrl.substring(0, cityUrl.length - 1);
  362. }
  363. // console.log('/house/search?'+ cityUrl+urlParams);
  364. window.location.href = '/house/search?' + cityUrl + urlParams;
  365. })
  366. // 筛选取消按钮
  367. $('.wx_cls').on('click', function () {
  368. $('.w_barrier').fadeOut();
  369. $('.wx_screen_box').animate({top: '-500px'});
  370. // p()
  371. })
  372. // 筛选框展示
  373. var condition = ['区域', '价格', '户型', '特色'];
  374. $('.y_qylist_con').on('click', function () {
  375. var oi = $(this).attr('data-id');
  376. $('.wx_screen_box').animate({top: '0'});
  377. $('.wx_screen_btn').find('i').html(condition[oi - 1]);
  378. $('.wx_screen_btn .wx_confirm').attr('data-id', oi);
  379. $('.w_barrier').fadeIn();
  380. $('.y_qylist_cnet .y_qylist_cnet_ind[data-id="' + oi + '"]').show();
  381. // s();
  382. // console.log(oi);
  383. $('.js_wx_screen_btn').show();
  384. if (oi == 2) {
  385. /*用于处理选中问题*/
  386. var txt = $(this).find('span').text();
  387. if (txt != condition[oi - 1]) {
  388. $('.wx_btn[data-id="2"] a').each(function () {
  389. var _this = $(this)
  390. if (txt == _this.text()) {
  391. _this.addClass('ki');
  392. }
  393. })
  394. }
  395. }else if (oi== 4) {
  396. $('.js_wx_screen_btn').hide();
  397. $('.yv3_revamp').height(360)
  398. }
  399. })
  400. // 点击遮层隐藏
  401. $('.w_barrier').on('click', function () {
  402. $('.wx_screen_box').animate({top: '-500px'});
  403. $('.w_barrier').fadeOut();
  404. // p()
  405. })
  406. // 点击选中
  407. $('.wx_sreen_con').on('click', 'a.link_click', function () {
  408. $(this).addClass('in').siblings().removeClass('in');
  409. $(this).siblings().removeClass('ki');
  410. })
  411. $('.link_click_a').on('click', function () {
  412. $(this).attr('id', 'on')
  413. $('.link-item').removeClass('on');
  414. $('.three_area').html('');
  415. })
  416. $(document).bind("click", function (e) {
  417. var target = $(e.target);
  418. if (target.closest(".link_click_a").length == 0) { //点击 .inputxz 之外的地方触发
  419. $('.link_click_a').attr('id', '');
  420. }
  421. })
  422. // 筛选-------------
  423. var url = window.location.href;
  424. var searchParamsv2 = ''; //最后拼接的参数
  425. var urlParamsv2 = '';
  426. var cityUrlv2 = '';
  427. var objUrlv2 = {}; //获取get参数
  428. var paramsv2 = getParams(url); //获取get请求的参数
  429. if(!$.isEmptyObject(paramsv2)){
  430. $.each(paramsv2,function(key,val){
  431. if(key == 'city') feng_cityTel = val;
  432. objUrlv2[key] = val;
  433. urlParamsv2 += key+'='+val+'&';
  434. })
  435. urlParamsv2 = urlParamsv2.substring(0,urlParamsv2.length - 1);
  436. searchParamsv2 = '&'+ urlParamsv2;
  437. }
  438. var atrNamev2 ='';
  439. var _valv2 ='';
  440. $('.js_screen_box').on('click','a.js_filtrateBut',function(){
  441. var _this = $(this);
  442. var ParamsArrv2 = ['l','brand']; //搜索字段
  443. atrNamev2 = _this.attr('name');
  444. _valv2 = _this.attr('value');
  445. urlParamsv2 = '';
  446. for (var k in ParamsArrv2){
  447. if(ParamsArrv2[k] == atrNamev2){
  448. objUrlv2[atrNamev2] = _valv2;
  449. delete objUrlv2.page;
  450. delete objUrlv2.name;
  451. }
  452. }
  453. $.each(objUrlv2,function(key,val){
  454. urlParamsv2 += key+'='+val+'&';
  455. })
  456. cityUrlv2 = '';
  457. urlParamsv2 = urlParamsv2.substring(0,urlParamsv2.length - 1);
  458. _this.addClass('on').siblings().removeClass('on');
  459. })
  460. // 清空
  461. $('.js_unlimited').on('click',function(){
  462. var ParamsArrv2 = ['l','brand']; //搜索字段
  463. urlParamsv2 = '';
  464. for (var k in ParamsArrv2){
  465. objUrlv2[ParamsArrv2[k]]=0;
  466. }
  467. $.each(objUrlv2,function(key,val){
  468. urlParamsv2 += key+'='+val+'&';
  469. })
  470. // console.log(urlParamsv2)
  471. cityUrlv2 = '';
  472. urlParamsv2 = urlParamsv2.substring(0,urlParamsv2.length - 1);
  473. $('.js_screen_box a.js_filtrateBut').removeClass('on');
  474. window.location.href = '/house/search?'+ cityUrlv2+urlParamsv2;
  475. })
  476. // 确认
  477. $('.js_confirm').on('click',function(){
  478. if(_valv2 != '' && atrNamev2 !=''){
  479. window.location.href = '/house/search?'+ cityUrlv2+urlParamsv2;
  480. // console.log( cityUrlv2+urlParamsv2)
  481. }else{
  482. var M = {};
  483. if(M.dialog1){
  484. return M.dialog1.show();
  485. }
  486. M.dialog1 = jqueryAlert({
  487. 'content' : '请选择', //txt 提示内容
  488. 'closeTime' : 2000,
  489. })
  490. }
  491. })
  492. //获取url中的参数----选中效果--------
  493. function getUrlParam(name) {
  494. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  495. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  496. if (r != null) return unescape(r[2]); return null; //返回参数值
  497. }
  498. var _label = getUrlParam('l');
  499. var _brand = getUrlParam('brand');
  500. // 筛选条件展示 ---------------
  501. var _hi=''
  502. // console.log(objUrlv2)
  503. $.each(objUrlv2,function(key,val){
  504. // console.log(key)
  505. if (val!=0 && val!='') {
  506. if (key=='l') {
  507. _hi=$('.y_v3filtrateList a[name="'+key+'"][value="'+val+'"]').text();
  508. $('.js_conditionBox').append('<span class="js_conditionLi" value="0" name="'+key+'"><em>'+_hi+'</em><i><img src="/image/lptj03.png" alt=""></i></span>')
  509. }else if (key=='brand') {
  510. _hi=$('.y_v3filtrateList a[name="'+key+'"][value="'+val+'"]').text();
  511. $('.js_conditionBox').append('<span class="js_conditionLi" value="0" name="'+key+'"><em>'+_hi+'</em><i><img src="/image/lptj03.png" alt=""></i></span>')
  512. }
  513. }
  514. })
  515. // 点击展示筛选条件------------------
  516. $('.js_conditionBox').on('click','span.js_conditionLi',function(){
  517. var urlParamsv3=''
  518. $(this).remove();
  519. var _CondId=$(this).attr('value');
  520. var _CondName=$(this).attr('name');
  521. $.each(objUrlv2,function(key,val){
  522. objUrlv2[_CondName]=_CondId;
  523. })
  524. $.each(objUrlv2,function(key,val){
  525. urlParamsv3 += key+'='+val+'&';
  526. })
  527. cityUrlv2 = '';
  528. urlParamsv3 = urlParamsv3.substring(0,urlParamsv3.length - 1);
  529. window.location.href = '/house/search?'+ cityUrlv2+urlParamsv3;
  530. })
  531. })