item.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <MeScroll :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
  3. <u-toast ref="uToast" />
  4. <card @confirm="confirm" :list="list"></card>
  5. </MeScroll>
  6. </template>
  7. <script>
  8. import MeScroll from '@/components/mescroll-body/mescroll-uni.vue'
  9. import card from './card.vue'
  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. userId: '',
  23. isInit: false, // 是否初始化
  24. list: [], // 列表数据
  25. mescroll: null, // mescroll 对象
  26. // 上拉配置参数
  27. up: {
  28. noMoreSize: 3,
  29. auto: false,
  30. page: {
  31. page: 0,
  32. size: 10
  33. }
  34. },
  35. // 下拉配置参数
  36. down: {
  37. use: false,
  38. auto: false
  39. }
  40. }
  41. },
  42. created() {
  43. this.userId = uni.getStorageSync("userId");
  44. },
  45. watch: {
  46. type(val) {
  47. if (!this.isInit && val === this.i) {
  48. this.mescroll.resetUpScroll()
  49. }
  50. }
  51. },
  52. mounted() {
  53. if (!this.isInit && this.i === 0) {
  54. this.mescroll.resetUpScroll()
  55. }
  56. },
  57. methods: {
  58. confirm(item){
  59. this.$dialog.showModal("确认收货?").then(res=>{
  60. let data=this.$u.deepClone(item)
  61. data.pointsGoodsStatus=2
  62. this.$u.api.pointsGoods.mineGoodsListSubmit(data).then(res=>{
  63. this.$u.toast('操作成功')
  64. this.mescroll.resetUpScroll()
  65. })
  66. })
  67. },
  68. /**
  69. * @param {Object} mescroll 初始化组件
  70. */
  71. initMeScroll(mescroll) {
  72. this.mescroll = mescroll
  73. },
  74. /**
  75. * @param {Object} mescroll 上拉回调
  76. */
  77. upFn(mescroll) {
  78. if (!this.userId) {
  79. this.$u.toast('用户未登录')
  80. mescroll.endErr();
  81. return
  82. }
  83. let that = this
  84. let obj = {
  85. userId: this.userId,
  86. current: mescroll.num,
  87. size: mescroll.size,
  88. pointsGoodsStatus:this.item.value
  89. }
  90. try {
  91. this.$u.api.pointsGoods.mineGoodsList(obj).then(res => {
  92. let data = res.records
  93. let length = data.length
  94. let total = res.total
  95. mescroll.endBySize(length, total);
  96. if (mescroll.num == 1) that.list = []; //如果是第一页需手动制空列表
  97. that.list = that.list.concat(data); //追加新数据
  98. })
  99. } catch (e) {
  100. mescroll.endErr();
  101. }
  102. },
  103. /**
  104. * 下拉回调
  105. * */
  106. downFn(mescroll) {
  107. setTimeout(() => {
  108. this.$showToast('刷新成功')
  109. this.mescroll.resetUpScroll()
  110. }, 1500)
  111. },
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. view {
  117. box-sizing: border-box;
  118. }
  119. </style>