comment-list.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!-- 评论列表 -->
  2. <template>
  3. <view class="page_box">
  4. <view class="head_box u-flex">
  5. <button :class="{ 'btn-active': typeCurrent === t.code }" class="u-reset-button type-btn" @tap="selType(t.code)" v-for="t in commentTypeList" :key="t.code">
  6. {{ t.name }}({{ t.num }})
  7. </button>
  8. </view>
  9. <view class="content_box">
  10. <scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box">
  11. <view class="comment-list">
  12. <block v-for="comment in commentList" :key="comment.id"><sh-comment :comment="comment"></sh-comment></block>
  13. </view>
  14. <shopro-empty v-if="isEmpty" :image="$IMG_URL + '/imgs/empty/comment_empty.png'" tipText="暂无此类评价~"></shopro-empty>
  15. <!-- 加载更多 -->
  16. <u-loadmore v-if="commentList.length" height="80rpx" :status="loadStatus" icon-type="flower" color="#ccc" />
  17. </scroll-view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import shComment from '../components/sh-comment.vue';
  23. export default {
  24. components: {
  25. shComment
  26. },
  27. data() {
  28. return {
  29. isEmpty: false,
  30. typeCurrent: 'all',
  31. commentList: [],
  32. commentTypeList: [],
  33. loadStatus: 'loadmore', //loadmore-加载前的状态,loading-加载中的状态,nomore-没有更多的状态
  34. currentPage: 1,
  35. lastPage: 1
  36. };
  37. },
  38. computed: {},
  39. onLoad() {
  40. this.getCommentType();
  41. },
  42. methods: {
  43. selType(id) {
  44. if (this.typeCurrent !== id) {
  45. this.typeCurrent = id;
  46. this.commentList = [];
  47. this.currentPage = 1;
  48. this.getCommentList();
  49. }
  50. },
  51. // 评价类型
  52. getCommentType() {
  53. let that = this;
  54. that.$http('goods.commentType', {
  55. goods_id: that.$Route.query.goodsId
  56. }).then(res => {
  57. if (res.code === 1) {
  58. that.commentTypeList = res.data;
  59. that.getCommentList();
  60. }
  61. });
  62. },
  63. // 商品评论
  64. getCommentList() {
  65. let that = this;
  66. that.loadStatus = 'loading';
  67. that.$http('goods.commentList', {
  68. goods_id: that.$Route.query.goodsId,
  69. pre_page: 10,
  70. page: that.currentPage,
  71. type: that.typeCurrent
  72. }, '加载中...').then(res => {
  73. if (res.code === 1) {
  74. that.commentList = [...that.commentList, ...res.data.data];
  75. that.isEmpty = !that.commentList.length;
  76. that.lastPage = res.data.last_page;
  77. that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
  78. }
  79. });
  80. },
  81. // 加载更多
  82. loadMore() {
  83. if (this.currentPage < this.lastPage) {
  84. this.currentPage += 1;
  85. this.getCommentList();
  86. }
  87. }
  88. }
  89. };
  90. </script>
  91. <style lang="scss">
  92. .empty-box {
  93. position: fixed;
  94. left: 50%;
  95. top: 50%;
  96. transform: translate(-50%, -50%);
  97. }
  98. .head_box {
  99. height: 114rpx;
  100. background-color: #fff;
  101. padding: 0 20rpx;
  102. .type-btn {
  103. width: 130rpx;
  104. line-height: 62rpx;
  105. background: rgba(238, 238, 238, 1);
  106. border-radius: 31rpx;
  107. border: none;
  108. font-size: 28rpx;
  109. font-weight: 400;
  110. color: rgba(153, 153, 153, 1);
  111. padding: 0;
  112. margin-right: 10rpx;
  113. }
  114. .btn-active {
  115. background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
  116. box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  117. color: #a8700d;
  118. }
  119. }
  120. .comment-list {
  121. margin-top: 20rpx;
  122. }
  123. </style>