You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.5 KiB

3 years ago
  1. <template>
  2. <view class="app">
  3. <view class="nav-wrap">
  4. <mix-nav-bar :navs="navs" :counts="navCounts" :current="navCurrent" @onChange="onNavBarChange"></mix-nav-bar>
  5. </view>
  6. <mescroll-body
  7. ref="mescrollRef"
  8. @init="mescrollInit"
  9. :top="84"
  10. @down="downCallback"
  11. :up="upOption"
  12. @up="loadList"
  13. >
  14. <rating-item
  15. v-for="(item, index) in list"
  16. :key="index"
  17. :item="item"
  18. ></rating-item>
  19. </mescroll-body>
  20. <mix-loading v-if="isLoading" :mask="true"></mix-loading>
  21. </view>
  22. </template>
  23. <script>
  24. import ratingItem from './components/rating-item'
  25. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  26. export default {
  27. components: {
  28. ratingItem
  29. },
  30. mixins: [MescrollMixin],
  31. data() {
  32. return {
  33. navs: [{name: '最新'}, {name: '好评'}, {name: '中评'}, {name: '差评'}, {name: '有图'}],
  34. navCurrent: 0, //当前tab
  35. upOption:{
  36. auto: false, // 是否自动加载
  37. page: {
  38. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  39. size: 15 // 每页数据的数量
  40. },
  41. noMoreSize: 5,
  42. },
  43. navCounts: [], //数量
  44. list: [],
  45. }
  46. },
  47. onLoad(options) {
  48. this.id = options.id;
  49. this.loadCount();
  50. },
  51. methods: {
  52. async loadList(e){
  53. this.mescroll && this.mescroll.removeEmpty();
  54. const res = await this.$request('rating', 'get', {
  55. product_id: this.id,
  56. offset: (e.num - 1) * e.size,
  57. limit: e.size,
  58. type: this.navCurrent
  59. });
  60. const curList = res.data;
  61. if(e.num === 1){
  62. //第一页清空数据重载
  63. this.list = [];
  64. }
  65. this.list = this.list.concat(curList); //追加新数据
  66. this.mescroll.endSuccess(curList.length); //结束加载状态
  67. },
  68. async loadCount(){
  69. const res = await this.$request('rating', 'count', {
  70. product_id: this.id
  71. })
  72. this.navCounts = res;
  73. console.log(res);
  74. },
  75. mescrollInit(mescroll){
  76. this.isLoading = true;
  77. this.mescroll = mescroll;
  78. setTimeout(()=>{
  79. this.mescroll.resetUpScroll(false)
  80. }, 10)
  81. },
  82. //tab切换
  83. onNavBarChange(current){
  84. if(this.navCurrent === current){
  85. return;
  86. }
  87. this.navCurrent = current;
  88. this.isLoading = true;
  89. this.mescroll && this.mescroll.resetUpScroll(false)
  90. }
  91. }
  92. }
  93. </script>
  94. <style scoped lang="scss">
  95. .app{
  96. padding: 0 30rpx;
  97. /deep/ {
  98. .mescroll-body-content{
  99. padding-top: 10rpx;
  100. }
  101. }
  102. }
  103. </style>