qlg.frontend/js/choiceness.js
2019-09-06 10:45:33 +08:00

317 lines
12 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

$('.mui-slider-indicator').html('')
mui.init({
pullRefresh: {
container: '#pullrefresh',
down: {
style: 'circle', //必选下拉刷新样式目前支持原生5+ circle 样式
color: '#2BD009', //可选,默认“#2BD009” 下拉刷新控件颜色
height: '50px', //可选,默认50px.下拉刷新控件的高度,
range: '100px', //可选 默认100px,控件可下拉拖拽的范围
offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
// auto: true, //可选,默认false.首次加载自动上拉刷新一次
contentdown: "下拉可以刷新", //可选,在下拉可刷新状态时,下拉刷新控件上显示的标题内容
contentover: "释放立即刷新", //可选,在释放可刷新状态时,下拉刷新控件上显示的标题内容
contentrefresh: "正在刷新...", //可选,正在刷新状态时,下拉刷新控件上显示的标题内容
callback: pulldownRefresh //必选刷新函数根据具体业务来编写比如通过ajax从服务器获取新数据
},
up: {
contentrefresh: '正在加载...',
callback: pullupRefresh
}
}
});
var count = 1;
function pullupRefresh() {
count += 1;
////console.log(count)
setTimeout(function() {
mui('#pullrefresh').pullRefresh().endPullupToRefresh();
// //console.log(order_class)
mui.ajax(qlgUrl('addon/hyhchosen-Hyhchosen-getChosen'), {
data: {
page: count,
goodsSize: 3,
pagesize: 10
},
dataType: 'json', //服务器返回json格式数据
type: 'post', //HTTP请求类型
timeout: 10000, //超时时间设置为10秒
success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;
// //console.log(data.data.goodsFavoritesNum)
// //console.log(data.data.Rows)
var data = toJson(data);
if (data.status == 1) {
data = data.data;
if (data.Rows.length == 0) {
mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
return;
}
var html = ''
$.each(data.Rows, function() {
html += '<div class="block"><div class="b_title" data-shopId="' + this.shopId +
'"><img class="b_img" src="' + hyhImgUrl(this.shopImg) + '" /><p class="storename">' + this.shopName +
'</p><p class="time">' + this.newTime +
'</p><div class="btn_gz">+ 关注</div></div><div class="b_con clearfix">';
$.each(this.goods, function() {
html += '<div data-goodsId="' + this.goodsId + '" class="bc_img"><img src="' + hyhImgUrl(this.goodsImg) +
'" /><p>¥' + this.shopPrice + '</p></div>';
});
html += '</div></div>'
});
$('.con').append(html);
} else {
mui.alert(data.msg)
////console.log(data.status)
}
},
error: function(xhr, type, errorThrown) { //异常处理;
// mui.alert(type);
}
});
}, 500);
}
/**
* 下拉刷新具体业务实现
*/
function pulldownRefresh() {
setTimeout(function() {
window.location.reload();
mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
}, 1500);
}
mui.plusReady(function() {
function openAds(item) {
if (item.attr('data-adURL') == '' || item.attr('data-targetType') == 0) {
return;
}
var adURL = item.attr('data-adURL');
var targetType = '';
var data_set = {};
if (item.attr('data-targetType') == 1) {
//商品
targetType = 'details.html';
data_set = {
data_id: adURL
}
} else if (item.attr('data-targetType') == 2) {
//商家
targetType = 'storeout.html';
if (adURL == 1) {
// targetType='self_shop.html';
}
data_set = {
shopId: adURL
}
} else if (item.attr('data-targetType') == 3) {
//活动
targetType = adURL + '.html';
}
mui.openWindow({
url: targetType,
id: targetType + adURL,
styles: {
top: '0px', //新页面顶部位置
bottom: '0px', //新页面底部位置
width: '100%', //新页面宽度默认为100%
height: '100%' //新页面高度默认为100%
},
extras: data_set,
createNew: false, //是否重复创建同样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, //等待框背景区域高度,默认根据内容自动计算合适高度
// ......
}
}
})
}
var data = '';
mui.ajax(qlgUrl('addon/hyhchosen-Hyhchosen-getChosen'), {
data: {
pagesize: 10,
goodsSize: 3,
page: 1
},
dataType: 'json', //服务器返回json格式数据
type: 'post', //HTTP请求类型
timeout: 10000, //超时时间设置为10秒
success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;
data = toJson(data);
if (data.status == 1) {
data = data.data;
var html = '';
$.each(data.Rows, function() {
html += '<div class="block"><div class="b_title" data-shopId="' + this.shopId +
'"><img class="b_img" src="' + hyhImgUrl(this.shopImg) + '" /><p class="storename">' + this.shopName +
'</p><p class="time">' + this.newTime +
'</p><div class="btn_gz">+ 关注</div></div><div class="b_con clearfix">';
$.each(this.goods, function() {
html += '<div data-goodsId="' + this.goodsId + '" class="bc_img"><img src="' + hyhImgUrl(this.goodsImg) +
'" /><p>¥' + this.shopPrice + '</p></div>';
});
html += '</div></div>'
});
$('.con').html(html)
if (data.chosenAdsList.length != 0) {
var html1 = '<div class="mui-slider-group mui-slider-loop"><div data-adId="' + data.chosenAdsList[data.chosenAdsList
.length - 1].adId + '" class="mui-slider-item mui-slider-item-duplicate"><a href="#"><img src="' +
hyhImgUrl(data.chosenAdsList[data.chosenAdsList.length - 1].adFile) + '"></a></div>';
var html2 = '<div class="mui-slider-indicator">';
$.each(data.chosenAdsList, function() {
html1 += '<div data-adId="' + this.adId + '"data-adURL="' + this.adURL + '"data-targetType="' + this.targetType +
'" class="mui-slider-item "><a href="#"><img src="' + hyhImgUrl(this.adFile) + '"></a></div>'
html2 += '<div class="mui-indicator"></div>'
})
html2 += '</div>'
html1 += '<div data-adId="' + data.chosenAdsList[0].adId + '"data-adURL="' + data.chosenAdsList[0].adURL +
'"data-targetType="' + data.chosenAdsList[0].targetType +
'" class="mui-slider-item mui-slider-item-duplicate"><a href="#"><img src="' + hyhImgUrl(data.chosenAdsList[
0].adFile) + '"></a></div></div>'
html1 += html2;
$('#slider').html(html1);
mui("#slider").slider({
interval: 5000
});
document.getElementsByClassName('mui-indicator')[0].className += ' mui-active';
}
} else {
mui.alert(data.msg)
}
},
error: function(xhr, type, errorThrown) { //异常处理;
// mui.alert(type);
}
});
mui('.con').on('tap', '.storename', function() {
var shopId = $(this).parent().attr('data-shopId');
var url = 'storeout.html';
if (shopId == 1) {
// url='self_shop.html'
}
mui.openWindow({
url: url,
id: url + shopId,
styles: {
top: '0px', //新页面顶部位置
bottom: '0px', //新页面底部位置
width: '100%', //新页面宽度默认为100%
height: '100%' //新页面高度默认为100%
},
extras: {
shopId: shopId
// ..... //自定义扩展参数,可以用来处理页面间传值
},
createNew: false, //是否重复创建同样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, //等待框背景区域高度,默认根据内容自动计算合适高度
// ......
}
}
})
})
mui('.con').on('tap', '.bc_img', function() {
var goodsId = $(this).attr('data-goodsId');
mui.openWindow({
url: 'details.html',
id: 'details.html' + goodsId,
styles: {
top: '0px', //新页面顶部位置
bottom: '0px', //新页面底部位置
width: '100%', //新页面宽度默认为100%
height: '100%' //新页面高度默认为100%
},
extras: {
data_id: goodsId
// ..... //自定义扩展参数,可以用来处理页面间传值
},
createNew: false, //是否重复创建同样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, //等待框背景区域高度,默认根据内容自动计算合适高度
// ......
}
}
})
})
mui('.con').on('tap', '.btn_gz', function() {
var shopId = $(this).parent().attr('data-shopId');
var that = $(this);
mui.ajax(hyhUrl('app/Favorites/add'), {
data: {
id: shopId,
type: 1
},
dataType: 'json', //服务器返回json格式数据
type: 'post', //HTTP请求类型
timeout: 10000, //超时时间设置为10秒
success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;
// //console.log(data.data.goodsFavoritesNum)
// //console.log(data.data.Rows)
var data = toJson(data);
if (data.status == 1) {
that.html('已关注');
that.addClass('btn_gz1').removeClass('btn_gz');
} else {
mui.alert(data.msg) ////console.log(data.status)
}
},
error: function(xhr, type, errorThrown) { //异常处理;
// mui.alert(type);
}
});
})
//轮播图跳转
$('#slider').on('tap', '.mui-slider-item', function() {
openAds($(this));
})
})