index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <script lang="ts" setup>
  2. import { computed, ref } from 'vue'
  3. import { getHomeCouponRedemptionList } from '@/api/home'
  4. import { useScroll } from '@/hooks/useScroll'
  5. import { changtime, safeAreaInsets } from '@/utils'
  6. definePage({
  7. style: {
  8. navigationBarTitleText: '',
  9. navigationStyle: 'custom',
  10. },
  11. })
  12. const topSafeAreaHeight = safeAreaInsets?.top || 0
  13. const currentState = ref('1')
  14. const currentCouponType = ref('3')
  15. const currentDate = ref(Date.now())
  16. const show = ref(false)
  17. const datetimePickerRef = ref(null)
  18. const {
  19. list: data, // 响应式的数据列表
  20. loading, // 是否加载中
  21. finished, // 是否已全部加载
  22. error, // 是否加载失败
  23. refresh: onRefresh, // 下拉刷新方法
  24. loadMore: onLoadMore, // 加载更多方法
  25. } = useScroll({
  26. fetchData: async (page, pageSize) => {
  27. const response = await getHomeCouponRedemptionList({
  28. pageNo: page,
  29. pageSize,
  30. verificationStatus: currentState.value,
  31. couponType: currentCouponType.value,
  32. year: changtime(currentDate.value, 'YYYY'),
  33. month: changtime(currentDate.value, 'MM'),
  34. })
  35. return response.records || []
  36. },
  37. pageSize: 7,
  38. })
  39. // 计算底部安全区高度
  40. const safeBottomHeight = computed(() => {
  41. return safeAreaInsets?.bottom || 0
  42. })
  43. // 格式化日期显示:YYYY年MM月
  44. const formattedDate = computed(() => {
  45. return changtime(currentDate.value, 'YYYY年MM月')
  46. })
  47. // 计算加载状态
  48. const status = computed(() => {
  49. if (loading.value) {
  50. return 'loading'
  51. }
  52. if (finished.value) {
  53. return 'nomore'
  54. }
  55. if (error.value) {
  56. return 'error'
  57. }
  58. return 'loadmore'
  59. })
  60. onLoad((options) => {
  61. if (options.state) {
  62. currentState.value = options.state
  63. }
  64. })
  65. function redemptionChange(state) {
  66. currentState.value = state
  67. onRefresh()
  68. }
  69. function couponTypeChange(type) {
  70. currentCouponType.value = type
  71. onRefresh()
  72. }
  73. function datePickerConfirm() {
  74. show.value = false
  75. onRefresh()
  76. }
  77. </script>
  78. <template>
  79. <view class="page-container">
  80. <up-navbar title="优惠券" :auto-back="true" />
  81. <up-status-bar />
  82. <view class="redemption-type" :style="{ paddingTop: `${topSafeAreaHeight}px` }">
  83. <view class="redemption-type-item" :class="{ active: currentState === '1' }" @click="redemptionChange('1')">
  84. 待核销
  85. </view>
  86. <up-line direction="col" color="#9A9B9B" length="40rpx" />
  87. <view class="redemption-type-item" :class="{ active: currentState === '2' }" @click="redemptionChange('2')">
  88. 已核销
  89. </view>
  90. </view>
  91. <view class="redemption-select">
  92. <view class="redemption-select-item coupon-type">
  93. <view class="coupon-type-item" :class="{ 'coupon-active': currentCouponType === '3' }"
  94. @click="couponTypeChange('3')">
  95. 满减券
  96. </view>
  97. <view class="coupon-type-item" :class="{ 'coupon-active': currentCouponType === '2' }"
  98. @click="couponTypeChange('2')">
  99. 折扣券
  100. </view>
  101. </view>
  102. <view class="redemption-select-item">
  103. <up-datetime-picker ref="datetimePickerRef" v-model="currentDate" :show="show" mode="year-month"
  104. @cancel="show = false" @confirm="datePickerConfirm" />
  105. <view class="date-display" @click="show = true">
  106. {{ formattedDate }}
  107. <up-icon name="arrow-down" />
  108. </view>
  109. </view>
  110. </view>
  111. <view class="redemption-content">
  112. <scroll-view scroll-y :refresher-enabled="true" :refresher-triggered="loading" @refresherrefresh="onRefresh"
  113. @scrolltolower="onLoadMore">
  114. <template v-for="(item, index) in data" :key="index">
  115. <view class="redemption-content-card">
  116. <template v-if="currentState === '1'">
  117. <view class="redemption-content-item">
  118. <view class="redemption-content-item-left">
  119. 优惠券名称
  120. </view>
  121. <view class="redemption-content-item-header-right">
  122. {{ item?.couponName || '' }}
  123. </view>
  124. </view>
  125. <view class="redemption-content-item">
  126. <view class="redemption-content-item-left">
  127. 用户名称
  128. </view>
  129. <view class="redemption-content-item-header-right">
  130. {{ item?.receiveUserName || '' }}
  131. </view>
  132. </view>
  133. <view class="redemption-content-item">
  134. <view class="redemption-content-item-left">
  135. 到期时间
  136. </view>
  137. <view class="redemption-content-item-right">
  138. {{ item?.expireTime || '--' }}
  139. </view>
  140. </view>
  141. </template>
  142. <template v-if="currentState === '2'">
  143. <view class="redemption-content-item">
  144. <view class="redemption-content-item-left">
  145. 核销时间
  146. </view>
  147. <view class="redemption-content-item-header-right">
  148. {{ item?.verificationTime || '--' }}
  149. </view>
  150. </view>
  151. <view class="redemption-content-item">
  152. <view class="redemption-content-item-left">
  153. 优惠券名称
  154. </view>
  155. <view class="redemption-content-item-header-right">
  156. {{ item?.couponName || '' }}
  157. </view>
  158. </view>
  159. <view class="redemption-content-item">
  160. <view class="redemption-content-item-left">
  161. 核销用户
  162. </view>
  163. <view class="redemption-content-item-header-right">
  164. {{ item?.receiveUserName || '' }}
  165. </view>
  166. </view>
  167. <view class="redemption-content-item">
  168. <view class="redemption-content-item-left">
  169. 商品名称
  170. </view>
  171. <view class="redemption-content-item-right">
  172. {{ item?.orderItemName || '' }}
  173. </view>
  174. </view>
  175. <view class="redemption-content-item">
  176. <view class="redemption-content-item-left">
  177. 实付金额
  178. </view>
  179. <view class="redemption-content-item-right">
  180. {{ item?.orderAmount || '' }}
  181. </view>
  182. </view>
  183. <view class="redemption-content-item">
  184. <view class="redemption-content-item-left">
  185. 预计获得佣金
  186. </view>
  187. <view class="redemption-content-item-right">
  188. {{ item?.commission || '' }}
  189. </view>
  190. </view>
  191. </template>
  192. </view>
  193. </template>
  194. <template v-if="!data || data.length === 0">
  195. <up-empty mode="data" style="height: 100%" />
  196. </template>
  197. <!-- 加载状态提示 -->
  198. <template v-else>
  199. <up-loadmore :status="status" />
  200. </template>
  201. </scroll-view>
  202. </view>
  203. <view class="safe-bottom" :style="{ height: `${safeBottomHeight}px` }" />
  204. </view>
  205. </template>
  206. <style lang="scss" scoped>
  207. .page-container {
  208. height: 100vh;
  209. background-color: #f8f8fa;
  210. display: flex;
  211. flex-direction: column; // 设置为flex布局,让子元素垂直排列
  212. .redemption-type {
  213. width: 100%;
  214. height: 88rpx;
  215. display: flex;
  216. flex-direction: row;
  217. justify-content: center;
  218. align-items: center;
  219. background-color: #ffffff;
  220. position: relative;
  221. }
  222. .redemption-type-item {
  223. flex: 1;
  224. text-align: center;
  225. font-weight: 400;
  226. font-size: 30rpx;
  227. color: #888888;
  228. line-height: 33rpx;
  229. transition: color 0.3s ease; // 添加颜色过渡动画
  230. position: relative;
  231. z-index: 1; // 确保文字在指示器上方
  232. padding: 20rpx 0; // 增加点击区域
  233. &.active {
  234. color: #333333;
  235. font-weight: bolder;
  236. }
  237. }
  238. .indicator {
  239. position: absolute;
  240. bottom: 0;
  241. width: 30%;
  242. height: 4rpx;
  243. background-color: #333333;
  244. transition: left 0.3s ease; // 添加左右移动的过渡动画
  245. transform: translateX(-50%); // 居中对齐
  246. }
  247. .redemption-select {
  248. height: 90rpx;
  249. display: flex;
  250. flex-direction: row;
  251. justify-content: space-between;
  252. align-items: center;
  253. padding: 0 20rpx;
  254. .coupon-type {
  255. display: flex;
  256. flex-direction: row;
  257. flex-wrap: nowrap;
  258. justify-content: center;
  259. align-items: center;
  260. gap: 19rpx;
  261. .coupon-type-item {
  262. width: 118rpx;
  263. height: 45rpx;
  264. padding: 11rpx 21rpx 10rpx 21rpx;
  265. text-align: center;
  266. background: #ffffff;
  267. border-radius: 35rpx;
  268. border: 1px solid #e5e5e5;
  269. &.coupon-active {
  270. font-weight: 400;
  271. color: #ffffff;
  272. background: linear-gradient(180deg, #ff7a72 0%, #ff3500 100%);
  273. }
  274. }
  275. }
  276. .redemption-select-item {
  277. .date-display {
  278. display: flex;
  279. flex-direction: row;
  280. flex-wrap: nowrap;
  281. gap: 13rpx;
  282. }
  283. }
  284. }
  285. .redemption-content {
  286. flex: 1; // 占据剩余空间
  287. padding: 9px 20rpx;
  288. overflow: hidden; // 隐藏超出部分
  289. scroll-view {
  290. height: 100%; // 充满整个容器
  291. }
  292. .redemption-content-card {
  293. background-color: #ffffff;
  294. border-radius: 10rpx;
  295. padding: 39rpx 20rpx;
  296. display: flex;
  297. flex-direction: column;
  298. flex-wrap: nowrap;
  299. justify-content: space-around;
  300. gap: 40rpx;
  301. .redemption-content-item {
  302. display: flex;
  303. flex-direction: row;
  304. flex-wrap: nowrap;
  305. justify-content: space-between;
  306. .redemption-content-item-left {
  307. font-weight: 400;
  308. font-size: 26rpx;
  309. color: #666666;
  310. }
  311. .redemption-content-item-right {
  312. font-weight: 400;
  313. font-size: 26rpx;
  314. color: #333333;
  315. }
  316. }
  317. }
  318. }
  319. }
  320. </style>