1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- var list = [];
- $().ready(function(){
- getToken()
- })
- //获取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='a07122d3365ded9cd710662d9fe3916626'
- // realTimeGoodsList();
- }
-
- }
- function callBackMethodName (data) {//app token 回调
- var data = JSON.parse(data)
- token = data.token;
- realTimeGoodsList();
- }
- function app_to_goodsdetail (goods_id,list_index) {
- //跳转到详情页
- var param = {
- 'goodsId':goods_id,
- 'commissionRate':list[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);
- }
- }catch(e){
- //TODO handle the exception
- }
- }
- function realTimeGoodsList () {
- //获取热销榜单
- $("#loading").show();
- $.ajax({
- url:'/api/goods/realTimeGoodsList',
- type:'post',
- dataType:'json',
- headers:{
- 'token': token
- },
- success:function (res){
- $("#loading").hide();
- if(res.errno == 0){
- if(res.rst.data.length == 0){
- $(".hotList").html('<div class="hint">暂无商品</div>')
- }else{
- var hotListhtml = '',shopType,topImg;
- list = res.rst.data;
- list.forEach(function (item,index) {
- if(item.shop_type == 1){
- //天猫
- shopType = '<img src="./img/tianmao.png"/>'
- }else{
- shopType = '<img src="./img/taobao.png"/>'
- }
-
- hotListhtml += '<li onclick="app_to_goodsdetail(' + item.goods_id + ',' + index + ')"><img class="shopImg" src="' + item.img + '"/><div class="shopCon"><h3>' + item.title + '</h3><div class="shop">' + shopType + item.shop_title + '</div><div class="shop_price">¥ <em>' + item.live_price + ' / </em><span>利润 <em>' + item.commission_rate + '</em></span></div><div class="shop_sales_volume">销量' + item.order_count + '</div></div></li>'
- });
- $(".hotList").html(hotListhtml)
- $(".hotList li").eq(0).append('<img class="topImg" src="./img/one.png"/>')
- $(".hotList li").eq(1).append('<img class="topImg" src="./img/two.png"/>')
- $(".hotList li").eq(2).append('<img class="topImg" src="./img/three.png"/>')
- }
- }else{
- showMsg(res.err)
- }
- },
- error:function (err){
- $("#loading").hide();
- }
- })
- }
- //提示弹框
- 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);
- }
|