$(function(){ // ========================================================== // owl-slider 控制 // ========================================================== function owlControl() { const picAmount = $('.store-banner').children().length if(picAmount) { $(".store-banner").owlCarousel({ loop : true, items : 1, nav : true, navText : ['',''], dots:true, autoplay:true, navSpeed:1000, autoplayTimeout:8000, autoplaySpeed:1000, dotsSpeed:1000, }); } else { $('.store-banner').remove() } } function ajax_rack_detail(rack_id){ $.post('/store/ajax/ajax_get_rack_data-p.php', {ID :rack_id}, function(h){ $("#data_name").attr('class',h.TStore); $("#map").html(h.Google_Map); $("#rack_pic").attr('src',h.Pic_Path); $("#class_name").html(h.className); $("#data_name").html(h.Name); $("#address").html(h.Address); $("#tel").html(h.Tel); $("#open").html(h.Open); $("#rack_content").html(h.Content); $("#store_banner").trigger('destroy.owl.carousel'); $("#store_banner").html(h.Store_Img); $("div.news").html("").html(h.Rack_Detail); if(h.Rack_Detail){ $(".news-title").show(); }else{ $(".news-title").hide(); } if(h.Pic_Path){ $("#rack_pic").show(); } else{ $("#rack_pic").hide(); } owlControl(); }, 'json'); } function update_list(data='') { var cid = $('#rack_class').val(), city = $('#city_id').val(), kind = $('#kind_id').val(); $.ajax({ url:'/store/ajax/ajax_get_rack_list.php', type:'POST', cache:false, data:'cid='+cid+'&city='+city+'&kind='+kind+data, error:function(d) { alert(d.responseText); }, success:function(d) { //更新內容 $('#List_Box').html(d); //更新下拉選單 $('#kind_id').html($("#Ajax_Update_Kind").val()); //處理位置 if(parseInt(cid) <= 0 && parseInt(city) <= 0 && parseInt(kind) <= 0) { if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var pos = { lat: position.coords.latitude, lng: position.coords.longitude }; $(document).ready(function(){ $.post("/ajax/ajax_get_store_distance.php", { lat: position.coords.latitude, lng: position.coords.longitude }, function(data,status){ $('.Store_Item').hide(); data = JSON.parse(data); for(var k in data) { $('#'+data[k]['ID']).show(); } } ); }); },function() { handleLocationError(true, infoWindow, map.getCenter()); }); } else { handleLocationError(false, infoWindow, map.getCenter()); } } var first = $("#List_Box").find("#store").attr('rack_id'); ajax_rack_detail(first); $(".Store_Item:visible").eq(0).find(".view_detail").trigger('click'); } }) } $('.inner').on('click', '.view_detail', function(event) { var rack_id = $(this).attr('rack_id'); ajax_rack_detail(rack_id); }); $("#rack_class,#city_id,#kind_id").on("change",function(){ update_list('&send=1'); }); owlControl(); update_list(); });