select-popup.vue 2.9 KB

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