comment.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view class="comments">
  3. <view class="h">
  4. <view :class="'item ' + (showType == 0 ? 'active' : '')" @tap="switchTab">
  5. <view class="txt">全部({{ allCount }})</view>
  6. </view>
  7. <view :class="'item ' + (showType == 0 ? '' : 'active')" @tap="switchTab">
  8. <view class="txt">有图({{ hasPicCount }})</view>
  9. </view>
  10. </view>
  11. <view class="b">
  12. <view class="item" v-for="(item, index) in comments" :key="index">
  13. <view class="info">
  14. <view class="user">
  15. <image :src="item.userInfo.avatarUrl"></image>
  16. <text>{{ item.userInfo.nickname }}</text>
  17. </view>
  18. <view class="time">{{ item.addTime }}</view>
  19. </view>
  20. <view class="comment">{{ item.content }}</view>
  21. <view class="imgs" v-if="item.picList.length > 0">
  22. <image class="img" :src="pitem" v-for="(pitem, index1) in item.picList" :key="index1"></image>
  23. </view>
  24. <view class="customer-service" v-if="item.adminContent">
  25. <text class="u">商家回复:</text>
  26. <text class="c">{{ item.adminContent }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. var app = getApp();
  34. var util = require('../../../utils/util.js');
  35. var api = require('../../../config/api.js');
  36. export default {
  37. data() {
  38. return {
  39. comments: [],
  40. allCommentList: [],
  41. picCommentList: [],
  42. type: 0,
  43. valueId: 0,
  44. showType: 0,
  45. allCount: 0,
  46. hasPicCount: 0,
  47. allPage: 1,
  48. picPage: 1,
  49. limit: 20,
  50. pitem: ''
  51. };
  52. },
  53. onLoad: function (options) {
  54. // 页面初始化 options为页面跳转所带来的参数
  55. this.setData({
  56. type: options.type,
  57. valueId: options.valueId
  58. });
  59. this.getCommentCount();
  60. this.getCommentList();
  61. },
  62. onPullDownRefresh() {
  63. uni.showNavigationBarLoading(); //在标题栏中显示加载
  64. this.getCommentCount();
  65. this.getCommentList();
  66. uni.hideNavigationBarLoading(); //完成停止加载
  67. uni.stopPullDownRefresh(); //停止下拉刷新
  68. },
  69. onReady: function () {
  70. // 页面渲染完成
  71. },
  72. onShow: function () {
  73. // 页面显示
  74. },
  75. onHide: function () {
  76. // 页面隐藏
  77. },
  78. onUnload: function () {
  79. // 页面关闭
  80. },
  81. onReachBottom: function () {
  82. console.log('onPullDownRefresh');
  83. if (this.showType == 0) {
  84. if (this.allCount / this.limit < this.allPage) {
  85. return false;
  86. }
  87. this.setData({
  88. allPage: this.allPage + 1
  89. });
  90. } else {
  91. if (this.hasPicCount / this.limit < this.picPage) {
  92. return false;
  93. }
  94. this.setData({
  95. picPage: this.picPage + 1
  96. });
  97. }
  98. this.getCommentList();
  99. },
  100. methods: {
  101. getCommentCount: function () {
  102. let that = this;
  103. util.request(api.CommentCount, {
  104. valueId: that.valueId,
  105. type: that.type
  106. }).then(function (res) {
  107. if (res.errno === 0) {
  108. that.setData({
  109. allCount: res.data.allCount,
  110. hasPicCount: res.data.hasPicCount
  111. });
  112. }
  113. });
  114. },
  115. getCommentList: function () {
  116. let that = this;
  117. util.request(api.CommentList, {
  118. valueId: that.valueId,
  119. type: that.type,
  120. limit: that.limit,
  121. page: that.showType == 0 ? that.allPage : that.picPage,
  122. showType: that.showType
  123. }).then(function (res) {
  124. if (res.errno === 0) {
  125. if (that.showType == 0) {
  126. that.setData({
  127. allCommentList: that.allCommentList.concat(res.data.list),
  128. allPage: res.data.page,
  129. comments: that.allCommentList.concat(res.data.list)
  130. });
  131. } else {
  132. that.setData({
  133. picCommentList: that.picCommentList.concat(res.data.list),
  134. picPage: res.data.page,
  135. comments: that.picCommentList.concat(res.data.list)
  136. });
  137. }
  138. }
  139. });
  140. },
  141. switchTab: function () {
  142. let that = this;
  143. if (that.showType == 0) {
  144. that.setData({
  145. allCommentList: [],
  146. allPage: 1,
  147. comments: [],
  148. showType: 1
  149. });
  150. } else {
  151. that.setData({
  152. picCommentList: [],
  153. picPage: 1,
  154. comments: [],
  155. showType: 0
  156. });
  157. }
  158. this.getCommentList();
  159. }
  160. }
  161. };
  162. </script>
  163. <style>
  164. .comments {
  165. width: 100%;
  166. height: auto;
  167. padding-left: 30rpx;
  168. background: #fff;
  169. margin: 20rpx 0;
  170. }
  171. .comments .h {
  172. position: fixed;
  173. left: 0;
  174. top: 0;
  175. z-index: 1000;
  176. width: 100%;
  177. display: flex;
  178. background: #fff;
  179. height: 84rpx;
  180. border-bottom: 1px solid rgba(0, 0, 0, 0.15);
  181. }
  182. .comments .h .item {
  183. display: inline-block;
  184. height: 82rpx;
  185. width: 50%;
  186. padding: 0 15rpx;
  187. text-align: center;
  188. }
  189. .comments .h .item .txt {
  190. display: inline-block;
  191. height: 82rpx;
  192. padding: 0 20rpx;
  193. line-height: 82rpx;
  194. color: #333;
  195. font-size: 30rpx;
  196. width: 170rpx;
  197. }
  198. .comments .h .item.active .txt {
  199. color: #ab2b2b;
  200. border-bottom: 4rpx solid #ab2b2b;
  201. }
  202. .comments .b {
  203. margin-top: 85rpx;
  204. height: auto;
  205. width: 720rpx;
  206. }
  207. .comments .b.no-h {
  208. margin-top: 0;
  209. }
  210. .comments .item {
  211. height: auto;
  212. width: 720rpx;
  213. overflow: hidden;
  214. border-bottom: 1px solid #d9d9d9;
  215. padding-bottom: 25rpx;
  216. }
  217. .comments .info {
  218. height: 127rpx;
  219. width: 100%;
  220. padding: 33rpx 0 27rpx 0;
  221. }
  222. .comments .user {
  223. float: left;
  224. width: auto;
  225. height: 67rpx;
  226. line-height: 67rpx;
  227. font-size: 0;
  228. }
  229. .comments .user image {
  230. float: left;
  231. width: 67rpx;
  232. height: 67rpx;
  233. margin-right: 17rpx;
  234. border-radius: 50%;
  235. }
  236. .comments .user text {
  237. display: inline-block;
  238. width: auto;
  239. height: 66rpx;
  240. overflow: hidden;
  241. font-size: 29rpx;
  242. line-height: 66rpx;
  243. }
  244. .comments .time {
  245. display: block;
  246. float: right;
  247. width: auto;
  248. height: 67rpx;
  249. line-height: 67rpx;
  250. color: #7f7f7f;
  251. font-size: 25rpx;
  252. margin-right: 30rpx;
  253. }
  254. .comments .comment {
  255. width: 720rpx;
  256. padding-right: 30rpx;
  257. line-height: 45.8rpx;
  258. font-size: 29rpx;
  259. margin-bottom: 16rpx;
  260. }
  261. .comments .imgs {
  262. width: 720rpx;
  263. height: 150rpx;
  264. margin-bottom: 25rpx;
  265. }
  266. .comments .imgs .img {
  267. height: 150rpx;
  268. width: 150rpx;
  269. margin-right: 28rpx;
  270. }
  271. .comments .spec {
  272. width: 720rpx;
  273. height: 25rpx;
  274. font-size: 24rpx;
  275. color: #999;
  276. }
  277. .comments .spec .item {
  278. color: #7f7f7f;
  279. font-size: 25rpx;
  280. }
  281. .comments .customer-service {
  282. width: 690rpx;
  283. height: auto;
  284. overflow: hidden;
  285. margin-top: 23rpx;
  286. background: rgba(0, 0, 0, 0.03);
  287. padding: 21rpx;
  288. }
  289. .comments .customer-service .u {
  290. font-size: 24rpx;
  291. color: #333;
  292. line-height: 37.5rpx;
  293. }
  294. .comments .customer-service .c {
  295. font-size: 24rpx;
  296. color: #999;
  297. line-height: 37.5rpx;
  298. }
  299. </style>