453 lines
14 KiB
JavaScript
453 lines
14 KiB
JavaScript
|
||
var timestamp1 = Date.parse(new Date());
|
||
//$('.getquan').css('display', 'none');
|
||
$('#search').css('width', '82%');
|
||
$('#search').css('left', '5%');
|
||
$('.searchimg').css('left', '8%');
|
||
//$('.time').css('display', 'none');
|
||
//首页navId
|
||
$('.class_block').eq(0).attr('data-classifyId', 0);
|
||
$('.class_block').eq(1).attr('data-classifyId', 2);
|
||
$('.class_block').eq(2).attr('data-classifyId', 4);
|
||
$('.class_block').eq(3).attr('data-classifyId', 3);
|
||
$('.class_block').eq(4).attr('data-classifyId', 9);
|
||
$('.class_block').eq(5).attr('data-classifyId', 1);
|
||
$('.class_block').eq(6).attr('data-classifyId', 10);
|
||
$('.class_block').eq(7).attr('data-classifyId', 11);
|
||
$('.class_block').eq(8).attr('data-classifyId', 12);
|
||
$('.class_block').eq(9).attr('data-classifyId', '');
|
||
var $uList = $(".scroll-box ul");
|
||
var timer = null;
|
||
//触摸清空定时器
|
||
$uList.hover(function() {
|
||
clearInterval(timer);
|
||
},
|
||
function() { //离开启动定时器
|
||
timer = setInterval(function() {
|
||
scrollList($uList);
|
||
},
|
||
2000);
|
||
}).trigger("mouseleave"); //自动触发触摸事件
|
||
//滚动动画
|
||
function scrollList(obj) {
|
||
//获得当前<li>的高度
|
||
var scrollHeight = $("ul li:first").height();
|
||
//滚动出一个<li>的高度
|
||
$uList.stop().animate({
|
||
marginTop: -scrollHeight
|
||
},
|
||
600,
|
||
function() {
|
||
//动画结束后,将当前<ul>marginTop置为初始值0状态,再将第一个<li>拼接到末尾。
|
||
$uList.css({
|
||
marginTop: 0
|
||
}).find("li:first").appendTo($uList);
|
||
});
|
||
}
|
||
|
||
$('.bcon_left').height($('.bcon_left').width() * 345 / 185);
|
||
|
||
$('.bcr_block').height($('.bcr_block').width());
|
||
$('.addsct_block').height($('.addsct_block').width() * 225 / 355);
|
||
$('.addscb_block').height($('.addscb_block').width() * 260 / 180);
|
||
|
||
var page = 1;
|
||
var pagesize = 10;
|
||
var isjiazai = 1;
|
||
|
||
function getRecommend(page, pagesize) {
|
||
var recommenddata = {
|
||
page: page ? page : 1,
|
||
pagesize: pagesize ? pagesize : 10
|
||
}
|
||
if (isjiazai == 0) {
|
||
return;
|
||
} else {
|
||
isjiazai = 0;
|
||
}
|
||
mui.ajax(qlgUrl('app/index/getHotGoods'), {
|
||
data: recommenddata,
|
||
dataType: 'json', //服务器返回json格式数据
|
||
type: 'post', //HTTP请求类型
|
||
timeout: 10000, //超时时间设置为10秒;
|
||
success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;
|
||
// //console.log(data);
|
||
|
||
// var data = toJson(data, 1);
|
||
if (data.status == 1) {
|
||
//console.log(data);
|
||
|
||
var html = '';
|
||
var data = data.data;
|
||
if (data.Rows == '') {
|
||
$('.mui-scroll').append('<p style="float: left;width: 100%;text-align: center;padding-bottom: 9px;">没有更多商品</p>');
|
||
isjiazai = 0;
|
||
return;
|
||
}
|
||
$.each(data.Rows, function() {
|
||
|
||
html += '<div class="recommend_con_block shadown_wai" data-goodsId="' + this.goodsId +
|
||
'"><img class="rcb_img" src="' + ectImgUrl(this.goodsImg) +
|
||
'" alt="" /><div class="rcb_con"><div class="rcb_title"><span style="display:none;" data-shopId="' + this.shopId +
|
||
'">自营</span>' + this.goodsName + '</div><div class="rcb_pay">¥' + this.shopPrice +
|
||
' <span style="display:none;">满减</span></div><div class="rcb_bottom"><div><span>'+this.saleNum+'</span><span>人购买</span></div><div style="display:none"><span>优惠率 </span><span>'+this.discountRate+'%</span></div></div></div><img style="display:none;" class="icon_icon" src="../img/icon_sscl.png" alt="" /></div>';
|
||
});
|
||
|
||
if (page == 1) {
|
||
$('#recommend_con').html(html);
|
||
} else {
|
||
$('#recommend_con').append(html);
|
||
}
|
||
isjiazai = 1;
|
||
$('.rcb_title span').each(function() {
|
||
if ($(this).attr('data-goodsId') == 1) {
|
||
$(this).css('display', 'none');
|
||
}
|
||
})
|
||
$('.rcb_img').height($('.rcb_img').width());
|
||
|
||
} else {
|
||
// //console.log(2)
|
||
}
|
||
},
|
||
error: function(xhr, type, errorThrown) { //异常处理;
|
||
// mui.alert(errorThrown);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
|
||
//滚动动画
|
||
function scrollList(obj) {
|
||
//获得当前<li>的高度
|
||
var scrollHeight = $("ul li:first").height();
|
||
//滚动出一个<li>的高度
|
||
$uList.stop().animate({
|
||
marginTop: -scrollHeight
|
||
},
|
||
600,
|
||
function() {
|
||
//动画结束后,将当前<ul>marginTop置为初始值0状态,再将第一个<li>拼接到末尾。
|
||
$uList.css({
|
||
marginTop: 0
|
||
}).find("li:first").appendTo($uList);
|
||
});
|
||
}
|
||
mui.plusReady(function() {
|
||
var ua = navigator.userAgent.toLowerCase();
|
||
var issx = 0;
|
||
|
||
if (timestamp1 <= 1550678400000) {
|
||
//活动弹窗
|
||
var lxy_div =
|
||
'<div class="mui-backdrop lxy_home_zz" style="display: block;background-color: rgba(0,0,0,.7);" id="home_zhezhao"><div class="lxy_zz"><img src="' +
|
||
ectImgUrl('static/app2/img/showActive.png') + '" /></div></div>';
|
||
|
||
$('body').append(lxy_div);
|
||
}
|
||
//点击让遮罩层消失
|
||
mui('body').on('tap', '#home_zhezhao', function() {
|
||
$('#home_zhezhao').css('display', 'none');
|
||
});
|
||
|
||
//跳转活动会场
|
||
mui('#home_zhezhao').on('tap', '.lxy_zz', function() {
|
||
mui.openWindow({
|
||
url: 'journalism_con.html',
|
||
id: 'journalism_con.html21',
|
||
styles: {
|
||
top: '0px', //新页面顶部位置
|
||
bottom: '0px', //新页面底部位置
|
||
},
|
||
extras: {
|
||
data_articleId: 21
|
||
},
|
||
createNew: false, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
|
||
show: {},
|
||
waiting: {}
|
||
})
|
||
});
|
||
// 点击扫一扫
|
||
$('.saoyisao').on('tap',function () {
|
||
JZL.openWindow('saoyisao.html','saoyisao.html')
|
||
})
|
||
|
||
//bannerTop
|
||
mui.ajax(qlgUrl('app/appport/appBanner'), {
|
||
dataType: 'json', //服务器返回json格式数据
|
||
type: 'post', //HTTP请求类型
|
||
timeout: 10000, //超时时间设置为10秒;
|
||
success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;
|
||
var data = toJson(data, 1);
|
||
if (data.status == 1) {
|
||
var html = '';
|
||
var data = data.data;
|
||
$.each(data, function() {
|
||
html += '<div class="swiper-slide" data-adURL="' + this.adURL + '" data-targetType="' + this.targetType +
|
||
'"><img src="' + hyhImgUrl(this.adFile) + '" alt="" /></div>';
|
||
});
|
||
$('#top_banner .swiper-wrapper').html(html);
|
||
var swiper = new Swiper('#top_banner', {
|
||
pagination: '#top_banner_pagination',
|
||
spaceBetween: 0,
|
||
loop: true,
|
||
autoplay: 3500,
|
||
autoplayDisableOnInteraction: false
|
||
});
|
||
// console.log($('#top_banner').width());
|
||
var topBannerheight=($('#top_banner').width() )* 460 / 750;
|
||
// console.log(topBannerheight);
|
||
$('#top_banner').height(($('#top_banner').width() )* 460 / 750);
|
||
localStorage.setItem('topBannerheight',topBannerheight)
|
||
} else {
|
||
// //console.log(data.status)
|
||
}
|
||
},
|
||
error: function(xhr, type, errorThrown) { //异常处理;
|
||
// mui.alert(errorThrown);
|
||
}
|
||
});
|
||
//为你推荐
|
||
getRecommend(page, pagesize);
|
||
document.querySelector('.mui-scroll-wrapper').addEventListener('scroll', function(e) {
|
||
// 判断默认行为是否可以被禁用
|
||
if (e.cancelable) {
|
||
// 判断默认行为是否已经被禁用
|
||
if (!e.defaultPrevented) {
|
||
e.preventDefault();
|
||
}
|
||
}
|
||
if (scroll.y == scroll.maxScrollY) {
|
||
if (isjiazai == 1) {
|
||
page++;
|
||
getRecommend(page, pagesize);
|
||
}
|
||
}
|
||
if (-scroll.y < 0) {
|
||
num = 0;
|
||
} else if ((-scroll.y > 0 || scroll.y == 0) && -scroll.y < 150) {
|
||
num = -scroll.y / 150;
|
||
} else {
|
||
num = 1;
|
||
}
|
||
$('.header').css('background-color', 'rgba(255,255,255,' + num + ')')
|
||
|
||
if (-scroll.y < 75) {
|
||
$('.saoyisao').attr('src', '../img/saoyisao.png');
|
||
$('.msg').attr('src', '../img/icon_msg.png');
|
||
$('.search').attr('src', '../img/icon_search.png');
|
||
$('#search').css('background-color', 'white');
|
||
// $('#search').css('color', 'black');
|
||
// $('#keyword').css('color', 'black');
|
||
$('.header').removeClass('shadown_wai');
|
||
} else {
|
||
$('.saoyisao').attr('src', '../img/saoyisao1.png');
|
||
$('.msg').attr('src', '../img/icon_msg1.png');
|
||
$('.search').attr('src', '../img/icon_search1.png');
|
||
$('#search').css('background-color', '#d8d8d8');
|
||
// $('#search').css('color', 'white');
|
||
// $('#keyword').css('color', 'white');
|
||
$('.header').addClass('shadown_wai');
|
||
}
|
||
|
||
if (scroll.y > 80 && issx == 0) {
|
||
issx = 1;
|
||
setTimeout(function() {
|
||
location.reload()
|
||
}, 1000)
|
||
}
|
||
}, false)
|
||
setInterval(function() {
|
||
|
||
$('.add_top_left img').height($('.add_top_left img').width());
|
||
$('.add_top_right_con img').height($('.add_top_right_con img').width());
|
||
$('.add_bottom_con img').height($('.add_bottom_con img').width());
|
||
|
||
$('.rcb_img').height($('.rcb_img').width());
|
||
|
||
}, 100)
|
||
//轮播图跳转
|
||
$('#top_banner').on('tap', '.swiper-slide', function() {
|
||
openAds($(this));
|
||
})
|
||
|
||
mui('body').on('tap', '.bannerAdd', function() {
|
||
localStorage.setItem('aaaaaa', 1);
|
||
})
|
||
mui('.classify').on('tap', '.class_block', function() {
|
||
var classifyId = $(this).attr('data-classifyId');
|
||
var url = 'orSupermarket.html';
|
||
|
||
if (classifyId == 0) {
|
||
url = 'self_shop.html';
|
||
}
|
||
if (classifyId == '') {
|
||
url = 'classify.html';
|
||
}
|
||
|
||
mui.openWindow({
|
||
url: url,
|
||
id: url,
|
||
styles: {
|
||
top: '0px', //新页面顶部位置
|
||
bottom: '0px', //新页面底部位置
|
||
},
|
||
extras: {
|
||
classifyId: classifyId
|
||
// ..... //自定义扩展参数,可以用来处理页面间传值
|
||
},
|
||
createNew: false, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
|
||
show: {},
|
||
waiting: {}
|
||
})
|
||
})
|
||
// mui('body').on('tap', '.add_bcr', function() {
|
||
// //var brandId = $(this).attr('data-brandId');
|
||
//
|
||
// // openAds($(this));
|
||
// mui.openWindow({
|
||
// url: 'storeout.html',
|
||
// id: 'storeout.html' + shopId,
|
||
// styles: {
|
||
// top: '0px', //新页面顶部位置
|
||
// bottom: '0px', //新页面底部位置
|
||
// },
|
||
// extras: {
|
||
// shopId: shopId
|
||
// // ..... //自定义扩展参数,可以用来处理页面间传值
|
||
// },
|
||
// createNew: false, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
|
||
// show: {},
|
||
// waiting: {}
|
||
// })
|
||
// })
|
||
|
||
|
||
//领券
|
||
mui('body').on('tap', '.getquan', function() {
|
||
if (timestamp1 >= 1542470400000) {
|
||
mui.alert('敬请期待!');
|
||
return;
|
||
}
|
||
mui.openWindow({
|
||
url: 'god_ect.html',
|
||
id: 'god_ect.html',
|
||
styles: {
|
||
top: '0px', //新页面顶部位置
|
||
bottom: '0px', //新页面底部位置
|
||
},
|
||
extras: {
|
||
// data_keyword: searchName
|
||
// ..... //自定义扩展参数,可以用来处理页面间传值
|
||
},
|
||
createNew: false, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
|
||
show: {},
|
||
waiting: {}
|
||
})
|
||
})
|
||
|
||
//搜索
|
||
$('#keyword').on('focus', function() {
|
||
$(".search button").css('display', 'block');
|
||
})
|
||
$('#keyword').on('blur', function() {
|
||
$(".search button").css('display', 'none');
|
||
})
|
||
$(".search button").on('tap', function() {
|
||
var searchName = $('#keyword').val();
|
||
var url = '';
|
||
// e.preventDefault();
|
||
// //console.log(searchName)
|
||
//请求搜索接口
|
||
// //console.log($('.search select').val())
|
||
if ($('.search select').val() == 0) {
|
||
url = 'goodslist.html';
|
||
} else if ($('.search select').val() == 1) {
|
||
url = 'shopsList.html';
|
||
}
|
||
|
||
mui.openWindow({
|
||
url: url,
|
||
id: url + searchName,
|
||
styles: {
|
||
top: '0px', //新页面顶部位置
|
||
bottom: '0px', //新页面底部位置
|
||
width: '100%', //新页面宽度,默认为100%
|
||
height: '100%' //新页面高度,默认为100%
|
||
},
|
||
extras: {
|
||
data_keyword: searchName
|
||
// ..... //自定义扩展参数,可以用来处理页面间传值
|
||
},
|
||
createNew: true, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
|
||
show: {
|
||
// autoShow: true, //页面loaded事件发生后自动显示,默认为true
|
||
// aniShow: animationType, //页面显示动画,默认为”slide-in-right“;
|
||
// duration: animationTime, //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒;
|
||
// event: 'titleUpdate', //页面显示时机,默认为titleUpdate事件时显示
|
||
// extras: {} //窗口动画是否使用图片加速
|
||
},
|
||
waiting: {
|
||
autoShow: true, //自动显示等待框,默认为true
|
||
title: '正在加载...', //等待对话框上显示的提示内容
|
||
options: {
|
||
// width: waiting - dialog - widht, //等待框背景区域宽度,默认根据内容自动计算合适宽度
|
||
// height: waiting - dialog - height, //等待框背景区域高度,默认根据内容自动计算合适高度
|
||
// ......
|
||
}
|
||
}
|
||
})
|
||
$('#keyword').val("")
|
||
})
|
||
$("#keyword").on('keypress', function(e) {
|
||
var keycode = e.keyCode;
|
||
var searchName = $(this).val();
|
||
var url = '';
|
||
if (keycode == '13') {
|
||
// e.preventDefault();
|
||
// //console.log(searchName)
|
||
//请求搜索接口
|
||
// //console.log($('.search select').val())
|
||
if ($('.search select').val() == 0) {
|
||
url = 'goodslist.html';
|
||
} else if ($('.search select').val() == 1) {
|
||
url = 'shopsList.html';
|
||
}
|
||
|
||
mui.openWindow({
|
||
url: url,
|
||
id: url + searchName,
|
||
styles: {
|
||
top: '0px', //新页面顶部位置
|
||
bottom: '0px', //新页面底部位置
|
||
width: '100%', //新页面宽度,默认为100%
|
||
height: '100%' //新页面高度,默认为100%
|
||
},
|
||
extras: {
|
||
data_keyword: searchName
|
||
// ..... //自定义扩展参数,可以用来处理页面间传值
|
||
},
|
||
createNew: true, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
|
||
show: {
|
||
// autoShow: true, //页面loaded事件发生后自动显示,默认为true
|
||
// aniShow: animationType, //页面显示动画,默认为”slide-in-right“;
|
||
// duration: animationTime, //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒;
|
||
// event: 'titleUpdate', //页面显示时机,默认为titleUpdate事件时显示
|
||
// extras: {} //窗口动画是否使用图片加速
|
||
},
|
||
waiting: {
|
||
autoShow: true, //自动显示等待框,默认为true
|
||
title: '正在加载...', //等待对话框上显示的提示内容
|
||
options: {
|
||
// width: waiting - dialog - widht, //等待框背景区域宽度,默认根据内容自动计算合适宽度
|
||
// height: waiting - dialog - height, //等待框背景区域高度,默认根据内容自动计算合适高度
|
||
// ......
|
||
}
|
||
}
|
||
})
|
||
|
||
}
|
||
});
|
||
})
|