|
|
- <template>
- <view class="exchange-record">
- <!-- 自定义tabs -->
- <view class="custom-tabs">
- <view
- v-for="(tab, index) in tabList"
- :key="index"
- class="tab-item"
- @click="tabChange(index)"
- >
- <text class="tab-text" :class="{ active: currentTab === index }">{{ tab.name }}</text>
- <view v-if="currentTab === index" class="tab-line"></view>
- </view>
- </view>
-
- <!-- 兑换记录列表 -->
- <view class="record-list">
- <view
- v-for="(item, index) in currentRecordList"
- :key="index"
- class="record-item"
- @click="handleItemClick(item)"
- >
- <image class="record-image" :src="item.image" mode="aspectFit"></image>
- <view class="record-content">
- <view class="record-info">
- <view class="title-row">
- <text class="record-title">{{ item.title }}</text>
- </view>
- <view class="record-points">
- <uv-icon name="integral" size="16" color="#218cdd"></uv-icon>
- <text class="points-text">{{ item.price }}积分</text>
- </view>
- <view class="record-time">
- <uv-icon name="clock" size="14" color="#999"></uv-icon>
- <text class="time-text">兑换时间:{{ item.createTime }}</text>
- </view>
- </view>
- <view class="record-action">
- <uv-button
- v-if="currentTab === 0"
- type="primary"
- size="small"
- text="确认领取"
- shape="circle"
- @click.stop="viewDetail(item)"
- ></uv-button>
- <uv-button
- v-else-if="currentTab === 1"
- type="success"
- size="small"
- text="查看详情"
- shape="circle"
- @click.stop="viewDetail(item)"
- ></uv-button>
- <uv-button
- v-else
- type="error"
- size="small"
- text="已取消"
- shape="circle"
- disabled
- ></uv-button>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
-
- <script>
- export default {
- data() {
- return {
- currentTab: 0,
- pageNo: 1,
- pageSize: 10,
- tabList: [
- { name: '待领取' },
- { name: '已领取' },
- { name: '系统取消' }
- ],
- // 待领取记录列表
- pendingList: [
- ],
- // 已领取记录列表
- receivedList: [
-
- ],
- // 系统取消记录列表
- cancelledList: [
-
- ]
- }
- },
- computed: {
- currentRecordList() {
- if (this.currentTab === 0) {
- return this.pendingList
- } else if (this.currentTab === 1) {
- return this.receivedList
- } else {
- return this.cancelledList
- }
- }
- },
- methods: {
- tabChange(index) {
- this.currentTab = index
- this.initData()
- this.getOrderList()
- },
-
- handleItemClick(item) {
- if (this.currentTab === 0) {
- this.viewDetail(item)
-
- } else if (this.currentTab === 1) {
- this.viewDetail(item)
- } else if (this.currentTab === 2) {
- this.viewDetail(item)
- }
- },
- confirmReceive(item) {
- // 确认领取逻辑
- uni.showModal({
- title: '确认领取',
- content: '确认已领取该商品?',
- success: (res) => {
- if (res.confirm) {
- // 移动到已领取列表
- const index = this.pendingList.findIndex(record => record.id === item.id)
- if (index !== -1) {
- const record = this.pendingList.splice(index, 1)[0]
- this.receivedList.unshift(record)
- }
- uni.showToast({
- title: '领取成功',
- icon: 'success'
- })
- }
- }
- })
- },
- viewDetail(item) {
- // 查看详情逻辑 - 跳转到兑换详情页面
- let status = 'pending'
- if (this.currentTab === 1) {
- status = 'received'
- } else if (this.currentTab === 2) {
- status = 'cancelled'
- }
-
- uni.navigateTo({
- url: `/subPages/my/exchangeDetail?id=${item.goodsId}&status=${status}`
- })
- },
-
- // 清空列表数据
- initData() {
- this.pageNo = 1
- this.pendingList = []
- this.receivedList = []
- this.cancelledList = []
- },
- // 获取列表
- async getOrderList() {
- const res = await this.$api.user.queryOrderList({
- pageNo: this.pageNo,
- pageSize: this.pageSize,
- status: this.currentTab
- })
-
- if (res.result.records.length){
- if (this.currentTab === 0) {
- this.pendingList.push(...res.result.records)
- } else if (this.currentTab === 1) {
- this.receivedList.push(...res.result.records)
- } else {
- this.cancelledList.push(...res.result.records)
- }
- this.pageNo++
- }else {
- uni.showToast({
- title: '暂无数据',
- icon: 'none'
- })
- }
- }
- },
- async onReachBottom() {
- await this.getOrderList()
- },
- async onPullDownRefresh() {
- this.initData()
- await this.getOrderList()
- uni.stopPullDownRefresh()
- },
- async onShow() {
- this.initData()
- await this.getOrderList()
- }
- }
- </script>
-
- <style lang="scss" scoped>
- .exchange-record {
- background-color: #f5f5f5;
- min-height: 100vh;
-
- .custom-tabs {
- display: flex;
- background-color: #fff;
- border-bottom: 1rpx solid #e5e5e5;
-
- .tab-item {
- flex: 1;
- position: relative;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 30rpx 0;
- cursor: pointer;
-
- .tab-text {
- font-size: 28rpx;
- color: #666;
- transition: color 0.3s;
-
- &.active {
- color: #218cdd;
- font-weight: bold;
- }
- }
-
- .tab-line {
- position: absolute;
- bottom: 0;
- left: 50%;
- transform: translateX(-50%);
- width: 60rpx;
- height: 4rpx;
- background-color: #218cdd;
- border-radius: 2rpx;
- }
- }
- }
-
- .record-list {
- padding: 20rpx;
-
- .record-item {
- display: flex;
- align-items: flex-start;
- margin-bottom: 30rpx;
- background: #fff;
- border-radius: 12rpx;
- padding: 20rpx;
-
- .record-image {
- width: 215rpx;
- height: 215rpx;
- border-radius: 8rpx;
- margin-right: 20rpx;
- flex-shrink: 0;
- }
-
- .record-content {
- flex: 1;
- display: flex;
- flex-direction: column;
-
- .record-info {
- display: flex;
- flex-direction: column;
- margin-bottom: 20rpx;
-
- .title-row {
- margin-bottom: 10rpx;
- }
-
- .record-title {
- font-size: 22rpx;
- // font-weight: bold;
- color: #000;
- line-height: 1.4;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- overflow: hidden;
- }
-
- .record-points {
- display: flex;
- align-items: center;
- margin-bottom: 8rpx;
-
- .points-text {
- font-size: 26rpx;
- color: #218cdd;
- font-weight: bold;
- margin-left: 6rpx;
- }
- }
-
- .record-time {
- display: flex;
- align-items: center;
-
- .time-text {
- font-size: 22rpx;
- color: #999;
- margin-left: 6rpx;
- }
- }
- }
-
- .record-action {
- display: flex;
- justify-content: flex-end;
- // padding-top: 10rpx;
- border-top: 1rpx solid #f0f0f0;
-
- }
- }
- }
- }
- }
- </style>
|