safeguardingDetail.js 10.0 KB

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