var search_info = ""; var current_loc = null; var longitude = ''; //经度 var latitude = ''; //纬度 var street = getCookie('street') ? getCookie('street') : ''; var point = getCookie('point') ? getCookie('point') : ''; $(document).ready(function() { ifLogin(function(flag) { $("#show_html").show(); var search_h = $("#search").height(); var all_h = $(document).height() - 44; var list_h = all_h - search_h; $("#prod_list").height(list_h); $("#navbar-example").height(list_h); if(street == '') { get_list(); getLocation(); } else { $('#dingwei').text(street); $('#dingwei').show(); get_list(); // getLocation(); } // get_list(); // getLocation(); $('#search_input').on('input', function(e) { var input_text = $("#search_input").val(); if(input_text != "") { $(".search_r").show(); $("#go_search").show(); delay(function() { get_list(); }, 1500); } else { $(".search_r").hide(); $("#go_search").hide(); get_list(); } }); $('#cancel').on('click', function() { $("#search_input").val(""); $(".search_r").hide(); $("#go_search").hide(); get_list(); }); $('#go_search').on('click', function() { get_list(); }); }); //滚动监听 //滚动监听 // $("#prod_list").scroll(function(){ //var arr = []; //$(".prod_scroll").each(function(index,dom){ // var top_h=$("#search").height(); // var div_h = $(dom).offset().top; // // var t=top_h-div_h; // arr.push($(dom).attr('id')); // if(t>-1 && t<=30){ // var this_id_name=$(dom).attr('id'); // var t = $('a[href="#'+this_id_name+'"]'); // // console.log(this_id_name); // console.log('%ccoding..........................................','font-size:20px;color:red;'); // $('#left_menu li').removeClass('active'); // $('a[href="#'+this_id_name+'"]').parent().addClass('active'); // } // if(t>=-30 && t<1){ // console.log('top_h',top_h,'-----------div_h',div_h,'tttttttttt=',t); // var i = index; // if(i>0){ // i = i-1; // }else{ // i=0; // } // $('#left_menu li').removeClass('active'); // $('a[href="#'+arr[i]+'"]').parent().addClass('active'); // // } // //}); //}); }); function get_list() { search_info = $("#search_input").val(); ZZLog(point); // point = '121.321586' + ',' + '31.203112'; $.ajax({ url: base_api + "prod/prod/get-prod-list", //请求地址 data: { where: search_info, point: point }, type: "post", dataType: "json", async: false, success: function(res_data) { console.log(res_data) if(res_data.flag) { list_html(res_data.data); $('#left_menu li:first').addClass('active'); $('#prod_list').animate({ scrollTop: 0 }, 200); } else { if(codeNotLogin == res_data['code']) { location.href = res_data['url']; } else if(codeNotRegister == res_data['code']) { location.href = 'register.html'; } else { alert(res_data['msg']); } } }, error: function(error) { console.log(error); } }); } function list_html(data) { var left_temp = ""; var right_temp = ""; for(var i = 0, j = data.prod_list.length; i < j; i++) { if(data.prod_list[i].cms_category_id == 2) { left_temp += '
  • ' + data.prod_list[i].category_name + '
  • ' } else { left_temp += '
  • ' + data.prod_list[i].category_name + '
  • ' } var length = data.prod_list[i].recom_arr.length; if(length > 0) { for(var h = 0; h < length; h++) { // right_temp = '
    ' if(h == 0) { right_temp += '
    ' + data.prod_list[i].category_name + '(' + data.prod_list[i].recom_arr.length + ')' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + data.prod_list[i].prod_arr[h].pro_cate_name + '
    ' + '
    ' + data.prod_list[i].prod_arr[h].prod_des + '
    ' + '
    ' + '' + '
    ' + data.prod_list[i].prod_arr[h].show_price + '
    ' + '
    ' + '
    ' + '
    ' } else { right_temp += '
    ' + '
    ' + '
    ' + '
    ' + data.prod_list[i].recom_arr[h].pro_cate_name + '
    ' + '
    ' + data.prod_list[i].recom_arr[h].prod_des + '
    ' + '
    ' + '' + '
    ' + data.prod_list[i].recom_arr[h].show_price + '
    ' + '
    ' + '
    ' + '
    ' } } right_temp += '
    点击查看全部
    ' right_temp += ''; // right_temp += '
    '; } else { for(var h = 0, k = data.prod_list[i].prod_arr.length; h < k; h++) { if(h == 0) { right_temp += '
    ' + data.prod_list[i].category_name + '(' + data.prod_list[i].prod_arr.length + ')' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + data.prod_list[i].prod_arr[h].pro_cate_name + '
    ' + '
    ' + data.prod_list[i].prod_arr[h].prod_des + '
    ' + '
    ' + '' + '
    ' + data.prod_list[i].prod_arr[h].show_price + '
    ' + '
    ' + '
    ' + '
    ' } else { right_temp += '
    ' + '
    ' + '
    ' + '
    ' + data.prod_list[i].prod_arr[h].pro_cate_name + '
    ' + '
    ' + data.prod_list[i].prod_arr[h].prod_des + '
    ' + '
    ' + '' + '
    ' + data.prod_list[i].prod_arr[h].show_price + '
    ' + '
    ' + '
    ' + '
    ' } } } } // right_temp += ''; $("#left_menu").html(left_temp); $("#prod_list").html(right_temp); if(data.prod_list.length == 0) { $('#no_info').show(); $('#prod_list').hide(); } else { $('#no_info').hide(); $('#prod_list').show(); } $("#left_menu li").on("click", function() { $("#left_menu li").removeClass("active"); $(this).addClass("active"); }); $(".click_prod").on("click", function() { var category_id = $(this).attr("category_id"); var pro_cate_id = $(this).attr("pro_cate_id"); setStorage("category_id", category_id); setStorage("pro_cate_id", pro_cate_id); if(category_id == "1") { window.location.href = "landmark_ticket.html?"+version; } else if(category_id == '1000') { window.location.href = 'station_ticket.html?'+version; } else { window.location.href = "scene_ticket.html?"+version; } }); } $('#refresh').on('click', function() { getLocation(); }) //定位 function getLocation() { $('#dingwei').text('正在定位……'); current_loc = new BMap.Geolocation(); var geoc = new BMap.Geocoder(); current_loc.getCurrentPosition(function(r) { if(this.getStatus() == BMAP_STATUS_SUCCESS) { var temp_street = ''; if(r.accuracy == null) { //用户决绝地理位置授权 alert('用户拒绝地理位置授权'); $('#dingwei').text('无法获取定位'); $('.dingwei').hide(); } else { longitude = r.longitude; latitude = r.latitude; point = longitude + ',' + latitude; geoc.getLocation(r.point, function(rs) { var addComp = rs.addressComponents; $('#dingwei').text(addComp.district + ' ' + addComp.street); temp_street = addComp.district + ' ' + addComp.street; $('.dingwei').show(); setCookie('point', point, 'h4'); setCookie('street', temp_street, 'd30'); if(street != temp_street) { get_list(); } }); } } }) } //查看更多 function seeMoreList(obj, count1, count2, index, id) { $(obj).hide(); $(obj).next().show(); var name = $(obj).attr('name'); var total = count1 + count2; $('#prod' + index + '' + id).text(name + '(' + total + ')'); }