item.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_shopId || null,
  73. params.launchType=this.$global.SHOP
  74. res=await this.$api.activity.list(params)
  75. }
  76. if (this.item.value==1) {
  77. //可参加的活动
  78. params.mallId=this.vuex_mallId || null
  79. params.launchId=this.vuex_shopId || null,
  80. params.launchType=this.$global.SHOP
  81. res=await this.$api.activity.getCanJoinActivity(params)
  82. }
  83. if (this.item.value==2) {
  84. // 已参加的活动
  85. params.joinId=this.vuex_shopId || null
  86. params.joinType=this.$global.SHOP
  87. res=await this.$api.joinRecord.joined(params)
  88. }
  89. try{
  90. let data=res.data.records
  91. let length=data.length
  92. let total=res.data.total
  93. mescroll.endBySize(length, total);
  94. if(mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
  95. this.list=this.list.concat(data); //追加新数据
  96. }catch(e){
  97. mescroll.endErr();
  98. }
  99. },
  100. //下拉回调
  101. downFn(mescroll) {
  102. setTimeout(()=>{
  103. this.u.toast('刷新成功')
  104. this.mescroll.resetUpScroll()
  105. },1500)
  106. },
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. view{
  112. box-sizing: border-box;
  113. }
  114. </style>