adviserDetail.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * @author:liting
  3. * @update:2018/06/20
  4. *
  5. */
  6. import 'css/bootstrap.less';
  7. import 'bootstrap/dist/js/bootstrap.js';
  8. import 'css/newMenu/public.css';
  9. import 'css/newMenu/header.css'
  10. import 'css/newMenu/adviserDetail.css';
  11. import 'js/public.js';
  12. "use strict";
  13. $(function () {
  14. init();
  15. function init(){
  16. pages();
  17. }
  18. $('.collectionN .heart').click(function () {
  19. let heart = $('.heart');
  20. if (heart.hasClass('active')) {
  21. collectionApi(0) //取消关注
  22. } else {
  23. collectionApi(1) //关注
  24. }
  25. })
  26. let hash = window.location.search,
  27. hashArr =hash.split('='),
  28. ids =hashArr[1];
  29. function collectionApi(index) {
  30. let nub=parseInt($('.nubCollect').text());
  31. let url = index?'/api/user/portal/expertInterest':'/api/user/portal/expertCancelInterest';
  32. $.ajax({
  33. method: "post",
  34. dataType: "json",
  35. url: globalConfig.context + url,
  36. data: {
  37. id:ids
  38. },
  39. success: function (data) {
  40. if (data.error && data.error.length) {
  41. msg(data.error[0].message);
  42. }else{
  43. if(!index){
  44. $('.heart').removeClass('active');
  45. $('.collectionN').removeClass('active');
  46. $('.nubCollect').text((nub-1))
  47. $('#msg').val('取消关注')
  48. }else{
  49. $('.heart').addClass('active');
  50. $('.collectionN').addClass('active');
  51. $('.nubCollect').text((nub+1));
  52. $('#msg').val('关注成功,请至个人中心-我的关注查看.');
  53. }
  54. msg(index?'关注成功,请至个人中心-我的关注查看.':'取消关注');
  55. }
  56. }
  57. })
  58. }
  59. //评论列表
  60. loadDate();
  61. var thePageNo = 1,
  62. thePageLength = 1,
  63. pageSize = 4;
  64. function loadDate(pageNo) {
  65. $.ajax({
  66. method: "get",
  67. dataType: "json",
  68. url: globalConfig.context + "/open/unlanded/comment/list",
  69. data: {
  70. pageNo: pageNo || 1,
  71. pageSize:4,
  72. commodityId:ids
  73. },
  74. success: function (data) {
  75. var theArrs = [];
  76. if(data&&data.error.length){
  77. msg(data.error[0].message)
  78. };
  79. if(data.data.totalCommentCount>0){
  80. let good = (((data.data.positiveCommentCount)/(data.data.totalCommentCount))*100).toFixed(1),
  81. middle = (((data.data.ordinaryCommentCount)/(data.data.totalCommentCount))*100).toFixed(1),
  82. bad = (100-good-middle).toFixed(1);
  83. $('.commentDetails').html(`
  84. 评价 :<span>好评(${good+'%'})</span><span>中评(${middle+'%'})</span><span>差评(${bad+'%'})</span>
  85. `)
  86. }else{
  87. $('.commentDetails').html(`
  88. 评价 :<span>好评(100%)</span><span>中评(0%)</span><span>差评(0%)</span>
  89. `)
  90. }
  91. if (data.data && data.data.comments.list.length) {
  92. let nub = data.data.comments.list.length;
  93. for (let i = 0; i < nub; i++) {
  94. let thisdata = data.data.comments.list[i],name;
  95. let times =thisdata.createTime?new Date(thisdata.createTime).toLocaleString():'',
  96. star=thisdata.star;
  97. if(thisdata.uname.indexOf('游客')>-1){
  98. name='匿名'
  99. }else{
  100. name=thisdata.uname
  101. };
  102. theArrs.push(`
  103. <li>
  104. <div class="stasf">
  105. <p>用户名 :<span class="uName">${name}</span></p>
  106. <div class="satisfied">
  107. <span>满意度:</span>
  108. <ol>
  109. <li><span class="glyphicon ${star>=1?'glyphicon-star':'glyphicon-star-empty'} "></span></li>
  110. <li><span class="glyphicon ${star>=2?'glyphicon-star':'glyphicon-star-empty'}"></span></li>
  111. <li><span class="glyphicon ${star>=3?'glyphicon-star':'glyphicon-star-empty'}"></span></li>
  112. <li><span class="glyphicon ${star>=4?'glyphicon-star':'glyphicon-star-empty'}"></span></li>
  113. <li><span class="glyphicon ${star>=5?'glyphicon-star':'glyphicon-star-empty'}"></span></li>
  114. </ol>
  115. </div>
  116. </div>
  117. <div><time>${times}</time></div>
  118. <div class="satisfiedContent">
  119. <p>${thisdata.content}</p>
  120. </div>
  121. </li>`);
  122. };
  123. };
  124. $('.numberBars').html(data.data.totalCommentCount>10?'10+':data.data.totalCommentCount)
  125. $('.evaluateList>ul').empty();
  126. $('.evaluateList>ul').append(theArrs.join(''));
  127. if (!(data.data.comments.list.length)) {
  128. $('.evaluateList>ul').html("<div class='list_none'>暂无评论</div>");
  129. $('.pagination_box').css('display', 'none')
  130. }else{
  131. $('.pagination_box').css('display', 'block');
  132. }
  133. thePageLength = data.data.comments.totalCount ? Math.ceil(data.data.comments.totalCount / pageSize) : 1;
  134. $('.totalCount').html(`共${data.data.comments.totalCount}条数据 ${thePageLength}页`)
  135. var pageArr = [],
  136. firstNo = 1,
  137. endNo = 5;
  138. if (thePageNo > 3) {
  139. firstNo = thePageNo - 2;
  140. endNo = Math.min((Number(thePageNo) + 2), thePageLength);
  141. } else {
  142. endNo = Math.min(thePageLength, 5);
  143. };
  144. for (let i = firstNo; i <= endNo; i++) {
  145. if (i == thePageNo) {
  146. pageArr.push(
  147. '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
  148. );
  149. } else {
  150. pageArr.push(
  151. '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
  152. );
  153. }
  154. };
  155. $('.pageNumber').remove();
  156. $('.pagePre').after(pageArr.join(''));
  157. }
  158. });
  159. }
  160. //f分页
  161. function pages() {
  162. $('.pagination').on('click', 'li', function (e) {
  163. e.preventDefault();
  164. if (this.className === 'pagePre') {
  165. if (thePageNo > 1) {
  166. thePageNo = 1;
  167. loadDate(thePageNo);
  168. }
  169. } else if (this.className === 'pageNext') {
  170. if (thePageNo < thePageLength) {
  171. thePageNo = thePageLength;
  172. loadDate(thePageNo);
  173. }
  174. } else {
  175. var nextPageNo = $(this).children()[0].text;
  176. if (thePageNo != nextPageNo) {
  177. $(this).siblings("li").removeClass("active");
  178. $(this).addClass("active");
  179. thePageNo = nextPageNo;
  180. loadDate(thePageNo);
  181. };
  182. };
  183. });
  184. }
  185. //提示框渐隐函数
  186. function msg(txt) {
  187. if($('.smg').hasClass('active')){
  188. return ;
  189. }
  190. txt?$('#msg').val(txt):'';
  191. $('.smg').addClass('active');
  192. var lit = $('#msg').val(txt);
  193. setTimeout(function () {
  194. $('.smg').removeClass('active');
  195. $('#msg').val('');
  196. }, 2000)
  197. }
  198. //评论星星
  199. star();
  200. function star(){
  201. $('.commentStar .ulStar span').hover(function(){
  202. $(this).addClass('glyphicon-star').removeClass('glyphicon-star-empty').prevAll().addClass('glyphicon-star').removeClass('glyphicon-star-empty');
  203. $(this).nextAll().removeClass('glyphicon-star').addClass('glyphicon-star-empty').stop(true);
  204. })
  205. }
  206. //新建评论
  207. addComment();
  208. function addComment(){
  209. $('.CommentSend .btn').click(function(e){
  210. e.preventDefault();
  211. let starNum = $('.commentStar .ulStar span.glyphicon-star').length,
  212. textVal = $('#commentArea').val();
  213. if(!starNum){
  214. msg('请您选择星级!');
  215. return;
  216. }
  217. if(!textVal){
  218. msg('请您填写评论内容!');
  219. return;
  220. }
  221. $.ajax({
  222. method:'post',
  223. url: globalConfig.context + "/open/addComment",
  224. dataType:'json',
  225. data:{
  226. commodityId:ids,
  227. content:textVal,
  228. star:starNum,
  229. commodityType:4
  230. }
  231. }).done(function(data){
  232. if(data&&data.error.length){
  233. msg(data.error[0].message);
  234. return;
  235. }
  236. msg('评论成功,感谢您的评论。');
  237. $('#commentArea').val('');
  238. $('.ulStar span').removeClass('glyphicon-star').addClass('glyphicon-star-empty');
  239. loadDate();
  240. })
  241. })
  242. }
  243. })