comment.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="">
  3. <u-navbar
  4. :title="title"
  5. :placeholder="true"
  6. :autoBack="true"
  7. :safeAreaInsetTop="true"
  8. >
  9. </u-navbar>
  10. <!-- <view class="sort u-flex">
  11. <view class="sort-item"
  12. :class="{active:index==activeIndex}"
  13. @click="sortClick(index)"
  14. v-for="(item,index) in sortArr" :key="index">
  15. {{item.name}}
  16. </view>
  17. </view> -->
  18. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  19. <view class="page-wrap" >
  20. <view class="comment" v-for="item in dataList" :key="item.id">
  21. <view class="top u-flex u-row-between">
  22. <view class="left u-flex">
  23. <u-avatar :src="item.avatar"></u-avatar>
  24. <view class="name">{{item.createBy}}</view>
  25. </view>
  26. <view class="time">{{item.createTime}}</view>
  27. </view>
  28. <u-rate count="5" active-color="#FFB600" v-model="item.star" readonly></u-rate>
  29. <view class="text">{{item.contentText}}</view>
  30. <view class="imgs" v-if="item.contentImgList">
  31. <u-album :urls="item.contentImgList"></u-album>
  32. </view>
  33. </view>
  34. </view>
  35. </mescroll-body>
  36. </view>
  37. </template>
  38. <script>
  39. // 引入mescroll-mixins.js
  40. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  41. export default {
  42. mixins: [MescrollMixin], // 使用mixin
  43. components: {
  44. },
  45. data() {
  46. return {
  47. staticUrl:this.$commonConfig.staticUrl,
  48. downOption: {},
  49. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  50. upOption: {
  51. page: {
  52. size: 10 // 每页数据的数量,默认10
  53. },
  54. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  55. empty: {
  56. tip: '暂无相关数据'
  57. }
  58. },
  59. title:'商品评价',
  60. params:{
  61. id:'',
  62. },
  63. activeIndex:0,
  64. sortArr:[{name:'综合'},{name:'有图'},{name:'最新'},{name:'好评'}],
  65. // 列表数据
  66. dataList: []
  67. }
  68. },
  69. onLoad(page) {
  70. // console.log('page',page);
  71. this.params.id = page.id;
  72. },
  73. methods: {
  74. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  75. downCallback(){
  76. this.mescroll.resetUpScroll();
  77. },
  78. /*上拉加载的回调*/
  79. upCallback(page) {
  80. // 此处可以继续请求其他接口
  81. // if(page.num == 1){
  82. // // 请求其他接口...
  83. // }
  84. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  85. if(!this.params.id){
  86. this.mescroll.endErr()
  87. return // 此处return,先获取xx
  88. }
  89. let pageNum = page.num; // 页码, 默认从1开始
  90. let pageSize = page.size; // 页长, 默认每页10条isAsc:0//时间排序 0:降序 1:升序 (默认星级降序排序)
  91. if('最新'){
  92. this.params.isAsc = 0
  93. }
  94. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  95. this.$u.api.commentList(this.params).then(data => {
  96. console.log('data',JSON.parse(JSON.stringify(data)));
  97. // 接口返回的当前页数据列表 (数组)
  98. let curPageData = data.data.rows;
  99. console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  100. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  101. let curPageLen = curPageData.length;
  102. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  103. // let totalPage = data.data.data.totalPage;
  104. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  105. let totalSize = data.data.total;
  106. // 接口返回的是否有下一页 (true/false)
  107. // let hasNext = data.xxx;
  108. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  109. //设置列表数据
  110. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  111. this.dataList = this.dataList.concat(curPageData); //追加新数据
  112. // 请求成功,隐藏加载状态
  113. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  114. // this.mescroll.endByPage(curPageLen, totalPage);
  115. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  116. this.mescroll.endBySize(curPageLen, totalSize);
  117. }).catch(err => {
  118. this.mescroll.endErr()
  119. console.log(err)
  120. });
  121. },
  122. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  123. reloadList() {
  124. this.mescroll.resetUpScroll();
  125. },
  126. sortClick(index){
  127. this.activeIndex = index;
  128. this.params.name = this.sortArr[index].name;
  129. this.reloadList();
  130. },
  131. search(e){
  132. this.reloadList();
  133. console.log('search',e)
  134. }
  135. }
  136. }
  137. </script>
  138. <style>
  139. page{
  140. background-color: #F5F5F5;
  141. }
  142. </style>
  143. <style lang="scss" scoped>
  144. .sort{
  145. background-color: #fff;
  146. padding: 40rpx 20rpx 20rpx;
  147. margin-bottom: 20rpx;
  148. .sort-item{
  149. background-color: #F5F5F5;
  150. border-radius: 2px;
  151. font-size: 26rpx;
  152. padding: 6rpx 18rpx;
  153. border: 1px solid #F5F5F5;
  154. &.active{
  155. background-color: #E5F5EC;
  156. border-color: #00A447;
  157. color: #00A447;
  158. }
  159. &:not(:first-child){
  160. margin-left: 20rpx;
  161. }
  162. }
  163. }
  164. .comment{
  165. background-color: #fff;
  166. padding: 20rpx;
  167. margin-bottom: 70rpx;
  168. font-size: 26rpx;
  169. .top{
  170. margin-bottom: 30rpx;
  171. font-weight: 400;
  172. color: #999999;
  173. .name{
  174. margin-left: 10rpx;
  175. font-weight: 600;
  176. color: #333333;
  177. }
  178. }
  179. .text{
  180. margin:20rpx 0;
  181. font-weight: 400;
  182. color: #333333;
  183. line-height: 37rpx;
  184. }
  185. }
  186. </style>