bd-comments.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="bd-comments" v-if="isComment == 1">
  3. <template v-if="list.length > 0">
  4. <view class="bd-top dir-left-nowrap cross-center" @click="goto">
  5. <view class="box-grow-1 bd-name">评价</view>
  6. <view class="box-grow-0 bd-more">查看更多</view>
  7. <image class="box-grow-0 bd-icon" src="../../../static/image/icon/arrow-right.png"></image>
  8. </view>
  9. <view class="bd-bottom bt" v-for="(item, index) in list" :key="index" >
  10. <view class="bd-title dir-left-nowrap cross-center">
  11. <image class="box-grow-0 bd-avatar" :src="item.avatar"></image>
  12. <view class="box-grow-1 bd-nickname">{{item.nickname}}</view>
  13. <view class="bd-more box-grow-0">{{item.time}}</view>
  14. </view>
  15. <view class="bd-attr-name">{{ item.attr_name }}</view>
  16. <view class="bd-content u-line-2">{{item.content}}</view>
  17. <view class="dir-left-wrap pic-list">
  18. <image class="bd-pic" @click="imgPreview(index, ind)" :src="pic_url" v-for="(pic_url, ind) in item.pic_url" :key="ind"></image>
  19. </view>
  20. </view>
  21. </template>
  22. <view class="bd-nothing" v-else>暂无评价</view>
  23. </view>
  24. </template>
  25. <script>
  26. import {mapState} from "vuex";
  27. export default {
  28. name: "bd-comments",
  29. props: {
  30. goodsId: Number
  31. },
  32. data() {
  33. return {
  34. list: []
  35. }
  36. },
  37. computed: {
  38. ...mapState({
  39. isComment: function(state) {
  40. return state.mallConfig.mall.setting.is_comment;
  41. }
  42. })
  43. },
  44. methods: {
  45. getList: function(goodsId) {
  46. this.$request({
  47. url: this.$api.goods.comments_list,
  48. data: {
  49. goods_id: goodsId
  50. }
  51. }).then((res) => {
  52. if (res.code === 0) {
  53. this.list = res.data.comments.slice(0, 2);
  54. } else {
  55. uni.showToast({
  56. icon: 'none',
  57. title: res.msg
  58. });
  59. }
  60. });
  61. },
  62. imgPreview: function(index, ind) {
  63. if (this.list && this.list[index] && this.list[index].pic_url && this.list[index].pic_url.length > 0) {
  64. uni.previewImage({
  65. current: ind,
  66. urls: this.list[index].pic_url
  67. });
  68. }
  69. },
  70. goto() {
  71. uni.navigateTo({
  72. url: `/pages/comments/comments?goods_id=${this.goodsId}`
  73. });
  74. }
  75. },
  76. watch: {
  77. goodsId: {
  78. immediate: true,
  79. handler(newVal) {
  80. this.getList(newVal);
  81. }
  82. }
  83. }
  84. }
  85. </script>
  86. <style scoped>
  87. .bd-comments {
  88. width: 702upx;
  89. margin: 24upx 24upx 0 24upx;
  90. background-color: #ffffff;
  91. border-radius: 15upx;
  92. }
  93. .bd-nothing {
  94. padding: 20upx;
  95. font-size: 26upx;
  96. color: #353535;
  97. }
  98. .bd-top {
  99. height: 90upx;
  100. border-bottom: 1upx solid #eeeeee;
  101. padding: 0 20upx;
  102. }
  103. .bd-icon {
  104. width: 12upx;
  105. height: 22upx;
  106. margin-left: 15upx;
  107. }
  108. .bd-name {
  109. font-size: 26upx;
  110. color: #999999;
  111. }
  112. .bd-more {
  113. font-size: 22upx;
  114. color: #999999;
  115. }
  116. .bd-bottom {
  117. padding: 20upx;
  118. }
  119. .bd-title {
  120. margin-top: 8upx;
  121. margin-bottom: 22upx;
  122. }
  123. .bd-avatar {
  124. width: 56upx;
  125. height: 56upx;
  126. border-radius: 50%;
  127. }
  128. .bd-nickname {
  129. font-size: 26upx;
  130. color: #999999;
  131. margin-left: 26upx;
  132. }
  133. .bd-attr-name {
  134. font-size: 24upx;
  135. color: #999999;
  136. line-height: 34upx;
  137. margin-bottom: 14upx;
  138. }
  139. .bd-content {
  140. font-size: 26upx;
  141. line-height: 36upx;
  142. color: #353535;
  143. }
  144. .pic-list {
  145. margin-top: 20upx;
  146. }
  147. .bd-pic {
  148. width: 210upx;
  149. height: 210upx;
  150. margin-right: 10upx;
  151. margin-bottom: 10upx;
  152. }
  153. </style>