123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- /*
- * @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(`
- 评价 :<span>好评(${good+'%'})</span><span>中评(${middle+'%'})</span><span>差评(${bad+'%'})</span>
- `)
- }else{
- $('.commentDetails').html(`
- 评价 :<span>好评(100%)</span><span>中评(0%)</span><span>差评(0%)</span>
- `)
- }
- 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(`
- <li>
- <div class="stasf">
- <p>用户名 :<span class="uName">${name}</span></p>
- <div class="satisfied">
- <span>满意度:</span>
- <ol>
- <li><span class="glyphicon ${star>=1?'glyphicon-star':'glyphicon-star-empty'} "></span></li>
- <li><span class="glyphicon ${star>=2?'glyphicon-star':'glyphicon-star-empty'}"></span></li>
- <li><span class="glyphicon ${star>=3?'glyphicon-star':'glyphicon-star-empty'}"></span></li>
- <li><span class="glyphicon ${star>=4?'glyphicon-star':'glyphicon-star-empty'}"></span></li>
- <li><span class="glyphicon ${star>=5?'glyphicon-star':'glyphicon-star-empty'}"></span></li>
- </ol>
- </div>
- </div>
- <div><time>${times}</time></div>
- <div class="satisfiedContent">
- <p>${thisdata.content}</p>
- </div>
- </li>`);
- };
-
- };
-
- $('.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("<div class='list_none'>暂无评论</div>");
- $('.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(
- '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
- );
- } else {
- pageArr.push(
- '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
- );
- }
- };
- $('.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();
- })
- })
- }
- })
|