item.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <MeScroll :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
  3. <card :list="list" :current="type"></card>
  4. </MeScroll>
  5. </template>
  6. <script>
  7. import MeScroll from '@/components/mescroll-body/mescroll-uni.vue'
  8. import card from './card.vue'
  9. export default {
  10. components:{
  11. MeScroll,card
  12. },
  13. props: {
  14. refresh:false,
  15. type: Number,
  16. i: Number,
  17. item:Object
  18. },
  19. data() {
  20. return {
  21. isInit: false, // 是否初始化
  22. list: [], // 列表数据
  23. mescroll: null, // mescroll 对象
  24. // 上拉配置参数
  25. up: {
  26. noMoreSize: 5,
  27. auto: false,
  28. page: {
  29. page: 0,
  30. size: 10
  31. }
  32. },
  33. // 下拉配置参数
  34. down: {
  35. use: false,
  36. auto: false
  37. }
  38. }
  39. },
  40. created() {
  41. },
  42. watch:{
  43. type(val) {
  44. if(!this.isInit && val === this.i) {
  45. this.mescroll.resetUpScroll()
  46. }
  47. },
  48. refresh(val) {
  49. console.log(val);
  50. this.mescroll.resetUpScroll()
  51. }
  52. },
  53. mounted() {
  54. if(!this.isInit && this.i === 0) {
  55. this.mescroll.resetUpScroll()
  56. }
  57. },
  58. methods: {
  59. //初始化组件
  60. initMeScroll(mescroll) {
  61. this.mescroll = mescroll
  62. },
  63. //上拉回调
  64. async upFn(mescroll) {
  65. let res=null
  66. let params={
  67. current:mescroll.num,
  68. size:mescroll.size,
  69. }
  70. if (this.item.value==0) {
  71. //自己发起的活动
  72. params.launchId=this.vuex_mallId || '-1',
  73. params.launchType=this.$global.sponsorType.mall
  74. res=await this.$api.activity.list(params)
  75. }
  76. if (this.item.value==1) {
  77. //可参加的活动
  78. //该商场发布的活动或者该商场下的商户发布的活动
  79. params.mallId=this.vuex_mallId || '-1'
  80. params.launchId=this.vuex_mallId || '-1',
  81. params.launchType=this.$global.sponsorType.mall
  82. res=await this.$api.activity.getCanJoinActivity(params)
  83. }
  84. if (this.item.value==2) {
  85. // 已参加的活动
  86. params.joinId=this.vuex_mallId || '-1'
  87. params.joinType=this.$global.sponsorType.mall
  88. res=await this.$api.joinRecord.joined(params)
  89. }
  90. console.log(res);
  91. try{
  92. let data=res.data.records
  93. let length=data.length
  94. let total=res.data.total
  95. mescroll.endBySize(length, total);
  96. if(mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
  97. this.list=this.list.concat(data); //追加新数据
  98. }catch(e){
  99. mescroll.endErr();
  100. }
  101. },
  102. //下拉回调
  103. downFn(mescroll) {
  104. setTimeout(()=>{
  105. this.u.toast('刷新成功')
  106. this.mescroll.resetUpScroll()
  107. },1500)
  108. },
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. view{
  114. box-sizing: border-box;
  115. }
  116. </style>