mui.init();
mui('.mui-scroll-wrapper').scroll();
var pageNumber = 1;
var pageSize=10;
var droploader;
/**
*初始化、添加监听
*/
mui.ready(function(){
getCategory();
getProduct("");
$('.mui-bar-tab').on('tap', 'a', function(e) {
location.href=$(this).attr("href");
});
$(".mui-segmented-control").on("tap",".mui-control-item",function(e){
pageNumber=1;
$(".product").empty();
$(".dropload-down").remove();
getProduct($(this).attr("data-id"));
});
//跳转
$(".product").on('tap','li',function(){
location.href=base+'/mobile/productDetail.jsp?id='+$(this).attr('data-id');
});
//推广
$("#tuiguang").on('tap',function(){
if(user.is_share=='1'){
$("#share").show();
}else{
location.href=base+'/mobile/userInfo.jsp?flag=1';
}
});
$("#kefu").on("tap",function(e){
var html=[];
html.push('
' +
'电话:'+mobile.getParam('customer_tel')+'');
mui.alert(html.join(""), '长按二维码联系客服');
});
//分享
$(".share-bg").on('tap',function(){
$("#share").hide();
});
//分享
$(".share-img").on('tap',function(){
$("#share").hide();
});
});
/**
*获取导航
*/
function getNav(){
mobile.ajaxPost(base+'/wxNav/getList',{},function(json){
$(".nav").empty();
if(json.data){
$.each(json.data,function(id,item){
if(item.type=="10"){//轮播
$(".nav").append('
');
$("#slider .mui-slider-group").append('');
if(item.list.length>1){//数量大于1定时滚动
$.each(item.list,function(id2,item2){
$("#slider .mui-slider-group").append('');
if(id2==0){
$("#slider .mui-slider-indicator").append('');
}else{
$("#slider .mui-slider-indicator").append('');
}
});
}else{//数量等于1
$("#slider .mui-slider-group").append('');
}
$("#slider .mui-slider-group").append('');
if(item.list.length>1){
var slider = mui("#slider");
slider.slider({
interval: 3000
});
}
}
});
//$(".nav").append('');
$("img.slider-lazy").lazyload({
threshold : 200,
effect: "fadeIn",
placeholder: base+'/static/mobile/image/500.gif',
skip_invisible : false
});
}
},"");
}
function getCategory() {
mobile.ajaxPost(base+'/productCategory/getList',{"navShow":"1"},function(json){
if(json.data&&json.data.length>0){
$(".mui-segmented-control .mui-scroll").append('全部');
$.each(json.data,function (id,item) {
$(".mui-segmented-control .mui-scroll").append(''+item.cat_name+'');
});
}
});
}
/**
*获取导航
*/
function getProduct(type){
if (droploader){
droploader.lock();
droploader.noData();
droploader.resetload();
}
if(!type){
type="";
}
droploader = $('.product-content').dropload({
scrollArea : window,
loadDownFn : function(me){
mobile.ajaxPost(base+'/product/getList',{
type: type,
productType: "10",
pageSize: pageSize,
pageNumber: pageNumber
},function(json){
if(json.list&&json.list.length>0){
if(pageNumber==json.totalPage){
me.lock();
me.noData();
}else{
pageNumber++;
}
var html=[];
jQuery.each(json.list,function(id,item){
html.push('');
html.push('');
html.push('

');
if(item.order_hour<=0){
html.push('
免预约')
}
html.push('
');
html.push('');
html.push('
'+item.merchant_name+'
');
html.push('
'+item.product_name+'
');
html.push('
');
html.push('¥'+item.product_price+''+item.product_old_price+'元');
if(item.share_price&&user.is_share=="1"){
html.push('佣金¥'+item.share_price+'')
}else{
html.push('')
}
if(item.time_status==0){
html.push('马上抢');
}else if(item.time_status==1){
html.push('已抢完');
}else if(item.time_status==2){
html.push('已结束');
}else{
html.push('已过期');
}
html.push('
');
html.push('
');
html.push('');
if(item.time_status!=3){
html.push(''+item.visit_num+'人关注');
}else{
html.push(''+item.visit_num+'人关注');
}
html.push('
');
html.push('
');
html.push('');
if(item.time_status!=3){
clearInterval(interval);
var interval= setInterval(function() {
var data_id=item.id;
var typeName;
var time;
var leftTime
if(item.time_status==0){
leftTime = (new Date(item.end_time.replace(/-/g, "/"))) - (new Date()); //计算剩余的毫秒数
typeName = "结束";
}else{
leftTime = (new Date(item.use_time.replace(/-/g, "/"))) - (new Date()); //计算剩余的毫秒数
typeName = "过期";
}
var days = parseInt(leftTime / 1000 / 60 / 60 / 24 , 10); //计算剩余的天数
var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //计算剩余的小时
var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟
var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
hours = checkTime(hours);
minutes = checkTime(minutes);
seconds = checkTime(seconds);
$("li[data-id='"+data_id+"'] .end_time").html("剩"+days+"天" + hours+"小时" + minutes+"分"+seconds+"秒"+typeName);
}, 1000);
}
});
$(".product").append(html.join(""));
droploader.resetload();
// $("img.product-lazy").lazyload({
// threshold : 200,
// effect: "fadeIn",
// placeholder: base+'/static/mobile/image/100.gif',
// skip_invisible : false
// });
}else{
droploader.lock();
droploader.noData();
droploader.resetload();
}
});
}
});
}
function checkTime(i){ //将0-9的数字前面加上0,例1变为01
if(i<10)
{
i = "0" + i;
}
return i;
}