select-popup.vue 3.1 KB

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