item.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <view class="">
  3. <u-toast ref="uToast"/>
  4. <MeScroll :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
  5. <card :list="dataList" :current="i"></card>
  6. </MeScroll>
  7. </view>
  8. </template>
  9. <script>
  10. import MeScroll from '@/components/mescroll-body/mescroll-uni.vue'
  11. import card from './card.vue'
  12. var app=getApp()
  13. export default {
  14. components:{
  15. MeScroll,card
  16. },
  17. props: {
  18. type: Number,
  19. i: Number,
  20. item:Object
  21. },
  22. data() {
  23. return {
  24. tenantId:'',
  25. isInit: false, // 是否初始化
  26. dataList: [], // 列表数据
  27. mescroll: null, // mescroll 对象
  28. // 上拉配置参数
  29. up: {
  30. noMoreSize: 2,
  31. auto: false,
  32. page: {
  33. page: 0,
  34. size: 10
  35. }
  36. },
  37. // 下拉配置参数
  38. down: {
  39. use: true,
  40. auto: false
  41. }
  42. }
  43. },
  44. created() {
  45. this.tenantId=this.$cache.get('agencyTenantId')
  46. },
  47. watch:{
  48. type(val) {
  49. if(!this.isInit && val === this.i) {
  50. this.mescroll.resetUpScroll()
  51. }
  52. }
  53. },
  54. mounted() {
  55. if(!this.isInit && this.i === 0) {
  56. this.mescroll.resetUpScroll()
  57. }
  58. },
  59. methods: {
  60. /**
  61. * @param {Object} mescroll 初始化组件
  62. */
  63. initMeScroll(mescroll) {
  64. this.mescroll = mescroll
  65. },
  66. /**
  67. * @param {Object} mescroll 上拉回调
  68. */
  69. async upFn(mescroll) {
  70. let that=this
  71. let params={
  72. current:mescroll.num,
  73. size:mescroll.size,
  74. tenantId:this.tenantId,
  75. }
  76. let res=null
  77. try{
  78. if (this.i==0) {
  79. //入场记录
  80. res=await this.$api.car.enterPage(params)
  81. }else if (this.i==1) {
  82. //出场记录
  83. res=await this.$api.car.outPage(params)
  84. }
  85. let data=res.data.records
  86. this.mescroll.endBySize(data.length, res.total)
  87. if (mescroll.num==1) this.dataList=[]
  88. this.dataList=this.dataList.concat(data)
  89. }catch(e){
  90. this.mescroll.endErr();
  91. }
  92. },
  93. /**
  94. * 下拉回调
  95. * */
  96. downFn(mescroll) {
  97. setTimeout(()=>{
  98. this.$showToast('刷新成功')
  99. this.mescroll.resetUpScroll()
  100. },1500)
  101. },
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. view{
  107. box-sizing: border-box;
  108. }
  109. </style>