mescrollUni-item.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <!--
  3. swiper中的transfrom会使fixed失效,此时用height固定高度;
  4. swiper中无法触发mescroll-mixins.js的onPageScroll和onReachBottom方法,只能用mescroll-uni,不能用mescroll-body
  5. -->
  6. <!-- ref动态生成: 字节跳动小程序编辑器不支持一个页面存在相同的ref (如不考虑字节跳动小程序可固定值为 ref="mescrollRef") -->
  7. <!-- top的高度等于悬浮菜单tabs的高度 -->
  8. <mescroll-uni :ref="'mescrollRef' + i" @init="mescrollInit" :height="height" :down="downOption" @down="downCallback"
  9. :up="upOption" @up="upCallback" @emptyclick="emptyClick">
  10. <view>
  11. <view class="item" v-for="(item,index) in list" :key="index">
  12. <view class="flex-row justify-between" @click="goOrderDetail(item)">
  13. <view class="leftText" :class="{'backColor1':item.tradeNoType == '1','backColor2':item.tradeNoType == '2','backColor3':item.tradeNoType == '3'}">
  14. <text v-if="item.tradeNoType == '1'">消费</text>
  15. <text v-if="item.tradeNoType == '2'">充值</text>
  16. <text v-if="item.tradeNoType == '3'">退款</text>
  17. </view>
  18. <view class="rightText flex-col">
  19. <view class=" flex-row justify-between">
  20. <text class="text1">{{item.remark}}</text>
  21. <text class="text2" v-if="item.tradeNoType == '2'">¥{{item.amount}}</text>
  22. <text class="text2" v-else>-¥{{item.amount}}</text>
  23. </view>
  24. <view class=" flex-row justify-between">
  25. <text class="text3">{{item.createTime}}</text>
  26. <text class="text3">账户余额:¥{{item.beforeBalance}}</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </mescroll-uni>
  33. </template>
  34. <script>
  35. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  36. import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js"
  37. export default {
  38. mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
  39. components: {
  40. },
  41. data() {
  42. return {
  43. downOption: {
  44. auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
  45. },
  46. upOption: {
  47. auto: false, // 不自动加载
  48. // page: {
  49. // num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  50. // size: 10 // 每页数据的数量
  51. // },
  52. noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  53. empty: {
  54. icon: '/static/imageIcon/empty.png',
  55. tip: '暂无内容', // 提示
  56. // btnText: '去看看'
  57. },
  58. textNoMore: '没有更多了'
  59. },
  60. list:[],
  61. }
  62. },
  63. props: {
  64. i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
  65. index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
  66. type: Number,
  67. default () {
  68. return 0
  69. }
  70. },
  71. dataTime:{
  72. type:String,
  73. default(){
  74. return ''
  75. }
  76. },
  77. tabs: { // 为了请求数据,演示用,可根据自己的项目判断是否要传
  78. type: Array,
  79. default () {
  80. return []
  81. }
  82. },
  83. height: [Number, String], // mescroll的高度
  84. },
  85. watch:{
  86. },
  87. created(){
  88. },
  89. methods: {
  90. /*下拉刷新的回调 */
  91. downCallback() {
  92. // 这里加载你想下拉刷新的数据, 比如刷新轮播数据
  93. // loadSwiper();
  94. // 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  95. this.mescroll.resetUpScroll()
  96. },
  97. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  98. upCallback(page) {
  99. //联网加载数据
  100. let httpData = {
  101. pageNum:page.num,
  102. pageSize:10,
  103. dataTime:this.dataTime,
  104. tradeNoType:this.index
  105. }
  106. if (this.index ===0){
  107. httpData.tradeNoType = ''
  108. }
  109. this.$api.transactionRecordsList(httpData).then((res) => {
  110. //联网成功的回调,隐藏下拉刷新和上拉加载的状态;
  111. this.mescroll.endSuccess(res.data.rows.length,res.data.rows.length === 10);
  112. //设置列表数据
  113. if (page.num === 1) this.list = []; //如果是第一页需手动制空列表
  114. this.list = this.list.concat(res.data.rows); //追加新数据
  115. console.log(this.list)
  116. }).catch((err) => {
  117. //联网失败, 结束加载
  118. this.mescroll.endErr();
  119. })
  120. },
  121. //点击空布局按钮的回调
  122. emptyClick() {
  123. uni.showToast({
  124. title: '点击了按钮,具体逻辑自行实现'
  125. })
  126. },
  127. // 搜索
  128. doSearch() {
  129. this.list = []; // 先清空列表,显示加载进度
  130. this.mescroll.resetUpScroll();
  131. },
  132. goOrderDetail(item){
  133. uni.navigateTo({
  134. url:'/myPages/transactionRecordDetail/index?item='+JSON.stringify(item)
  135. })
  136. },
  137. }
  138. }
  139. </script>
  140. <style>
  141. @import '/common/css/common.css';
  142. @import './index.rpx.css';
  143. </style>