item.vue 2.2 KB

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