Files
youfang-app/fangija-zsyf/views/news/newsDetail.html
T
xuhe@fangjia.com 5fab6ca812 返回刷新
2018-03-30 10:08:55 +08:00

554 lines
15 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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-66">
<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>
</div>
<div class="searchbar row commentReleaseBox dn">
<div class="search-input col-85">
<input type="text" maxlength="250">
</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>
document.addEventListener('plusready', onPlusReady, false);
var id//= "183627425584775168";
var shareUrl = BASE_PATH+"/news/newDetail?newsId=";
var sharehrefTitle = "停车坐爱枫林晚,霜叶红于二月花";
var sharehrefDes = "客观里面请!";
var shareId='';
var province;
var city;
var region;
var picUrl = '_www/logo.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
$.ajax({
type : 'get',
url : BASE_PATH + "/rest/news/detail",
data:{newsId:id},
dataType:'json',
async:false,
success:function(result){
if(result.code==200){
data = result.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 = data.thumbsUpCount
//预先加载20条
sharehrefTitle = data.title
sharehrefDes = data.introduction
picUrl = data.coverImg
//加载评论列表
addItems(itemsPerLoad, 0);
//是否收藏
isCollect();
}
},
error:function(){
}
})
getPosition();
updateSerivces();
}
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;
}, 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 = "游客"
if(vo.wxName){
name = vo.wxName
}else if(vo.name){
name = vo.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>"+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).find(".icon").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 () {
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();
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);
});
}
mui.init({
beforeback: function() {
     //获得父页面的webview
var list = plus.webview.getWebviewById('yfindex.html');
     //触发父页面的自定义事件(refresh),从而进行刷新
mui.fire(list, 'refresh');
//返回true,继续页面关闭逻辑
return true;
}
});
</script>
</body>
</html>