serviceDetails.js 10 KB

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