暫無描述

news_drs.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. var qs = parseQueryString(window.location.href);
  2. $().ready(function(){
  3. init(qs.id?qs.id:'')
  4. })
  5. function init(id) {
  6. $(".loading").show();
  7. $.ajax({
  8. url:'/api/v2/adv/talentArticle',
  9. type:'get',
  10. dataType:'json',
  11. data:{
  12. id:id
  13. },
  14. success:function (res){
  15. $(".loading").hide();
  16. if(res.errno==0) {
  17. var data = res.rst.data
  18. var content = data.article;
  19. var goodsInfo = data.items;
  20. $("#app_image").attr("src",data.app_image)
  21. var news_info_con = '<h3 class="title">' + data.name + '</h3><div class="drs_info"><div class="left"><img src="' + data.head_img + '" class="head_img"/><span class="talent_name">'+ data.talent_name +'</span></div><div class="right"><img class="readtimes_icon" src="./yanjing.png"/><span class="readtimes">' + data.readtimes + '</span></div></div>'
  22. $(".news_info").html(news_info_con)
  23. $("#container").html(decodeHtml(content))
  24. document.title = data.shorttitle;
  25. $(".commodity-tkmoney").remove();
  26. $(".commodity-tkrates").remove();
  27. $(".single-tkmoney").remove();
  28. $(".single-tkrates").remove();
  29. //删除goodsInfo中没有的商品
  30. var goods_id = '';
  31. Array.prototype.slice.call($(".js_tobuy")).forEach(function (item,index){
  32. goods_id = $(item).attr('id').split('itemid')[1];
  33. if(JSON.stringify(goodsInfo).indexOf(goods_id)==-1){
  34. $(item).remove()
  35. }
  36. })
  37. $(".js_tobuy").click(function () {
  38. console.log($(this).attr('id'))
  39. var itemid = $(this).attr('id').split('itemid')[1];
  40. var param = '';
  41. console.log(itemid)
  42. goodsInfo.forEach(function (item, index) {
  43. if(item.goods_id == itemid){
  44. param = {
  45. goods_id: item.goods_id,
  46. is_coupon: item.is_coupon,
  47. coupon_price: item.coupon_price,
  48. price: item.price,
  49. discount_price: item.discount_price,
  50. commission_rate: item.commission_rate,
  51. coupon_start_time: item.coupon_start_time,
  52. coupon_end_time: item.coupon_end_time
  53. }
  54. param = JSON.stringify(param)
  55. goGoodsDetail(param)//跳详情
  56. }
  57. })
  58. })
  59. }else {
  60. showMsg(res.err)
  61. }
  62. },
  63. error:function () {
  64. $(".loading").hide();
  65. showMsg('网络异常,请稍后再试')
  66. }
  67. })
  68. }
  69. // 展示错误提示信息
  70. function showMsg(msg) {
  71. var msgBox = document.getElementsByClassName('alert-info')[0];
  72. msgBox.getElementsByTagName("p")[0].innerHTML=msg;
  73. msgBox.style.display="block";
  74. setTimeout(function() {
  75. msgBox.style.display="none";
  76. }, 2000);
  77. }
  78. //获取地址栏参数
  79. function parseQueryString(url) {
  80. var urlObj = {};
  81. var reg = /([^?=&]+)=([^?=&]+)/g;
  82. url.replace(reg, function($0, $1, $2) {
  83. urlObj[$1] = decodeURIComponent($2);
  84. })
  85. return urlObj;
  86. }
  87. //打开商品详情
  88. function goGoodsDetail (param) {
  89. console.log(param)
  90. try{
  91. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  92. window.webkit.messageHandlers.app_h5_open_goodDetail.postMessage(param);
  93. }
  94. if(navigator.userAgent.match(/android/i)){
  95. obj4H5.app_h5_open_goodDetail(param);
  96. }
  97. }catch(e){
  98. //TODO handle the exception
  99. console.log("兼容")
  100. }
  101. }
  102. //文章解析
  103. function decodeHtml(s) {
  104. var HTML_DECODE = {
  105. "&lt;": "<",
  106. "&gt;": ">",
  107. "&amp;": "&",
  108. "&nbsp;": " ",
  109. "&quot;": "\"",
  110. "&copy;": ""
  111. // Add more
  112. };
  113. var REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;
  114. var REGX_HTML_DECODE = /&\w+;|&#(\d+);/g;
  115. var REGX_TRIM = /(^\s*)|(\s*$)/g;
  116. s = (s != undefined) ? s : "";
  117. return (typeof s != "string") ? s :
  118. s.replace(REGX_HTML_DECODE,
  119. function ($0, $1) {
  120. var c = HTML_DECODE[$0];
  121. if (c == undefined) {
  122. // Maybe is Entity Number
  123. if (!isNaN($1)) {
  124. c = String.fromCharCode(($1 == 160) ? 32 : $1);
  125. } else {
  126. c = $0;
  127. }
  128. }
  129. return c;
  130. });
  131. };