Files
youfang-app/fangija-zsyf/views/news/newsDetail.html
T
2018-04-27 16:11:12 +08:00

634 lines
17 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title id="title2">咨询详情</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="../../css/sm.css">
<link rel="stylesheet" href="../../css/theme-blue.css">
<link rel="stylesheet" href="../../css/mui.min.css">
<link rel="stylesheet" href="../../css/main.css">
<style>
.list-block .item-text{-webkit-line-clamp:unset;}
</style>
</head>
<body>
<div class="page-group">
<div class="page page-current">
<header class="bar bar-nav">
<button class="button button-link button-nav pull-left" onclick="back(),plus.nativeUI.closeWaiting();">
<span class="mui-icon mui-icon mui-icon-arrowleft"></span>
</button>
<!--<a href="javascript:void(0)" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left">返回刷新</a>-->
<button class="button button-link button-nav pull-right open-popover" onclick="shareHref()">
<span class="icon icon-path"></span>
</button>
<h1 class="title"></h1>
</header>
<div class="content contentText infinite-scroll infinite-scroll-bottom" data-distance="40">
<div class="content-padded">
<h1 id="title"></h1>
<p><small id="source"></small><small style="float:right;" id="visit_count"><i class="icon icon-eye-grey"></i></small><br><small id="create_time"></small></p>
<div id="content">
</div>
</div>
<!--
<div class="newCss">
<ul>
<li><span>房贷</span></li>
<li><span>广州</span></li>
<li><span>首套房</span></li>
</ul>
</div>
-->
<div class="adBoxApp">
<img src="../../images/wx_app.png">
<p><label>有房&nbsp;&nbsp;有家&nbsp;&nbsp;有爱</label><br><small>更多房产资讯上有房APP</small></p>
</div>
<div class="list-block media-list commentList">
<ul>
</ul>
</div>
<!-- 加载提示符 -->
<div class="infinite-scroll-preloader" style="position: relative;top: -70px;">
<div class="preloader"></div>
</div>
</div>
<div class="bar commentBox">
<div class="searchbar row commentInputBox">
<div class="search-input col-60">
<label class="icon icon-comments" for="search"></label>
<input type="text" placeholder="我也说两句">
</div>
<!--<span class="col-33">
<a class="praise"><i class="icon icon-praise-grey02"></i><font id="newsPraise">{{ newsDzCount }}</font></a>
<a class="collection collection01"><i class="icon icon-collection01"></i></a>
</span>-->
<span class="praise col-20">
<i class="icon icon-praise-grey02"></i><font id="newsPraise">{{ newsDzCount }}</font>
</span>
<span class="collection collection01 col-15">
<i class="icon icon-collection01"></i>
</span>
</div>
<div class="searchbar row commentReleaseBox dn">
<div class="search-input col-85">
<input type="text" maxlength="250" id="commentInput">
</div>
<a class="col-15" id="publishBtn">发布</a>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="../../js/zepto.js" charset="utf-8"></script>
<script>
/* 关闭路由,以实现不同页面之间的相互跳转(仅开发环境需要) */
Zepto = $
$.config = {router: false}
</script>
<script type="text/javascript" src="../../js/beacon_release.js"></script>
<script type="text/javascript" src="../../js/vue.js"></script>
<script type="text/javascript" src="../../js/light7.js" charset="utf-8"></script>
<script type="text/javascript" src="../../js/cn.js" charset="utf-8"></script>
<script type="text/javascript" src="../../js/mui.min.js" charset="utf-8"></script>
<script src="../../config.js"></script>
<script type="text/javascript" src="../../js/common.js" ></script>
<script type="text/javascript" src="../../js/axios.min.js"></script>
<script type="text/javascript" src="../../js/axiosPlugin.js"></script>
<script type="text/javascript" src="../../js/shara/sharaMine.js" ></script>
<script type="text/javascript" src="../../js/log/log_stat.js" ></script>
<script type="text/javascript" src="../../js/city.js" ></script>
<script>
document.addEventListener('plusready', onPlusReady, false);
var id; //= "186182250936643584";
var shareUrl = BASE_PATH+"/news/newDetail?newsId=";
var sharehrefTitle = "停车坐爱枫林晚,霜叶红于二月花";
var sharehrefDes = "客观里面请!";
var shareId='';
var province;
var city;
var region;
//var picUrl = '_www/logo.png';
var picUrl = '_www/img/default_share.png';
//新闻评论列表
$.init()
//加载flag
var loading = false;
//最多可加载的条目
var maxItems = 100;
//上次加载的序号
var lastIndex = 0;
//每次加载添加多少条目
var itemsPerLoad = 10;
var curpage = 1;
var totalCount = 0;
var curPageSize = 0;
var vm = new Vue({
el: '#newsPraise',
data:{
newsDzCount: 0
}
})
function onPlusReady() {
var self = plus.webview.currentWebview();
id = self.newsId;
shareId = id
shareUrl = shareUrl+id
axios.get("/rest/news/detail",{params:{newsId:id}}).then(function(response){
if(response.data.code==200){
data = response.data.data
$("#title").text(data.title)
$("#title2").text(data.title)
$("#source").text(data.source==null?"":"来源:"+data.source)
$("#visit_count").append(data.visitCount)
var date = new Date(data.deployTime)
var dateStr = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
$("#create_time").text(dateStr)
$("#content").html(data.content)
//$("#newsPraise").text(data.thumbsUpCount);
vm.newsDzCount = numberConver(data.thumbsUpCount)
//预先加载20条
sharehrefTitle = data.title
sharehrefDes = data.introduction
picUrl = data.smallCoverImg==null||data.smallCoverImg==""?picUrl:data.smallCoverImg
//加载评论列表
addItems(itemsPerLoad, 0);
//是否收藏
isCollect();
}
}).catch(function(error){
console.log(error)
});
getPosition();
updateSerivces();
}
//数量进行转换
function numberConver(thumbsUpCount){
var thumbsUpCountStr = ""
if(thumbsUpCount>=10000){
thumbsUpCountStr = (thumbsUpCount/10000).toFixed(1)+"万"
}else{
thumbsUpCountStr = thumbsUpCount
}
return thumbsUpCountStr;
}
function isCollect(){
axios.post("/rest/news/checkCollect",{newsId : id}).then(function (response) {
var msg = response.data.data;
if(msg){
$(".collection").addClass("collection02")
$(".collection i").addClass("icon-collection02")
$(".collection").removeClass("collection01")
$(".collection i").removeClass("icon-collection01")
}
})
.catch(function (error) {
console.log(error);
});
}
// 获取当前用户位置
function getPosition(){
plus.geolocation.getCurrentPosition(function(p){
province = p.address.province;
city = p.address.city;
region = p.address.district;
if(city){
city = formatBaiduCity(city);
}
}, function(e){
},
{
provider:'baidu',
enableHighAccuracy:true,
coordsType:'bd09ll'
}
);
}
function addItems(number, lastIndex) {
if(!id){
return;
}
curpage = lastIndex/itemsPerLoad + 1;
axios.get("/rest/news/comment", {
params: {
newsId: id,
page:curpage,
pageSize:itemsPerLoad
}
})
.then(function (response) {
var results = response.data.data
curPageSize = results.length;
if(results==null || results.length==0) {
// 加载完毕,则注销无限加载事件,以防不必要的加载
$.detachInfiniteScroll($('.infinite-scroll'));
// 删除加载提示符
$('.infinite-scroll-preloader').hide();
return;
}
// 生成新条目的HTML
var html = '';
for(var i in results){
var vo = results[i];
html = html+"<li>"+
"<a class='item-content'>";
if(vo.headImg!=null){
html = html + "<div class='item-media'><img src='"+vo.headImg+"'></div>";
}else{
html = html + "<div class='item-media'><img src='../../images/headPortrait.png'></div>";
}
html = html + "<div class='item-inner'>";
var name = null;
if(vo.wxName){
name = vo.wxName
}
if(name == null){
name = vo.name
}
if(name == null){
name = vo.mobile
}
if(name == null){
name = "游客"
}
html = html + "<div class='item-title-row'>"+
"<div class='item-title'>"+name+"</div>"+
"<div class='item-after'><span data-cid='"+vo.id+"'><i class='icon icon-praise-grey01'></i><label>"+numberConver(vo.praiseCount)+"</label></span></div>"+
"</div>"+
"<div class='item-title-row'>";
var address = "";
if(vo.commentUserProvince && vo.commentUserCity && vo.commentUserProvince == vo.commentUserCity){
html = html + "<div class='item-title'><span>"+vo.commentUserCity+" </span></div>";
}else{
if(vo.commentUserProvince && vo.commentUserCity){
html = html + "<div class='item-title'><span>"+vo.commentUserProvince+vo.commentUserCity+" </span></div>";
}else{
html = html + "<div class='item-title'><span> </span></div>";
}
}
var curTime = new Date().getTime()
var publishTime = vo.addTime;
var timeString = getDateDiff(curTime, publishTime)
var content = "";
if(vo.content){
content = vo.content
if(content.length > 250){
content = content.substr(0,250)+"...";
}
}
html = html + "<div class='item-after'><span>"+timeString+"</span></div>"+
"</div>"+
"<div class='item-text'>"+content+"</div>"+
"</div>"+
"</a>"+
"</li>";
}
// 添加新条目
$('.commentList ul').append(html);
if($('.commentList li').length== totalCount+1){
// 加载完毕,则注销无限加载事件,以防不必要的加载
$.detachInfiniteScroll($('.infinite-scroll'));
// 删除加载提示符
$('.infinite-scroll-preloader').hide();
}
})
.catch(function (error) {
console.log(error);
});
}
//注册'infinite'事件处理函数
$(document).on('infinite', '.infinite-scroll-bottom',function() {
// 如果正在加载,则退出
if (loading) return;
// 设置flag
loading = true;
// 模拟1s的加载过程
setTimeout(function() {
// 重置加载flag
loading = false;
// 更新最后加载的序号
lastIndex = $('.commentList li').length;
if (curPageSize < itemsPerLoad) {
// 加载完毕,则注销无限加载事件,以防不必要的加载
$.detachInfiniteScroll($('.infinite-scroll'));
// 删除加载提示符
$('.infinite-scroll-preloader').hide();
return;
}
// 添加新条目
addItems(itemsPerLoad, $('.commentList li').length);
//容器发生改变,如果是js滚动,需要刷新滚动
// $.refreshScroller();
}, 1000);
});
var MINU_SEC = 60 * 1000 ;
var HOUR_SEC = 60 * MINU_SEC;
var DAY_SEC = HOUR_SEC * 24;
var MONTH_SEC = DAY_SEC * 30;
var YEAR_SEC = MONTH_SEC * 12;
function getDateDiff(curTime, publishTime){
if (publishTime <= curTime) {
var diffSec = curTime - publishTime
if (diffSec < DAY_SEC) {
if (diffSec >= HOUR_SEC) {
var t = diffSec / HOUR_SEC;
return parseInt(t) + "小时前";
} else if (diffSec >= MINU_SEC) {
var t = diffSec / MINU_SEC;
return parseInt(t) + "分钟前";
} else {
return "1分钟";
}
} else if (DAY_SEC > diffSec && diffSec < DAY_SEC*2) {
return "昨天";
} else {
var date = new Date(publishTime)
var dateStr = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
return dateStr;
}
} else {
return "1分钟";
}
}
//添加评论
/* 评论点赞 */
$("body").delegate(".commentList span .icon-praise-grey01", "click", function () {
$(this).addClass("icon-praise-orange01");
var cid = $(this).parent().attr("data-cid")
$(this).attr("disabled","disabled");
var text = $(this).parent().text();
axios.get("/rest/comment/thumbsUp", {
params: {
commentId:cid
}
}).then(function (response) {
var msg = response.data.data
if(msg && msg =="点赞成功"){
$("span[data-cid='"+cid+"']").find("label").text(parseInt(text) + 1);
$.toast(msg);
}else{
msg = response.data.message
if(msg){
$.toast(msg);
}
}
})
.catch(function (error) {
console.log(error);
});
});
/*新闻点赞*/
$(".praise").on("click", function () {
$(this).find(".icon").addClass("icon-praise-orange02");
$(this).attr("disabled","disabled");
var text = $("#newsPraise").text();
axios.get("/rest/news/thumbsUp", {
params: {
newsId:id
}
}).then(function (response) {
var msg = response.data.data
if(msg && msg =="点赞成功"){
$(this).find("font").text(parseInt(text) + 1);
var count = parseInt(text) + 1;
vm.newsDzCount = count
$.toast(msg);
}else{
msg = response.data.message
if(msg){
$.toast(msg);
}
}
})
.catch(function (error) {
console.log(error);
});
});
//收藏
$(".collection").on("click", function () {
//localStorage.removeItem("user_token");
doCollect();
//collect();
});
function doCollect() {
if (localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == "") {
clicked('../user/codeSms.html',true,false,{},{},function(){
if(plus.webview.getWebviewById('views/house/houseDetail.html')!= null) {
plus.webview.getWebviewById('views/house/houseDetail.html').reload();
}
if(plus.webview.getWebviewById('views/house/houseManageList.html') != null) {
plus.webview.getWebviewById('views/house/houseManageList.html').reload();
}
if(plus.webview.getWebviewById('views/user/userInfo.html')!= null){
plus.webview.getWebviewById('views/user/userInfo.html').reload();
}
doCollect();
})
return;
} else {
collect();
}
}
function collect(){
axios.post("/rest/news/collect",{newsId : id}).then(function (response) {
var msg = response.data.message
if(msg){
if(msg=="用户不能为空"){
//先进行登录
}
}else{
msg = response.data.data
if(msg == "收藏成功"){
$(".collection").addClass("collection02")
$(".collection i").addClass("icon-collection02")
$(".collection").removeClass("collection01")
$(".collection i").removeClass("icon-collection01")
}else{
$(".collection").addClass("collection01")
$(".collection i").addClass("icon-collection01")
$(".collection").removeClass("collection02")
$(".collection i").removeClass("icon-collection02")
}
}
$.toast(msg);
})
.catch(function (error) {
console.log(error);
});
}
/* 发布评论 */
$(".commentInputBox input").focus(function () {
$(".commentInputBox").hide();
$(".commentReleaseBox").show();
$(".commentReleaseBox input").focus();
$(".commentReleaseBox input").val("");
});
$(".commentReleaseBox a").on("click", function () {
$(".commentReleaseBox").hide();
$(".commentInputBox").show();
var content = $(".commentReleaseBox input").val();
if(content){
addComment();
}
});
function addComment(){
var content = $(".commentReleaseBox input").val();
content = utf16toEntities(content);
axios.post("/rest/comment/add",{commentObjId : id, content:content, commentUserProvince:province, commentUserCity:city}).then(function (response) {
var msg = response.data.message
if(msg){
$.toast(msg);
}else{
window.location.reload();
}
})
.catch(function (error) {
console.log(error);
});
}
function utf16toEntities(str) {
var patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则
str = str.replace(patt, function(char) {
var H, L, code;
if (char.length === 2) {
H = char.charCodeAt(0);
// 取出高位
L = char.charCodeAt(1);
// 取出低位
code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00;
//转换算法
return "&#" + code + ";";
} else {
return char;
}
});
return str;
}
//$(window).bind('resize',_funResize);
var _funResize = function(){
document.body.scrollTop = document.body.scrollHeight;
target.scrollIntoView(true);
}
$(function() {
$('#commentInput').on('click', function () {
var target = this;
// 使用定时器是为了让输入框上滑时更加自然
setTimeout(function(){
document.body.scrollTop = document.body.scrollHeight;
target.scrollIntoView(true);
},100);
});
})
</script>
</body>
</html>