123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- var id = ''; //资讯id
- var view_num = '';//资讯阅读量
- var sessionid = '';//sessionid
- var is_login = '';//判断用户是否登录
- var qs = parseQueryString(window.location.href);
- $().ready(function () {
- if(qs.sessionid){
- document.cookie="PHPSESSID=" + qs.sessionid + ';path=/' ;
- }
- if(qs.id) {id = qs.id;}
- if(qs.view_num) {view_num = qs.view_num}
- newsDetailEvent();//详情页接口
- })
- function newsDetailEvent () {
- //详情页接口数据
- $.ajax({
- type:'post',
- url:'/user/huaJiangHu/newsDetail',
- dataType:'json',
- data:{
- id:id,
- view_num:view_num
- },
- success:function(res){
- if(res && res.errno == 0){
- is_login = res.rst.is_login;
- var html = '',conHtml,contentHtml,commodityHtml='';
- conHtml = `<div class="con">
- <h3>${res.rst.title}</h3>
- <div class="info">
- <div class="left">
- <span>媒体来源:${res.rst.source}</span>
- <span>${res.rst.publish_time}</span>
- </div>
- <div class="right">${res.rst.view_num}阅读</div>
- </div>
- <div class="content">${res.rst.content}</div>
- </div>`;
- res.rst.product.forEach(function (item, index) {
- var amount = '';
- if(item.upper_amount != item.lower_amount){
- amount = `${item.upper_amount}-${item.lower_amount}`
- }else{
- amount = `${item.upper_amount}`
- }
- commodityHtml += `<li class="details" data-id=${item.id}>
- <div class="left">
- <img src="${item.icon}" />
- <div>
- <span>${item.name}</span>
- <span>期限${item.term}</span>
- </div>
- </div>
- <div class="right">
- <span>${amount}</span>
- <span>额度(元)</span>
- </div>
- </li>`
- })
- contentHtml = `<div class="commodityRecommend">
- <h3>产品推荐</h3>
- <ul>${commodityHtml}</ul>
- </div>`;
- html = `${conHtml}${contentHtml}`;
- $(".container").html(html)
- goDetail();//点击推荐列表去详情
- var jsons = {
- title:res.rst.title,
- desc:$(".con .content p").eq(0).text()
- };
- jsons = JSON.stringify(jsons);
- webViewTitleContent(jsons)
- }
- console.log(res)
- }
- })
- }
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, ($0, $1, $2) => {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
- //点击推荐列表去详情
- function goDetail () {
- $(".details").click(function () {
- var id = $(this).context.dataset.id;
- //判断用户是否登录
- if (is_login == 1){
- //用户已经登录
- window.location.href = './details.html?id=' + id
- }else if (is_login == 0){
- //用户未登录
- window.location.href = './login.html?id=' + id
- }
- })
- }
- //提示信息
- function showMsg(msg) {
- var msg = msg;
- var msgBox = $('.alert-info');
- msgBox.children('p').text(msg);
- msgBox.show();
- setTimeout(function() {
- msgBox.hide();
- }, 2000);
- }
- function webViewTitleContent(jsons) {
- console.log("点击")
- console.log(jsons)
- if(navigator.userAgent.indexOf('Android') != -1){
- messageHandlers.webViewTitleContent(jsons)
- }else{
- window.webkit.messageHandlers.webViewTitleContent.postMessage(jsons)
- }
- }
|