serviceDetails.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. "use strict";
  13. $(function () {
  14. init();
  15. function init(){
  16. heightF();
  17. }
  18. $('.collection p').eq(0).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 url = index?'/api/user/portal/projectInterest':'/api/user/portal/projectCancelInterest'
  31. $.ajax({
  32. method: "post",
  33. dataType: "json",
  34. url: globalConfig.context + url,
  35. data: {
  36. id:ids
  37. },
  38. success: function (data) {
  39. if (data.error && data.error.length) {
  40. $('#msg').val(data.error[0].message);
  41. msg();
  42. }else{
  43. if(!index){
  44. $('.heart').removeClass('active');
  45. }else{
  46. $('.heart').addClass('active');
  47. }
  48. $('#msg').val(index?'收藏成功,请至个人中心查看.':'撤销收藏');
  49. msg();
  50. }
  51. }
  52. })
  53. }
  54. //价值
  55. function heightF(){
  56. let het = $('.serviceDetailsList .value div').height();
  57. $('.serviceDetailsList .value h4').css({
  58. height:(het+20)+'px',
  59. lineHeight:(het+20)+'px'
  60. })
  61. }
  62. //提示框渐隐函数
  63. function msg() {
  64. if($('.smg').hasClass('active')){
  65. return ;
  66. }
  67. $('.smg').addClass('active')
  68. setTimeout(function () {
  69. $('.smg').removeClass('active')
  70. $('#msg').val('');
  71. }, 2000)
  72. }
  73. })