bd-comments.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. font-size: 33rpx;
  120. font-weight: bold;
  121. color: #333;
  122. }
  123. .bd-more {
  124. font-size: 28upx;
  125. color: #E56283;
  126. }
  127. .bd-bottom {
  128. padding: 20upx;
  129. }
  130. .bd-title {
  131. margin-top: 8upx;
  132. margin-bottom: 22upx;
  133. }
  134. .bd-avatar {
  135. width: 56upx;
  136. height: 56upx;
  137. border-radius: 50%;
  138. }
  139. .bd-nickname {
  140. font-size: 26upx;
  141. color: #999999;
  142. margin-left: 26upx;
  143. display: flex;
  144. flex-direction: column;
  145. }
  146. .bd-attr-name {
  147. font-size: 24upx;
  148. color: #999999;
  149. line-height: 34upx;
  150. margin-bottom: 14upx;
  151. }
  152. .bd-content {
  153. font-size: 26upx;
  154. line-height: 36upx;
  155. color: #353535;
  156. }
  157. .pic-list {
  158. margin-top: 20upx;
  159. }
  160. .bd-pic {
  161. width: 210upx;
  162. height: 210upx;
  163. margin-right: 10upx;
  164. margin-bottom: 10upx;
  165. }
  166. .bd-time{
  167. font-size: 21rpx;
  168. }
  169. .bd-tags{
  170. display: flex;
  171. align-items: center;
  172. }
  173. .bd-tags .bd-tag{
  174. background: #FCDBE2;
  175. font-size: 22rpx;
  176. padding: 10rpx 30rpx;
  177. margin-left: 10rpx;
  178. border-radius: 10rpx;
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. }
  183. </style>