select-popup.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <su-popup :show="show" showClose round="10" backgroundColor="#eee" @close="emits('close')">
  3. <view class="select-popup">
  4. <view class="title">
  5. <span>{{ mode == 'goods' ? '我的浏览' : '我的订单' }}</span>
  6. </view>
  7. <scroll-view
  8. class="scroll-box"
  9. scroll-y="true"
  10. :scroll-with-animation="true"
  11. :show-scrollbar="false"
  12. @scrolltolower="loadmore"
  13. >
  14. <view
  15. class="item"
  16. v-for="item in state.pagination.data"
  17. :key="item.id"
  18. @tap="emits('select', { type: mode, data: item })"
  19. >
  20. <template v-if="mode == 'goods'">
  21. <GoodsItem :goodsData="item" />
  22. </template>
  23. <template v-if="mode == 'order'">
  24. <OrderItem :orderData="item" />
  25. </template>
  26. </view>
  27. <uni-load-more :status="state.loadStatus" :content-text="{ contentdown: '上拉加载更多' }" />
  28. </scroll-view>
  29. </view>
  30. </su-popup>
  31. </template>
  32. <script setup>
  33. import { reactive, watch } from 'vue';
  34. import _ from 'lodash-es';
  35. import GoodsItem from './goods.vue';
  36. import OrderItem from './order.vue';
  37. import OrderApi from '@/sheep/api/trade/order';
  38. import SpuHistoryApi from '@/sheep/api/product/history';
  39. const emits = defineEmits(['select', 'close']);
  40. const props = defineProps({
  41. mode: {
  42. type: String,
  43. default: 'goods',
  44. },
  45. show: {
  46. type: Boolean,
  47. default: false,
  48. },
  49. });
  50. watch(
  51. () => props.mode,
  52. () => {
  53. state.pagination.data = [];
  54. if (props.mode) {
  55. getList(state.pagination.page);
  56. }
  57. },
  58. );
  59. const state = reactive({
  60. loadStatus: '',
  61. pagination: {
  62. data: [],
  63. current_page: 1,
  64. total: 1,
  65. last_page: 1,
  66. },
  67. });
  68. async function getList(page, list_rows = 5) {
  69. state.loadStatus = 'loading';
  70. const res =
  71. props.mode == 'goods'
  72. ? await SpuHistoryApi.getBrowseHistoryPage({
  73. page,
  74. list_rows,
  75. })
  76. : await OrderApi.getOrderPage({
  77. page,
  78. list_rows,
  79. });
  80. let orderList = _.concat(state.pagination.data, res.data.list);
  81. state.pagination = {
  82. ...res.data,
  83. data: orderList,
  84. };
  85. if (state.pagination.current_page < state.pagination.last_page) {
  86. state.loadStatus = 'more';
  87. } else {
  88. state.loadStatus = 'noMore';
  89. }
  90. }
  91. function loadmore() {
  92. if (state.loadStatus !== 'noMore') {
  93. getList(state.pagination.current_page + 1);
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .select-popup {
  99. max-height: 600rpx;
  100. .title {
  101. height: 100rpx;
  102. line-height: 100rpx;
  103. padding: 0 26rpx;
  104. background: #fff;
  105. border-radius: 20rpx 20rpx 0 0;
  106. span {
  107. font-size: 32rpx;
  108. position: relative;
  109. &::after {
  110. content: '';
  111. display: block;
  112. width: 100%;
  113. height: 2px;
  114. z-index: 1;
  115. position: absolute;
  116. left: 0;
  117. bottom: -15px;
  118. background: var(--ui-BG-Main);
  119. pointer-events: none;
  120. }
  121. }
  122. }
  123. .scroll-box {
  124. height: 500rpx;
  125. }
  126. .item {
  127. background: #fff;
  128. margin: 26rpx 26rpx 0;
  129. border-radius: 20rpx;
  130. :deep() {
  131. .image {
  132. width: 140rpx;
  133. height: 140rpx;
  134. }
  135. }
  136. }
  137. }
  138. </style>