comment.vue 5.4 KB

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