detailbottom.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="dis-flex flex-x-between bottom-btns">
  3. <view class="dis-flex flex-y-center btn-active">
  4. <u-icon name="eye" color="#00aeec" size="18"></u-icon>
  5. <view class="btn-title">{{views || 0}}人阅读</view>
  6. </view>
  7. <view class="dis-flex flex-y-center" :class="{'btn-active':liked}" @click="like">
  8. <u-icon v-if="liked" name="thumb-up-fill" color="#00aeec" size="18"></u-icon>
  9. <u-icon v-else name="thumb-up" color="#7f7f7f" size="18"></u-icon>
  10. <view class="btn-title">{{likeNum || 0}}点赞</view>
  11. </view>
  12. <view class="dis-flex flex-y-center" :class="{'btn-active':collected}" @click="collection">
  13. <u-icon v-if="collected" name="star-fill" color="#00aeec" size="18"></u-icon>
  14. <u-icon v-else name="star" color="#7f7f7f" size="18"></u-icon>
  15. <view class="btn-title">{{collectNum || 0}}收藏数</view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. liked: Boolean,
  23. collected: Boolean,
  24. views: Number,
  25. likeNum: Number,
  26. collectNum: Number,
  27. articleId: String,
  28. type: String,
  29. },
  30. data() {
  31. return {
  32. submitting: false,
  33. }
  34. },
  35. methods: {
  36. like() {
  37. if (this.liked) {
  38. this.cancelLike()
  39. } else {
  40. this.addLike()
  41. }
  42. },
  43. collection() {
  44. if (this.collected) {
  45. this.cancelCollection()
  46. } else {
  47. this.addCollection()
  48. }
  49. },
  50. addLike() {
  51. if (this.submitting) {
  52. return;
  53. }
  54. this.submitting = true;
  55. uni.showLoading()
  56. // 点赞
  57. this.$u.api.addLike(this.articleId, this.type).then(res => {
  58. this.submitting = false;
  59. uni.hideLoading()
  60. this.finishSave()
  61. }).catch(e => {
  62. this.submitting = false;
  63. uni.hideLoading()
  64. });
  65. },
  66. cancelLike() {
  67. if (this.submitting) {
  68. return;
  69. }
  70. this.submitting = true;
  71. uni.showLoading()
  72. // 取消点赞
  73. this.$u.api.cancelLike(this.articleId, this.type).then(res => {
  74. this.submitting = false;
  75. uni.hideLoading()
  76. this.finishSave()
  77. }).catch(e => {
  78. this.submitting = false;
  79. uni.hideLoading()
  80. });
  81. },
  82. addCollection() {
  83. if (this.submitting) {
  84. return;
  85. }
  86. this.submitting = true;
  87. uni.showLoading()
  88. // 收藏
  89. this.$u.api.addCollection(this.articleId, this.type).then(res => {
  90. this.submitting = false;
  91. uni.hideLoading()
  92. this.finishSave()
  93. }).catch(e => {
  94. this.submitting = false;
  95. uni.hideLoading()
  96. });
  97. },
  98. cancelCollection() {
  99. if (this.submitting) {
  100. return;
  101. }
  102. this.submitting = true;
  103. uni.showLoading()
  104. // 取消收藏
  105. this.$u.api.cancelCollection(this.articleId, this.type).then(res => {
  106. this.submitting = false;
  107. uni.hideLoading()
  108. this.finishSave()
  109. }).catch(e => {
  110. this.submitting = false;
  111. uni.hideLoading()
  112. });
  113. },
  114. finishSave() {
  115. this.$emit("doRefresh")
  116. }
  117. },
  118. }
  119. </script>
  120. <style scoped lang="scss">
  121. .bottom-btns {
  122. width: 100%;
  123. .btn-title {
  124. margin-left: 10rpx;
  125. color: #7f7f7f;
  126. }
  127. }
  128. .btn-active {
  129. .btn-title {
  130. color: #00aeec;
  131. }
  132. }
  133. </style>