酷店app

index.js 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. var list = [];
  2. $().ready(function(){
  3. getToken()
  4. })
  5. //获取token
  6. function getToken () {
  7. var param = '{"js_callback" : "callBackMethodName"}';
  8. try{
  9. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  10. window.webkit.messageHandlers.app_h5_get_token.postMessage(param);
  11. }
  12. if(navigator.userAgent.match(/android/i)){
  13. obj4H5.app_h5_get_token(param);
  14. }
  15. }catch(e){
  16. //TODO handle the exception
  17. // token='a07122d3365ded9cd710662d9fe3916626'
  18. // realTimeGoodsList();
  19. }
  20. }
  21. function callBackMethodName (data) {//app token 回调
  22. var data = JSON.parse(data)
  23. token = data.token;
  24. realTimeGoodsList();
  25. }
  26. function app_to_goodsdetail (goods_id,list_index) {
  27. //跳转到详情页
  28. var param = {
  29. 'goodsId':goods_id,
  30. 'commissionRate':list[list_index].commission_rate
  31. }
  32. param = JSON.stringify(param)
  33. try{
  34. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  35. window.webkit.messageHandlers.app_h5_to_goodsdetail.postMessage(param);
  36. }
  37. if(navigator.userAgent.match(/android/i)){
  38. obj4H5.app_h5_to_goodsdetail(param);
  39. }
  40. }catch(e){
  41. //TODO handle the exception
  42. }
  43. }
  44. function realTimeGoodsList () {
  45. //获取热销榜单
  46. $("#loading").show();
  47. $.ajax({
  48. url:'/api/goods/realTimeGoodsList',
  49. type:'post',
  50. dataType:'json',
  51. headers:{
  52. 'token': token
  53. },
  54. success:function (res){
  55. $("#loading").hide();
  56. if(res.errno == 0){
  57. if(res.rst.data.length == 0){
  58. $(".hotList").html('<div class="hint">暂无商品</div>')
  59. }else{
  60. var hotListhtml = '',shopType,topImg;
  61. list = res.rst.data;
  62. list.forEach(function (item,index) {
  63. if(item.shop_type == 1){
  64. //天猫
  65. shopType = '<img src="./img/tianmao.png"/>'
  66. }else{
  67. shopType = '<img src="./img/taobao.png"/>'
  68. }
  69. 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>'
  70. });
  71. $(".hotList").html(hotListhtml)
  72. $(".hotList li").eq(0).append('<img class="topImg" src="./img/one.png"/>')
  73. $(".hotList li").eq(1).append('<img class="topImg" src="./img/two.png"/>')
  74. $(".hotList li").eq(2).append('<img class="topImg" src="./img/three.png"/>')
  75. }
  76. }else{
  77. showMsg(res.err)
  78. }
  79. },
  80. error:function (err){
  81. $("#loading").hide();
  82. }
  83. })
  84. }
  85. //提示弹框
  86. function showMsg(msg) {
  87. var msgBox = document.getElementsByClassName('alert-info')[0];
  88. msgBox.children[0].innerText = msg;
  89. msgBox.style.display="block";
  90. setTimeout(function() {
  91. msgBox.style.display="none";
  92. }, 1500);
  93. }