123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- var goods_list = []
- var loadingFlag = true;
- var page=1;
- var token = ''
- $().ready(function(){
- getToken()
- $(window).scroll(function(){
- if($(window).scrollTop()>= $(document).height()-$(window).height() - 20){
- //到达底部加载数据
- if(loadingFlag){
- page ++ ;
- listGoods();
- }
- }
- });
- })
- //获取token
- function getToken () {
- var param = '{"js_callback" : "callBackMethodName"}';
- try{
- if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
- window.webkit.messageHandlers.app_h5_get_token.postMessage(param);
- }
- if(navigator.userAgent.match(/android/i)){
- obj4H5.app_h5_get_token(param);
- }
- }catch(e){
- //TODO handle the exception
- // token='3411a38f800b591905df2150e28a8f95633'
- // listGoods();
- }
-
- }
- function callBackMethodName (data) {//app token 回调
- var data = JSON.parse(data)
- token = data.token;
- listGoods();
- }
- function app_to_goodsdetail (goods_id,goods_list_index) {
- //跳转到详情页
- var param = {
- 'goodsId':goods_id,
- 'commissionRate':goods_list[goods_list_index].commission_rate
- }
- param = JSON.stringify(param)
- try{
- if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
- window.webkit.messageHandlers.app_h5_to_goodsdetail.postMessage(param);
- }
- if(navigator.userAgent.match(/android/i)){
- obj4H5.app_h5_to_goodsdetail(param);
- }
- _czc.push(["_trackEvent",'优惠券专区','跳转详情','goods_id:' + goods_id]); //埋点
- }catch(e){
- //TODO handle the exception
- }
- }
- function listGoods () {
- //获取热销榜单
- loadingFlag = false;
- $("#loading").show();
- $.ajax({
- url:'/api/goods/listGoods',
- type:'post',
- dataType:'json',
- headers:{
- 'token': token
- },
- data:{
- page:page,
- id:4,
- type:'module'
- },
- success:function (res){
- $("#loading").hide();
- loadingFlag = true;
- if(res.errno == 0){
- if(res.rst.data.length == 0){
- showMsg('暂无更多商品')
- return;
- }
- if(page == 1){
- goods_list=res.rst.data;
- }else{
- goods_list=goods_list.concat(res.rst.data)
- }
- var list_html = '',shopType;
- goods_list.forEach(function (item,index) {
- if(item.shop_type == 1){
- //天猫
- shopType = '<img src="../common/tianmao.png"/>'
- }else{
- shopType = '<img src="../common/taobao.png"/>'
- }
-
- list_html += '<li onclick="app_to_goodsdetail(' + item.goods_id + ',' + index + ')"><div class="goods_img"><img src="' + item.img + '"/></div><div class="goods_info"><p class="goods_title">' + item.title + '</p><div class="goods_shop"><div class="shop">'+ shopType + item.shop_title + '</span></div><span class="monthly_sale">月售:' + item.volume + '</span></div><div class="price_info"><div class="left"><div class="price">¥<span>'+item.discount_price+'</span></div><div class="quan"><em>券</em><span>'+item.coupon_price+'</span></div></div><div class="right">利润<span>'+item.commission_rate+'</span></div></div></div></li>'
- });
- $("#list").html(list_html)
- }else{
- showMsg(res.err)
- }
- },
- error:function (err){
- $("#loading").hide();
- showMsg('请稍后重试!')
- }
- })
- }
- //提示弹框
- function showMsg(msg) {
- var msgBox = document.getElementsByClassName('alert-info')[0];
- msgBox.children[0].innerText = msg;
- msgBox.style.display="block";
- setTimeout(function() {
- msgBox.style.display="none";
- }, 1500);
- }
|