specialDetail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. import 'css/newMenu/public.css';
  2. import 'css/newMenu/header.css'
  3. import 'css/newMenu/special.css';
  4. import 'css/newMenu/quill.bubble.css';
  5. import 'js/public.js';
  6. $(function(){
  7. var thePageNo = 1,
  8. thePageLength = 1,
  9. pageSize = 4;
  10. init();
  11. function init(){
  12. //初始处理
  13. $('.totalCommit').empty();
  14. initState();
  15. //分享
  16. share();
  17. //写答案、写想法
  18. write();
  19. //收藏关注跳转
  20. jumpFollow();
  21. //点赞
  22. fabulous();
  23. //评论点
  24. commentClick();
  25. };
  26. function commentClick(){
  27. $('.commentDz').click(function(){
  28. if($(this).hasClass('active')){
  29. $(this).removeClass('active');
  30. $('.commentBody').hide();
  31. }else{
  32. $(this).addClass('active');
  33. $('.commentBody').show();
  34. loadDate();
  35. pLun();
  36. }
  37. })
  38. };
  39. //获取id
  40. function getRequest() {
  41. var url = window.location.search; //获取url中"?"符后的字串
  42. var theRequest = new Object();
  43. if (url.indexOf("?") != -1) {
  44. var str = url.substr(1),
  45. strs = str.split("&");
  46. for (var i = 0; i < strs.length; i++) {
  47. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  48. }
  49. }
  50. return theRequest;
  51. };
  52. //评论数据获取
  53. function loadDate(pageNo) {
  54. $('.commentList').hide()
  55. let ids = getRequest().id;
  56. $.ajax({
  57. method: "get",
  58. dataType: "json",
  59. url: globalConfig.context + "/open/unlanded/comment/list",
  60. data: {
  61. pageNo: pageNo || 1,
  62. pageSize:4,
  63. commodityId:ids
  64. },
  65. success: function (data) {
  66. var theArrs = [];
  67. if(data&&data.error.length){
  68. msg(data.error[0].message)
  69. };
  70. if(data.data.totalCommentCount==0){
  71. return;
  72. };
  73. if (data.data && data.data.comments.list.length) {
  74. let nub = data.data.comments.list.length;
  75. for (let i = 0; i < nub; i++) {
  76. let thisdata = data.data.comments.list[i],
  77. times =thisdata.createTime?new Date(thisdata.createTime).toLocaleString():'';
  78. if(thisdata.uname.indexOf('游客')>-1){
  79. name='匿名'
  80. }else{
  81. name=thisdata.uname
  82. };
  83. theArrs.push(`
  84. <li>
  85. <div>用户名:${name}<time>${times}</time></div>
  86. <p>${(thisdata.content).replace(/<.*?>/g, "")}</p>
  87. </li>`);
  88. };
  89. };
  90. $('.commentList').show();
  91. $('.totalCommit').html(`${data.data.totalCommentCount}条评论`)
  92. $('.commentList>ul').empty();
  93. $('.commentList>ul').append(theArrs.join(''));
  94. if (!(data.data.comments.list.length)) {
  95. $('.commentList>ul').html("<div class='list_none'>暂无评论</div>");
  96. $('.pagination_box').css('display', 'none');
  97. }else{
  98. $('.pagination_box').css('display', 'block');
  99. }
  100. thePageLength = data.data.comments.totalCount ? Math.ceil(data.data.comments.totalCount / pageSize) : 1;
  101. $('.totalCount').html(`共${data.data.comments.totalCount}条数据 ${thePageLength}页`)
  102. var pageArr = [],
  103. firstNo = 1,
  104. endNo = 5;
  105. if (thePageNo > 3) {
  106. firstNo = thePageNo - 2;
  107. endNo = Math.min((Number(thePageNo) + 2), thePageLength);
  108. } else {
  109. endNo = Math.min(thePageLength, 5);
  110. };
  111. for (let i = firstNo; i <= endNo; i++) {
  112. if (i == thePageNo) {
  113. pageArr.push(
  114. '<li class="pageNumber active"><a href="#" value=' + i + ' >' + i + '</a></li>'
  115. );
  116. } else {
  117. pageArr.push(
  118. '<li class="pageNumber"><a href="#" value=' + i + ' >' + i + '</a></li>'
  119. );
  120. }
  121. };
  122. $('.pageNumber').remove();
  123. $('.pagePre').after(pageArr.join(''));
  124. pages();
  125. }
  126. });
  127. };
  128. //点赞
  129. function fabulous(){
  130. $('.fabulous').click(function(){
  131. if($(this).hasClass('active')) return;
  132. let nut = $(this).find('span').text(),
  133. _this=$(this);
  134. $(this).addClass('active');
  135. $.ajax({
  136. method:'get',
  137. url:globalConfig.context+'/portal/special/addStar',
  138. dataType:'json',
  139. data:{
  140. id:getRequest().id
  141. },
  142. success:function(data){
  143. if(data.error&&data.error.length){
  144. msg(data.error[0].message);
  145. return;
  146. }
  147. fabulousAnimate(_this);
  148. _this.find('span').text(parseInt(nut)+1);
  149. _this.removeClass('active');
  150. }
  151. })
  152. });
  153. };
  154. //随机颜色
  155. function randowColor(){
  156. return '#'+Math.floor(Math.random()*0xffffff).toString(16);
  157. };
  158. //点赞特效
  159. function fabulousAnimate(_this){
  160. _this.append('<i>+1</i>');
  161. let len = _this.find('i').length;
  162. for(let i =0;i<len;i++){
  163. _this.find('i').eq(i).css({
  164. position:'absolute',
  165. left:'40px',
  166. zIndex:20+i,
  167. top:(-15-i*8)+'px',
  168. color:randowColor(),
  169. });
  170. setTimeout(()=>{
  171. _this.find('i').eq(i).hide(150).remove();
  172. },(i+1)*500)
  173. }
  174. }
  175. //f分页
  176. function pages() {
  177. $('.pagination').on('click', 'li', function (e) {
  178. e.preventDefault();
  179. if (this.className === 'pagePre') {
  180. if (thePageNo > 1) {
  181. thePageNo = 1;
  182. loadDate(thePageNo);
  183. }
  184. } else if (this.className === 'pageNext') {
  185. if (thePageNo < thePageLength) {
  186. thePageNo = thePageLength;
  187. loadDate(thePageNo);
  188. }
  189. } else {
  190. var nextPageNo = $(this).children()[0].text;
  191. if (thePageNo != nextPageNo) {
  192. $(this).siblings("li").removeClass("active");
  193. $(this).addClass("active");
  194. thePageNo = nextPageNo;
  195. loadDate(thePageNo);
  196. };
  197. };
  198. });
  199. }
  200. //关注
  201. colFun();
  202. function colFun(){
  203. $('.txt .heart').click(function (e) {
  204. let loginTxt=$('.head_login')[0];
  205. if(loginTxt&&($(loginTxt).text())=='登录'){
  206. window.location.hash='jump'
  207. msg('请先登录!')
  208. return false;
  209. }else{
  210. if(window.adminData&&window.adminData.mobile){
  211. msg('账号不正确,请退出重新登入。')
  212. return;
  213. }
  214. }
  215. e.preventDefault();
  216. e.stopPropagation();
  217. let nub=parseInt($(this).siblings('.nubCollect').text()),
  218. heart = $(this),
  219. id=$(this).parents('.txt').attr('data-id');
  220. if (heart.hasClass('active')) {
  221. $(this).removeClass('active')
  222. $(this).siblings('.nubCollect').text(nub-1);
  223. collectionApi(0,id,nub) //取消关注
  224. } else {
  225. $(this).addClass('active');
  226. $(this).siblings('.nubCollect').text(nub+1);
  227. collectionApi(1,id,nub) //关注
  228. }
  229. })
  230. }
  231. function collectionApi(index,ids,nub) {
  232. let url = index?'/api/user/portal/expertInterest':'/api/user/portal/expertCancelInterest';
  233. $.ajax({
  234. method: "post",
  235. dataType: "json",
  236. url: globalConfig.context + url,
  237. data: {
  238. id:ids
  239. },
  240. success: function (data) {
  241. if (data.error && data.error.length) {
  242. msg(data.error[0].message);
  243. }else{
  244. if(!index){
  245. $('#msg').val('取消关注')
  246. }else{
  247. $('#msg').val('关注成功,请至个人中心-我的关注查看.');
  248. }
  249. msg(index?'关注成功,请至个人中心-我的关注查看.':'取消关注');
  250. }
  251. }
  252. })
  253. };
  254. //评论数量
  255. function comNumber(){
  256. $.ajax({
  257. method:'get',
  258. url:globalConfig.context + '/portal/special/addComment',
  259. data:{
  260. id:getRequest().id
  261. }
  262. }).done(function(data){
  263. if(data.error&&data.error.length){
  264. msg(data.error[0].message);
  265. return ;
  266. }
  267. })
  268. };
  269. function jumpFollow(){
  270. $('.collection .myCollect').click(function(){
  271. let loginTxt=$('.head_login')[0];
  272. if(loginTxt&&($(loginTxt).text())=='登录'){
  273. $('.head_login').click();
  274. window.location.hash='jump';
  275. return false;
  276. }else{
  277. if(window.adminData&&window.adminData.mobile){
  278. msg('账号不正确,请退出重新登入。')
  279. return;
  280. }
  281. window.location.href= globalConfig.context+'/user/account/index.html#/collection';
  282. }
  283. });
  284. $('.collection .myFollow').click(function(){
  285. let loginTxt=$('.head_login')[0];
  286. if(loginTxt&&($(loginTxt).text())=='登录'){
  287. $('.head_login').click();
  288. window.location.hash='jump';
  289. return false;
  290. }else{
  291. if(window.adminData&&window.adminData.mobile){
  292. msg('账号不正确,请退出重新登入。')
  293. return;
  294. }
  295. window.location.href= globalConfig.context+'/user/account/index.html#/follow';
  296. }
  297. })
  298. };
  299. //评论
  300. function pLun(){
  301. $('.commentBody .btn').click(function(e){
  302. e.preventDefault();
  303. let val = $('.commentBody .search').val(),
  304. plNum = $('.commentDz span').text();;
  305. if(!val.trim()){
  306. $('#msg').val('请填写评论内容.')
  307. msg('请填写评论内容.');
  308. return ;
  309. };
  310. $.ajax({
  311. method:'post',
  312. dataType:'json',
  313. url:globalConfig.context+'/open/addComment',
  314. data:{
  315. commodityId:getRequest().id,
  316. content:val,
  317. star:5,
  318. commodityType:5
  319. }
  320. }).done(function(data){
  321. if(data&&data.error.length){
  322. msg(data.error[0].message)
  323. return;
  324. }
  325. msg('感谢您的评论.');
  326. $('.search').val('');
  327. let tt = parseInt(plNum);
  328. tt++;
  329. $('.commentDz span').text(tt);
  330. comNumber();
  331. loadDate(1);
  332. })
  333. })
  334. };
  335. function write(){
  336. $(' .writeXF div').click(function(){
  337. msg('敬请期待!');
  338. })
  339. }
  340. function initState(){
  341. $('.fengX').hover(function(){
  342. $(this).find('.fxWrap').show(10).addClass('active');
  343. },function(){
  344. $(this).find('.fxWrap').hide(200).removeClass('active');
  345. });
  346. };
  347. function share(){
  348. //好友
  349. document.querySelector('.qqHy').onclick=function(){
  350. let title = $('.detaiTitle h3').text(),
  351. img= $('.detaiTitle img').attr('src');
  352. shareQQ_friend(title, window.location.href, img)
  353. };
  354. //qq
  355. document.querySelector('.qqKj').onclick=function(){
  356. let title = $('.detaiTitle h3').text(),
  357. img= $('.detaiTitle img').attr('src');
  358. shareToQq(title, window.location.href, img)
  359. };
  360. //微博
  361. document.querySelector('.xlWb').onclick=function(){
  362. let title = $('.detaiTitle h3').text(),
  363. img= $('.detaiTitle img').attr('src');
  364. shareToXl(title,window.location.href,img);
  365. };
  366. };
  367. //分享
  368. function shareToQq(title, url, picurl) {
  369. var shareqqzonestring = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?summary=' + encodeURIComponent(title) + '&url=' +
  370. encodeURIComponent(url) + '&pics=' + encodeURIComponent(picurl)+'&title='+title;
  371. window.open(shareqqzonestring);
  372. }
  373. //微博
  374. function shareToXl(title,url,picurl){
  375. var sharesinastring='http://v.t.sina.com.cn/share/share.php?title='+title+'&url='+url+'&content=utf-8&sourceUrl='+url+'&pic='+picurl;
  376. window.open(sharesinastring);
  377. }
  378. //qq好友
  379. function shareQQ_friend(_title,_url,picurl){
  380. var _shareUrl = 'http://connect.qq.com/widget/shareqq/iframe_index.html?';
  381. _shareUrl += 'url=' + encodeURIComponent(_url); //分享的链接
  382. _shareUrl += '&title=' + encodeURIComponent(_title); //分享的标题
  383. _shareUrl+='&pics=' + encodeURIComponent(picurl)
  384. window.open(_shareUrl,'_blank','height=520, width=720');
  385. };
  386. //提示框渐隐函数
  387. function msg(txt) {
  388. if($('.smg').hasClass('active')){
  389. return ;
  390. }
  391. $('.smg').addClass('active');
  392. var lit = $('#msg').val(txt);
  393. setTimeout(function () {
  394. $('.smg').removeClass('active');
  395. $('#msg').val('');
  396. }, 2000)
  397. }
  398. })