window.onload = function() {
httpBaseInfo();
$('#div_body').removeClass('ui_hide');
}
function httpBaseInfo() {
$.ajax({
type: "post",
url: $$.base_api + 'home/home/home-list',
dataType: 'json',
success: function(res_data) {
$$.ZZLog(res_data);
if(res_data.flag == false) {
$$.alert(res_data.msg);
} else {
replaceBaseInfo(res_data.data);
}
},
error: function() {
alert($$.infoApiError);
}
});
// var temp_lunbo = "";
//轮播
// for(var i = 0, j = 3; i < j; i++) {
// // var str = data.recomList[i].toUrl;
// temp_lunbo += '
'
// }
// $(".swiper-wrapper").html(temp_lunbo);
//轮播空间swiper
// var swiper = new Swiper('.swiper-container', {
// pagination: '.swiper-pagination',
// loop: true,
// paginationClickable: true,
// centeredSlides: true,
// autoplay: 2000,
// autoplayDisableOnInteraction: false,
// onTouchEnd: function(swiper) {
// if(Math.abs(swiper.touches.currentX - swiper.touches.startX) < 3) {
// location.href = $('.swiper-container img').eq(swiper.activeIndex).attr('to_url');
// }
// }
// updateFormElements : true,//当内嵌图像加载完成之后 会重新初始化对象
// followFinger: false
// });
// $("img.lazy-load").lazyload({
// threshold: -120,
// effect: "fadeIn"
// });
// $(".lazy-load").lazyload({
// threshold: -70,
// effect: "fadeIn"
// })
window.tabbar.init({ index: 0, }, function(n) {
console.log(n);
});
}
//替换数据
function replaceBaseInfo(data) {
//轮播
var banner_list = data.banner_list;
var temp_banner = '';
banner_list.forEach(function(dict, index) {
temp_banner += ''
});
$(".swiper-wrapper").html(temp_banner);
var swiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
loop: true,
paginationClickable: true,
centeredSlides: true,
autoplay: 2000,
autoplayDisableOnInteraction: false,
onTouchEnd: function(swiper) {
if(Math.abs(swiper.touches.currentX - swiper.touches.startX) < 3) {
location.href = $('.swiper-container img').eq(swiper.activeIndex).attr('to_url');
}
}
});
//热门目的地
var hot_area_list = data.hot_area;
var temp_hot_area = '';
hot_area_list.forEach(function(dict, index) {
temp_hot_area += '' + dict.area_name + '
';
})
$('.hot_area_info').html(temp_hot_area);
$('.hot_area').on('click', function() {
var area_id = $(this).attr('area_id');
$$.ZZLog(area_id);
});
//主分类
$('.sigle_cms').on('click', function() {
var cms_id = $(this).attr('cms_id');
$$.ZZLog(cms_id);
});
//广告
$('.ad').attr('data-original', data.ad.img);
$('.ad').attr('to_url', data.ad.toUrl);
$('.ad').on('click', function() {
var to_url = $(this).attr('to_url');
$$.ZZLog(to_url);
});
//猜你喜欢
var like_list = data.like.like_list;
var temp_like = '';
like_list.forEach(function(dict, index) {
// if (index == 1) {
// dict.show_img = 'http://img.zhizhuchuxing.cn/wechat/ad1.jpg';
// }else if(index == 2){
// dict.show_img = 'http://h5.sztoda.cn/static/img/loveLetter/teacher/teacher4.jpg';
// }else{
// dict.show_img = 'http://h5.sztoda.cn/static/img/loveLetter/teacher/teacher3.jpg';
// }
var t_star = dict.star;
var star = parseFloat(t_star).toFixed(1);
var star_integer = parseInt(star);
var star_flt = star - star_integer;
//全星
var star_o_s = '';
for (var i = 0; i < star_integer; i++) {
star_o_s+='';
}
//判断是否填充半星
if (star_integer<5 && star_flt > 0) {
star_o_s+=''
}
//判断是否还要填充空星
var star_e = 5 - star;
if(star_e >= 1){
star_o_s += ''
}
// '' +
// '' +
// '' +
// '' +
// '' +
temp_like += '' +
'
' +
'
' +
'
' +
'
' + dict.pro_cate_name + '
' +
'
' +
'' + dict.category_name + '' +
'
' +
'
' +
'
' +
'
' +
'
评分' + dict.star + '
' +
'
' +
star_o_s +
'
' +
'
' +
'
月销' + dict.sales_count + '单
' +
'
' +
'
' +
'
原价' + dict.original_price + '元
' +
'
¥' + dict.show_price + '起
' +
'
' +
'
' +
'
' +
'
' +
'
';
})
$('.like_list').html(temp_like);
// var t_star = $('.star_ary').attr('star');
// var star = parseFloat(t_star).toFixed(1);
// var star_integer = parseInt(star);
// var star_flt = star - star_integer;
// for(var i = 0; i < star_integer; i++) {
// console.log($('.star_ary').children().eq(i).c);
// $('.star_ary').children().eq(i).css('background-image', 'url(images/home/staro.png)');
// }
//精品推荐
var recommon_list = data.recommon.recommon_list;
var temp_recommon = '';
var one = '';
recommon_list.forEach(function(dict, index) {
if(index % 2 == 0) {
var left_html = getHtmlByDict(dict);
one += '';
one += left_html;
one += '
';
} else {
var right_html = getHtmlByDict(dict);
one += right_html;
one += '
';
temp_recommon += one;
one = '';
}
});
$('.recommon_info').html(temp_recommon);
$(".lazy-load").lazyload({
threshold: -70,
effect: "fadeIn"
})
}
function getHtmlByDict(dict) {
if(dict.show_img == '') {
dict.show_img = 'images/home/product02loading.png';
}
var html = '' +
'
' +
'
' +
'
' + dict.pro_cate_name + '
' +
'
' +
'
原价' + dict.original_price + '元
' +
'
' +
'¥' + dict.show_price + '起' +
'
' +
'
' +
'
' +
'
'
return html;
}
//查询产品
function goToSearch() {
window.location.href = './prod_search.html';
}