mystore.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="我的门店"
  5. :placeholder="true"
  6. :autoBack="true"
  7. @leftClick="leftClick"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. <!-- <view class="tabs-wrap">
  12. <u-tabs
  13. :list="tabsList"
  14. lineColor="#00A447"
  15. :activeStyle="{color:'#333','font-weight': '600','font-size':'30rpx'}"
  16. :inactiveStyle="{color:'#999'}"
  17. @click="tabsClick"></u-tabs>
  18. </view> -->
  19. <view class="page-wrap">
  20. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  21. <view class="u-flex u-flex-wrap u-row-between">
  22. <view class="list-item" v-for="item in dataList" @click="$u.route('/center/store',{id:item.id})" :key="item.id">
  23. <view class="item">
  24. <view class="image-wrap">
  25. <u--image mode="aspectFill" height="300rpx" width="100%" :showLoading="true" class="image" :src="item.mainImg"></u--image>
  26. </view>
  27. <view class="name ellipsis-1">{{item.name}}</view>
  28. </view>
  29. </view>
  30. </view>
  31. </mescroll-body>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. // 引入mescroll-mixins.js
  37. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  38. export default {
  39. mixins: [MescrollMixin], // 使用mixin
  40. components:{
  41. },
  42. data() {
  43. return {
  44. downOption: {},
  45. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  46. upOption: {
  47. page: {
  48. size: 10 // 每页数据的数量,默认10
  49. },
  50. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  51. empty: {
  52. tip: '~暂无店铺~',
  53. icon:'../static/img/empty.png'
  54. }
  55. },
  56. tabsList:[],
  57. activeIndex:0,
  58. typeId:null,
  59. dataList:[]
  60. }
  61. },
  62. onLoad() {
  63. // this.shopGoodsType();
  64. },
  65. methods: {
  66. leftClick(e){
  67. let pages = getCurrentPages();
  68. if(pages.length==1){uni.$u.route('/pages/index/index')};
  69. },
  70. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  71. downCallback(){
  72. this.mescroll.resetUpScroll();
  73. },
  74. /*上拉加载的回调*/
  75. upCallback(page) {
  76. // 此处可以继续请求其他接口
  77. // if(page.num == 1){
  78. // // 请求其他接口...
  79. // }
  80. //如果希望先请求其他接口,再触发upCallback,可参考以下写法
  81. // if(!this.hasTypeId){
  82. // this.$u.api.shopGoodsType().then(res=>{
  83. // // this.tabsList = res.data;
  84. // this.tabsList = res.data.map(item=>{
  85. // return {name:item.dictLabel,id:item.dictValue}
  86. // });
  87. // this.hasTypeId = true
  88. // this.mescroll.resetUpScroll() // 重新触发upCallback
  89. // }).catch(()=>{
  90. // this.mescroll.endErr()
  91. // })
  92. // return // 此处return,先获取xx
  93. // }
  94. // let typeId = this.tabsList[this.activeIndex].id;
  95. let pageNum = page.num; // 页码, 默认从1开始
  96. let pageSize = page.size; // 页长, 默认每页10条
  97. let params ={
  98. // typeId:typeId,
  99. pageNum:pageNum,
  100. pageSize:pageSize
  101. };
  102. console.log('params',params);
  103. this.$u.api.shopList(params).then(data => {
  104. console.log('data',JSON.parse(JSON.stringify(data)));
  105. // 接口返回的当前页数据列表 (数组)
  106. let curPageData = data.data.list;
  107. // console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  108. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  109. let curPageLen = curPageData.length;
  110. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  111. // let totalPage = data.data.totalPage;
  112. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  113. let totalSize = data.data.total;
  114. // 接口返回的是否有下一页 (true/false)
  115. // let hasNext = data.xxx;
  116. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  117. //设置列表数据
  118. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  119. this.dataList = this.dataList.concat(curPageData); //追加新数据
  120. // 请求成功,隐藏加载状态
  121. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  122. // this.mescroll.endByPage(curPageLen, totalPage);
  123. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  124. this.mescroll.endBySize(curPageLen, totalSize);
  125. }).catch(err => {
  126. this.mescroll.endErr()
  127. console.log(err)
  128. });
  129. },
  130. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  131. reloadList() {
  132. this.mescroll.resetUpScroll();
  133. },
  134. // shopGoodsType(){
  135. // this.$u.api.shopGoodsType().then(res=>{
  136. // console.log('shopGoodsType',res.data);
  137. // this.tabsList = res.data.map(item=>{
  138. // return {name:item.dictLabel,id:item.dictValue}
  139. // });
  140. // console.log('shopGoodsType',res.data);
  141. // console.log('tabsList',this.tabsList);
  142. // }).catch(err=>{
  143. // // console.log('err11111',err);
  144. // })
  145. // },
  146. tabsClick(item){
  147. this.activeIndex = item.index;
  148. this.reloadList()
  149. console.log('item',item);
  150. },
  151. }
  152. }
  153. </script>
  154. <style>
  155. page{
  156. background-color: #F9F9F9;
  157. }
  158. </style>
  159. <style lang="scss" scoped>
  160. .tabs-wrap{
  161. background-color: #fff;
  162. margin-bottom: 10rpx;
  163. }
  164. .list-item{
  165. overflow: hidden;
  166. width: 48%;
  167. margin-bottom: 30rpx;
  168. padding-bottom: 20rpx;
  169. background-color: #fff;
  170. .image-wrap{
  171. margin-bottom: 20rpx;
  172. }
  173. .name{
  174. padding: 0 20rpx;
  175. }
  176. }
  177. </style>