1
0

bd-comments.vue 5.2 KB

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