credits.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="page-wrap">
  3. <u-navbar
  4. title="积分商城"
  5. :autoBack="true"
  6. :safeAreaInsetTop="true"
  7. >
  8. </u-navbar>
  9. <view class="header">
  10. <u--image class="image" :src="staticUrl+'/img/credits-header.png'" width="100%" height="260rpx"></u--image>
  11. <view class="inner">
  12. <view class="top u-flex u-row-between">
  13. <text>积分商城</text>
  14. <view class="right u-flex">
  15. <u-icon name="error-circle" color="#fff" size="34rpx"></u-icon>
  16. <text>规则</text>
  17. </view>
  18. </view>
  19. <view class="num">64565</view>
  20. <view class="bottom">
  21. <text>积分明细</text>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="tabs-wrap">
  26. <u-tabs
  27. :list="tabsList"
  28. lineColor="#00A447"
  29. :activeStyle="{color:'#333','font-weight': '600','font-size':'30rpx'}"
  30. :inactiveStyle="{color:'#999'}"
  31. @click="tabsClick"></u-tabs>
  32. </view>
  33. <view class="">
  34. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  35. <view class="credit-product u-flex u-flex-wrap">
  36. <view class="credit-product-item" v-for="(item,index) in dataList" :key="item.id">
  37. <view class="pic">
  38. <u--image class="image" :src="item.mainImg" width="100%" height="340rpx"></u--image>
  39. </view>
  40. <view class="text">
  41. <view class="til ellipsis-2">
  42. {{item.title||'测试标题测试标题测试标题测试标题测试标题测试标题'}}
  43. </view>
  44. <view class="price">¥54.00</view>
  45. <view class="bottom u-flex u-row-between">
  46. <text>+20000积分</text>
  47. <text class="btn">兑换</text>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </mescroll-body>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. // 引入mescroll-mixins.js
  58. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  59. export default {
  60. mixins: [MescrollMixin], // 使用mixin
  61. data() {
  62. return {
  63. staticUrl:this.$commonConfig.staticUrl,
  64. tabsList:[
  65. {name:'全部'},
  66. {name:'推荐'},
  67. {name:'美食'},
  68. {name:'饮料'},
  69. {name:'住行'},
  70. {name:'其他'}
  71. ],
  72. typeId:'',
  73. dataList:[{id:1},{id:2},{id:3}],
  74. }
  75. },
  76. onShow() {
  77. },
  78. onLoad() {
  79. },
  80. methods: {
  81. /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
  82. downCallback(){
  83. this.mescroll.resetUpScroll();
  84. },
  85. /*上拉加载的回调*/
  86. upCallback(page) {
  87. // 此处可以继续请求其他接口
  88. // if(page.num == 1){
  89. // // 请求其他接口...
  90. // }
  91. // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
  92. // if(!this.hasTypeId){
  93. // this.shopNewsType();
  94. // return // 此处return,先获取xx
  95. // }
  96. let pageNum = page.num; // 页码, 默认从1开始
  97. let pageSize = page.size; // 页长, 默认每页10条
  98. let params = {
  99. pageNum : page.num,
  100. pageSize : page.size,
  101. type : this.typeId,
  102. }
  103. // console.log('this.params',params);
  104. this.$u.api.shopNewsList(params).then(data => {
  105. console.log('data',JSON.parse(JSON.stringify(data)));
  106. // 接口返回的当前页数据列表 (数组)
  107. let curPageData = data.data.rows;
  108. // console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  109. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  110. let curPageLen = curPageData.length;
  111. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  112. // let totalPage = data.data.data.totalPage;
  113. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  114. let totalSize = data.data.total;
  115. // 接口返回的是否有下一页 (true/false)
  116. // let hasNext = data.xxx;
  117. // console.log('totalPage',totalPage,'curPageLen',curPageLen);
  118. //设置列表数据
  119. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  120. this.dataList = this.dataList.concat(curPageData); //追加新数据
  121. // 请求成功,隐藏加载状态
  122. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  123. // this.mescroll.endByPage(curPageLen, totalPage);
  124. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  125. this.mescroll.endBySize(curPageLen, totalSize);
  126. }).catch(err => {
  127. this.mescroll.endErr()
  128. console.log(err)
  129. });
  130. },
  131. /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
  132. reloadList() {
  133. this.mescroll.resetUpScroll();
  134. },
  135. tabsClick(item){
  136. this.typeId = item.id;
  137. this.reloadList()
  138. // console.log('item',item);
  139. },
  140. }
  141. }
  142. </script>
  143. <style>
  144. page{
  145. background-color: #F5F5F5;
  146. }
  147. </style>
  148. <style lang="scss" scoped>
  149. .header{
  150. color: #fff;
  151. position: relative;
  152. height: 260rpx;
  153. margin-bottom: 30rpx;
  154. /deep/ .u-image{
  155. position: absolute;
  156. left: 0;
  157. right: 0;
  158. top: 0;
  159. z-index: -1;
  160. }
  161. .inner{
  162. padding: 40rpx;
  163. .top{
  164. font-size: 26rpx;
  165. text{margin-left: 10rpx;}
  166. margin-bottom: 30rpx;
  167. }
  168. .num{
  169. font-size: 50rpx;
  170. font-weight: 600;
  171. color: #FFFFFF;
  172. line-height: 58rpx;
  173. }
  174. .bottom{
  175. text-align: right;
  176. text{
  177. display: inline-block;
  178. padding: 4rpx 20rpx;
  179. background: rgba(0,0,0,0.2);
  180. color: #fff;
  181. border-radius: 23rpx;
  182. font-size: 22rpx;
  183. }
  184. }
  185. }
  186. }
  187. .tabs-wrap{
  188. background-color: #fff;
  189. margin-bottom: 10rpx;
  190. }
  191. .credit-product{
  192. margin-top: 20rpx;
  193. &-item{
  194. width: 47%;
  195. background-color: #fff;
  196. margin-bottom: 30rpx;
  197. &:nth-child(even){
  198. margin-left: 6%;
  199. }
  200. .text{
  201. padding: 20rpx;
  202. .price{
  203. margin-top: 17rpx;
  204. font-size: 24rpx;
  205. font-weight: 600;
  206. color: #FF3C3F;
  207. line-height: 33rpx;
  208. }
  209. }
  210. .bottom{
  211. font-size: 30rpx;
  212. font-weight: 600;
  213. color: #00A447;
  214. line-height: 42rpx;
  215. .btn{
  216. font-size: 22rpx;
  217. font-weight: 400;
  218. color: #FFFFFF;
  219. padding: 5rpx 18rpx;
  220. background: #00A447;
  221. border-radius: 4px;
  222. }
  223. }
  224. }
  225. }
  226. </style>