topicComment.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="comments">
  3. <view class="b">
  4. <view class="item" v-for="(item, index) in comments" :key="item.id">
  5. <view class="info">
  6. <view class="user">
  7. <image :src="item.user_info.avatar"></image>
  8. <text>{{item.user_info.nickname||''}}</text>
  9. </view>
  10. <view class="time">{{item.add_time||''}}</view>
  11. </view>
  12. <view class="comment">{{item.content||''}}</view>
  13. <view class="imgs" v-if="item.pic_list.length > 0">
  14. <image class="img" v-for="(pitem, index) in item.pic_list" :key="pitem.id" :src="pitem.pic_url"></image>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. const util = require("@/utils/util.js");
  22. const api = require('@/utils/api.js');
  23. export default {
  24. data() {
  25. return {
  26. comments: [],
  27. allCommentList: [],
  28. picCommentList: [],
  29. typeId: 0,
  30. valueId: 0,
  31. showType: 0,
  32. allCount: 0,
  33. hasPicCount: 0,
  34. allPage: 1,
  35. picPage: 1,
  36. size: 20
  37. }
  38. },
  39. methods: {
  40. getCommentCount: function() {
  41. let that = this;
  42. util.request(api.CommentCount, {
  43. valueId: that.valueId,
  44. typeId: that.typeId
  45. }).then(function(res) {
  46. if (res.errno === 0) {
  47. that.allCount = res.data.allCount
  48. that.hasPicCount = res.data.hasPicCount
  49. }
  50. });
  51. },
  52. getCommentList: function() {
  53. let that = this;
  54. util.request(api.CommentList, {
  55. valueId: that.valueId,
  56. typeId: that.typeId,
  57. size: that.size,
  58. page: (that.showType == 0 ? that.allPage : that.picPage),
  59. showType: that.showType
  60. }).then(function(res) {
  61. if (res.errno === 0) {
  62. if (that.showType == 0) {
  63. that.allCommentList = that.allCommentList.concat(res.data.data)
  64. that.allPage = res.data.currentPage
  65. that.comments = that.allCommentList.concat(res.data.data)
  66. } else {
  67. that.picCommentList = that.picCommentList.concat(res.data.data)
  68. that.picPage = res.data.currentPage
  69. that.comments = that.picCommentList.concat(res.data.data)
  70. }
  71. }
  72. });
  73. },
  74. switchTab: function() {
  75. this.showType = this.showType == 1 ? 0 : 1
  76. this.getCommentList();
  77. },
  78. },
  79. onLoad: function(options) {
  80. // 页面初始化 options为页面跳转所带来的参数
  81. this.typeId = options.typeId
  82. this.valueId = options.valueId
  83. this.getCommentCount();
  84. this.getCommentList();
  85. },
  86. onReachBottom: function() {
  87. if (this.showType == 0) {
  88. if (this.allCount / this.size < this.allPage) {
  89. return false;
  90. }
  91. this.setData({
  92. 'allPage': this.allPage + 1
  93. });
  94. } else {
  95. if (this.hasPicCount / this.size < this.picPage) {
  96. return false;
  97. }
  98. this.picPage = this.picPage + 1
  99. }
  100. this.getCommentList();
  101. }
  102. }
  103. </script>
  104. <style lang="scss">
  105. .comments {
  106. width: 100%;
  107. height: auto;
  108. padding-left: 30rpx;
  109. background: #fff;
  110. margin: 20rpx 0;
  111. }
  112. .comments .b {
  113. height: auto;
  114. width: 720rpx;
  115. }
  116. .comments .b.no-h {
  117. margin-top: 0;
  118. }
  119. .comments .item {
  120. height: auto;
  121. width: 720rpx;
  122. overflow: hidden;
  123. border-bottom: 1px solid #d9d9d9;
  124. padding-bottom: 25rpx;
  125. }
  126. .comments .info {
  127. height: 127rpx;
  128. width: 100%;
  129. padding: 33rpx 0 27rpx 0;
  130. }
  131. .comments .user {
  132. float: left;
  133. width: auto;
  134. height: 67rpx;
  135. line-height: 67rpx;
  136. font-size: 0;
  137. }
  138. .comments .user image {
  139. float: left;
  140. width: 67rpx;
  141. height: 67rpx;
  142. margin-right: 17rpx;
  143. border-radius: 50%;
  144. }
  145. .comments .user text {
  146. display: inline-block;
  147. width: auto;
  148. height: 66rpx;
  149. overflow: hidden;
  150. font-size: 29rpx;
  151. line-height: 66rpx;
  152. }
  153. .comments .time {
  154. display: block;
  155. float: right;
  156. width: auto;
  157. height: 67rpx;
  158. line-height: 67rpx;
  159. color: #7f7f7f;
  160. font-size: 25rpx;
  161. margin-right: 30rpx;
  162. }
  163. .comments .comment {
  164. width: 720rpx;
  165. padding-right: 30rpx;
  166. line-height: 45.8rpx;
  167. font-size: 29rpx;
  168. margin-bottom: 16rpx;
  169. }
  170. .comments .imgs {
  171. width: 720rpx;
  172. height: 150rpx;
  173. margin-bottom: 25rpx;
  174. }
  175. .comments .imgs .img {
  176. height: 150rpx;
  177. width: 150rpx;
  178. margin-right: 28rpx;
  179. }
  180. .comments .customer-service {
  181. width: 690rpx;
  182. height: auto;
  183. overflow: hidden;
  184. margin-top: 23rpx;
  185. background: rgba(0, 0, 0, .03);
  186. padding: 21rpx;
  187. }
  188. .comments .customer-service .u {
  189. font-size: 24rpx;
  190. color: #333;
  191. line-height: 37.5rpx;
  192. }
  193. .comments .customer-service .c {
  194. font-size: 24rpx;
  195. color: #999;
  196. line-height: 37.5rpx;
  197. }
  198. </style>