Aucune description

information.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. var id = ''; //资讯id
  2. var view_num = '';//资讯阅读量
  3. var sessionid = '';//sessionid
  4. var is_login = '';//判断用户是否登录
  5. var qs = parseQueryString(window.location.href);
  6. $().ready(function () {
  7. if(qs.sessionid){
  8. document.cookie="PHPSESSID=" + qs.sessionid + ';path=/' ;
  9. }
  10. if(qs.id) {id = qs.id;}
  11. if(qs.view_num) {view_num = qs.view_num}
  12. newsDetailEvent();//详情页接口
  13. })
  14. function newsDetailEvent () {
  15. //详情页接口数据
  16. $.ajax({
  17. type:'post',
  18. url:'/user/huaJiangHu/newsDetail',
  19. dataType:'json',
  20. data:{
  21. id:id,
  22. view_num:view_num
  23. },
  24. success:function(res){
  25. if(res && res.errno == 0){
  26. is_login = res.rst.is_login;
  27. var html = '',conHtml,contentHtml,commodityHtml='';
  28. conHtml = `<div class="con">
  29. <h3>${res.rst.title}</h3>
  30. <div class="info">
  31. <div class="left">
  32. <span>媒体来源:${res.rst.source}</span>
  33. <span>${res.rst.publish_time}</span>
  34. </div>
  35. <div class="right">${res.rst.view_num}阅读</div>
  36. </div>
  37. <div class="content">${res.rst.content}</div>
  38. </div>`;
  39. res.rst.product.forEach(function (item, index) {
  40. var amount = '';
  41. if(item.upper_amount != item.lower_amount){
  42. amount = `${item.upper_amount}-${item.lower_amount}`
  43. }else{
  44. amount = `${item.upper_amount}`
  45. }
  46. commodityHtml += `<li class="details" data-id=${item.id}>
  47. <div class="left">
  48. <img src="${item.icon}" />
  49. <div>
  50. <span>${item.name}</span>
  51. <span>期限${item.term}</span>
  52. </div>
  53. </div>
  54. <div class="right">
  55. <span>${amount}</span>
  56. <span>额度(元)</span>
  57. </div>
  58. </li>`
  59. })
  60. contentHtml = `<div class="commodityRecommend">
  61. <h3>产品推荐</h3>
  62. <ul>${commodityHtml}</ul>
  63. </div>`;
  64. html = `${conHtml}${contentHtml}`;
  65. $(".container").html(html)
  66. goDetail();//点击推荐列表去详情
  67. var jsons = {
  68. title:res.rst.title,
  69. desc:$(".con .content p").eq(0).text()
  70. };
  71. jsons = JSON.stringify(jsons);
  72. webViewTitleContent(jsons)
  73. }
  74. console.log(res)
  75. }
  76. })
  77. }
  78. //获取地址栏参数
  79. function parseQueryString(url) {
  80. var urlObj = {};
  81. var reg = /([^?=&]+)=([^?=&]+)/g;
  82. url.replace(reg, ($0, $1, $2) => {
  83. urlObj[$1] = decodeURIComponent($2);
  84. })
  85. return urlObj;
  86. }
  87. //点击推荐列表去详情
  88. function goDetail () {
  89. $(".details").click(function () {
  90. var id = $(this).context.dataset.id;
  91. //判断用户是否登录
  92. if (is_login == 1){
  93. //用户已经登录
  94. window.location.href = './details.html?id=' + id
  95. }else if (is_login == 0){
  96. //用户未登录
  97. window.location.href = './login.html?id=' + id
  98. }
  99. })
  100. }
  101. //提示信息
  102. function showMsg(msg) {
  103. var msg = msg;
  104. var msgBox = $('.alert-info');
  105. msgBox.children('p').text(msg);
  106. msgBox.show();
  107. setTimeout(function() {
  108. msgBox.hide();
  109. }, 2000);
  110. }
  111. function webViewTitleContent(jsons) {
  112. console.log("点击")
  113. console.log(jsons)
  114. if(navigator.userAgent.indexOf('Android') != -1){
  115. messageHandlers.webViewTitleContent(jsons)
  116. }else{
  117. window.webkit.messageHandlers.webViewTitleContent.postMessage(jsons)
  118. }
  119. }