serviceDetails.js 11 KB

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