/*
* @author:liting
* @update:2018/06/20
*
*/
import 'css/bootstrap.less';
import 'bootstrap/dist/js/bootstrap.js';
import 'css/newMenu/public.css';
import 'css/newMenu/header.css'
import 'css/newMenu/adviserDetail.css';
import 'js/public.js';
"use strict";
$(function () {
init();
function init(){
pages();
}
$('.collectionN .heart').click(function () {
let heart = $('.heart');
if (heart.hasClass('active')) {
collectionApi(0) //取消关注
} else {
collectionApi(1) //关注
}
})
let hash = window.location.search,
hashArr =hash.split('='),
ids =hashArr[1];
function collectionApi(index) {
let nub=parseInt($('.nubCollect').text());
let url = index?'/api/user/portal/expertInterest':'/api/user/portal/expertCancelInterest';
$.ajax({
method: "post",
dataType: "json",
url: globalConfig.context + url,
data: {
id:ids
},
success: function (data) {
if (data.error && data.error.length) {
msg(data.error[0].message);
}else{
if(!index){
$('.heart').removeClass('active');
$('.collectionN').removeClass('active');
$('.nubCollect').text((nub-1))
$('#msg').val('取消关注')
}else{
$('.heart').addClass('active');
$('.collectionN').addClass('active');
$('.nubCollect').text((nub+1));
$('#msg').val('关注成功,请至个人中心-我的关注查看.');
}
msg(index?'关注成功,请至个人中心-我的关注查看.':'取消关注');
}
}
})
}
//评论列表
loadDate();
var thePageNo = 1,
thePageLength = 1,
pageSize = 4;
function loadDate(pageNo) {
$.ajax({
method: "get",
dataType: "json",
url: globalConfig.context + "/open/unlanded/comment/list",
data: {
pageNo: pageNo || 1,
pageSize:4,
commodityId:ids
},
success: function (data) {
var theArrs = [];
if(data&&data.error.length){
msg(data.error[0].message)
};
if(data.data.totalCommentCount>0){
let good = (((data.data.positiveCommentCount)/(data.data.totalCommentCount))*100).toFixed(1),
middle = (((data.data.ordinaryCommentCount)/(data.data.totalCommentCount))*100).toFixed(1),
bad = (100-good-middle).toFixed(1);
$('.commentDetails').html(`
评价 :好评(${good+'%'})中评(${middle+'%'})差评(${bad+'%'})
`)
}else{
$('.commentDetails').html(`
评价 :好评(100%)中评(0%)差评(0%)
`)
}
if (data.data && data.data.comments.list.length) {
let nub = data.data.comments.list.length;
for (let i = 0; i < nub; i++) {
let thisdata = data.data.comments.list[i],name;
let times =thisdata.createTime?new Date(thisdata.createTime).toLocaleString():'',
star=thisdata.star;
if(thisdata.uname.indexOf('游客')>-1){
name='匿名'
}else{
name=thisdata.uname
};
theArrs.push(`
`);
};
};
$('.numberBars').html(data.data.totalCommentCount>10?'10+':data.data.totalCommentCount)
$('.evaluateList>ul').empty();
$('.evaluateList>ul').append(theArrs.join(''));
if (!(data.data.comments.list.length)) {
$('.evaluateList>ul').html("暂无评论
");
$('.pagination_box').css('display', 'none')
}else{
$('.pagination_box').css('display', 'block');
}
thePageLength = data.data.comments.totalCount ? Math.ceil(data.data.comments.totalCount / pageSize) : 1;
$('.totalCount').html(`共${data.data.comments.totalCount}条数据 ${thePageLength}页`)
var pageArr = [],
firstNo = 1,
endNo = 5;
if (thePageNo > 3) {
firstNo = thePageNo - 2;
endNo = Math.min((Number(thePageNo) + 2), thePageLength);
} else {
endNo = Math.min(thePageLength, 5);
};
for (let i = firstNo; i <= endNo; i++) {
if (i == thePageNo) {
pageArr.push(
'' + i + ''
);
} else {
pageArr.push(
'' + i + ''
);
}
};
$('.pageNumber').remove();
$('.pagePre').after(pageArr.join(''));
}
});
}
//f分页
function pages() {
$('.pagination').on('click', 'li', function (e) {
e.preventDefault();
if (this.className === 'pagePre') {
if (thePageNo > 1) {
thePageNo = 1;
loadDate(thePageNo);
}
} else if (this.className === 'pageNext') {
if (thePageNo < thePageLength) {
thePageNo = thePageLength;
loadDate(thePageNo);
}
} else {
var nextPageNo = $(this).children()[0].text;
if (thePageNo != nextPageNo) {
$(this).siblings("li").removeClass("active");
$(this).addClass("active");
thePageNo = nextPageNo;
loadDate(thePageNo);
};
};
});
}
//提示框渐隐函数
function msg(txt) {
if($('.smg').hasClass('active')){
return ;
}
txt?$('#msg').val(txt):'';
$('.smg').addClass('active');
var lit = $('#msg').val(txt);
setTimeout(function () {
$('.smg').removeClass('active');
$('#msg').val('');
}, 2000)
}
//评论星星
star();
function star(){
$('.commentStar .ulStar span').hover(function(){
$(this).addClass('glyphicon-star').removeClass('glyphicon-star-empty').prevAll().addClass('glyphicon-star').removeClass('glyphicon-star-empty');
$(this).nextAll().removeClass('glyphicon-star').addClass('glyphicon-star-empty').stop(true);
})
}
//新建评论
addComment();
function addComment(){
$('.CommentSend .btn').click(function(e){
e.preventDefault();
let starNum = $('.commentStar .ulStar span.glyphicon-star').length,
textVal = $('#commentArea').val();
if(!starNum){
msg('请您选择星级!');
return;
}
if(!textVal){
msg('请您填写评论内容!');
return;
}
$.ajax({
method:'post',
url: globalConfig.context + "/open/addComment",
dataType:'json',
data:{
commodityId:ids,
content:textVal,
star:starNum,
commodityType:4
}
}).done(function(data){
if(data&&data.error.length){
msg(data.error[0].message);
return;
}
msg('评论成功,感谢您的评论。');
$('#commentArea').val('');
$('.ulStar span').removeClass('glyphicon-star').addClass('glyphicon-star-empty');
loadDate();
})
})
}
})