productList.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view class="">
  3. <u-navbar
  4. :title="typeName"
  5. :autoBack="true"
  6. :safeAreaInsetTop="true"
  7. >
  8. </u-navbar>
  9. <view class="search-wrap">
  10. <u--input
  11. placeholder="输入搜索内容"
  12. prefixIcon="search"
  13. shape="circle"
  14. v-model="params.goodsName"
  15. @confirm="search"
  16. :customStyle="{'border-color':'#00A447!important'}"
  17. prefixIconStyle="font-size: 22px;color: #333"></u--input>
  18. </view>
  19. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  20. <view class="page-wrap" >
  21. <view class="" v-for="item in dataList" :key="item.id" @click="$u.route('/shopping/productdetails',{id:item.id})">
  22. <view class="product u-flex">
  23. <u--image :showLoading="true" :src="item.mainImg" width="180rpx" height="180rpx"></u--image>
  24. <view class="text">
  25. <view class="name ellipsis-2">{{item.goodsName}}</view>
  26. <view class="u-flex u-row-between">
  27. <view class="left">
  28. <view class="up">
  29. <view class="" v-if="vuex_member_info.levelType>1">
  30. <text class="price">¥ <text class="price-num">{{item.vipPrice}}</text></text>
  31. <text class="vip-icon">VIP</text>
  32. </view>
  33. <view class="" v-else>
  34. <text class="price">¥ <text class="price-num">{{item.salePrice}}</text></text>
  35. </view>
  36. </view>
  37. <view class="down">
  38. <!-- <text class="discount">8.8折</text> -->
  39. <text v-if="vuex_member_info.levelType>1" class="original-price gray line-through">¥ {{item.salePrice}}</text>
  40. <text class="sales gray">销量 {{item.saleCount}}</text>
  41. </view>
  42. </view>
  43. <u--image :showLoading="false" :src="staticUrl+'/img/add.png'" width="48rpx" height="48rpx"></u--image>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </mescroll-body>
  50. </view>
  51. </template>
  52. <script>
  53. // 引入mescroll-mixins.js
  54. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  55. export default {
  56. mixins: [MescrollMixin], // 使用mixin
  57. components: {
  58. },
  59. data() {
  60. return {
  61. staticUrl:this.$commonConfig.staticUrl,
  62. downOption: {},
  63. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  64. upOption: {
  65. page: {
  66. size: 10 // 每页数据的数量,默认10
  67. },
  68. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  69. empty: {
  70. tip: '暂无相关数据'
  71. }
  72. },
  73. typeName:'产品',
  74. params:{
  75. goodsName:'',
  76. typeId:'',
  77. // isExplode:0,//是否爆款 0不是,1是
  78. },
  79. // 列表数据
  80. dataList: []
  81. }
  82. },
  83. onLoad(page) {
  84. this.params.typeId = page.typeId;
  85. this.typeName = page.typeName||'产品';
  86. },
  87. methods: {
  88. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  89. downCallback(){
  90. this.mescroll.resetUpScroll();
  91. },
  92. /*上拉加载的回调*/
  93. upCallback(page) {
  94. // 此处可以继续请求其他接口
  95. // if(page.num == 1){
  96. // // 请求其他接口...
  97. // }
  98. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  99. if(!this.params.typeId){
  100. return // 此处return,先获取xx
  101. }
  102. let pageNum = page.num; // 页码, 默认从1开始
  103. let pageSize = page.size; // 页长, 默认每页10条
  104. if(this.typeName=='爆款专区'){
  105. this.params.typeId = '';
  106. this.params.isExplode = 1;
  107. }
  108. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  109. this.$u.api.memberGoodList(this.params).then(data => {
  110. console.log('data',JSON.parse(JSON.stringify(data)));
  111. // 接口返回的当前页数据列表 (数组)
  112. let curPageData = data.data.rows;
  113. console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  114. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  115. let curPageLen = curPageData.length;
  116. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  117. // let totalPage = data.data.data.totalPage;
  118. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  119. let totalSize = data.data.total;
  120. // 接口返回的是否有下一页 (true/false)
  121. // let hasNext = data.xxx;
  122. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  123. //设置列表数据
  124. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  125. this.dataList = this.dataList.concat(curPageData); //追加新数据
  126. // 请求成功,隐藏加载状态
  127. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  128. // this.mescroll.endByPage(curPageLen, totalPage);
  129. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  130. this.mescroll.endBySize(curPageLen, totalSize);
  131. }).catch(err => {
  132. this.mescroll.endErr()
  133. console.log(err)
  134. });
  135. },
  136. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  137. reloadList() {
  138. this.mescroll.resetUpScroll();
  139. },
  140. search(e){
  141. this.reloadList();
  142. console.log('search',e)
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .product{}
  149. </style>