123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <template>
- <view class="favorites-page">
-
- <!-- 列表 -->
- <view class="fav-list">
- <view class="fav-card" v-for="(item, idx) in list" :key="idx">
- <image @click="goPage('/pages/crowdFunding/crowdfundingDetails?id='+ item.id)" :src="item.main_image" class="fav-img"></image>
- <view class="fav-content">
- <view class="fav-header">
- <image :src="item.creator_avatar" class="avatar"></image>
- <text class="nickname" @click="goPage('/pages/crowdFunding/crowdfundingDetails?id='+ item.id)">{{ item.creator_username }}</text>
- <text class="tag" @click="goPage('/pages/crowdFunding/crowdfundingDetails?id='+ item.id)">发起人</text>
- <view style="position: relative;left: 0;top: 0;">
- <image src="/static/crowdFunding/more.png" class="more-img" @click="toggleDropdown(idx)"></image>
- <view class="dropdown-menu" v-if="currentDropdownIndex === idx">
- <view class="dropdown-item" @tap="handleOption('cancelCollection', idx)">取消收藏</view>
- </view>
- </view>
- </view>
- <view class="fav-title two-omit" @click="goPage('/pages/crowdFunding/crowdfundingDetails?id='+ item.id)">{{ item.title }}</view>
- <view class="fav-bottom">
- <text class="amount">已筹 ¥{{ item.current_amount }}</text>
- <!-- <text class="favorite-time">收藏于{{ item.favorite_time }}</text> -->
- </view>
- </view>
- </view>
- </view>
- <view v-if="!isLoading && list.length === 0" class="no-data">
- <text>暂无数据</text>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- list: [],
- page: 1,
- pageSize: 20,
- total: 0,
- isLoading: false,
- hasMore: true,
- currentDropdownIndex: null,
- show1: false,
- };
- },
- onLoad() {
- this.page = 1;
- this.list = [];
- this.hasMore = true;
- this.getList();
- },
- onPullDownRefresh() {
- this.page = 1;
- this.list = [];
- this.hasMore = true;
- this.getList(() => uni.stopPullDownRefresh());
- },
- onReachBottom() {
- if (this.hasMore && !this.isLoading) {
- this.getList();
- }
- },
- methods: {
- getList(cb) {
- if (this.isLoading) return;
- this.isLoading = true;
- uni.request({
- url: this.$apiHost + '/crowdfund/favorites',
- method: 'GET',
- data: {
- page: this.page,
- pageSize: this.pageSize,
- uuid: getApp().globalData.uuid,
- skey: getApp().globalData.skey,
- },
- success: (res) => {
- if (res.data && res.data.success === 'yes' && res.data.data) {
- var { list, total } = res.data.data;
- if (!Array.isArray(list)) {
- list = [];
- }
- if (this.page === 1) {
- this.list = list;
- } else {
- this.list = [...this.list, ...list];
- }
- this.total = total;
- this.hasMore = this.list && this.list.length < total;
- if (this.hasMore) this.page++;
- }
- },
- complete: () => {
- this.isLoading = false;
- cb && cb();
- }
- });
- },
- goBack() {
- uni.navigateBack();
- },
- toggleDropdown(idx) {
- this.currentDropdownIndex = this.currentDropdownIndex === idx ? null : idx;
- },
- goPage(url) {
- console.log(url,888);
-
- uni.navigateTo({
- url,
- });
- },
- // 处理下拉菜单选项点击
- handleOption(type, idx) {
- this.currentDropdownIndex = null;
- if (type === "cancelCollection") {
- const item = this.list[idx];
- uni.request({
- url: this.$apiHost + '/crowdfund/favorite',
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded',
- },
- data: {
- crowdfund_id: item.id,
- action: 'remove',
- uuid: getApp().globalData.uuid,
- skey: getApp().globalData.skey,
- },
- success: (res) => {
- if (res.data && res.data.success && res.data.success === 'yes') {
- this.list.splice(idx, 1);
- uni.showToast({
- title: '取消收藏成功',
- icon: 'none',
- duration: 2000
- });
- this.show1 = !this.show1;
- } else {
- uni.showToast({
- title: res.data.msg || '取消失败',
- icon: 'none',
- duration: 2000
- });
- }
- },
- fail: () => {
- uni.showToast({
- title: '网络错误',
- icon: 'none',
- duration: 2000
- });
- }
- });
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .favorites-page {
- min-height: 100vh;
- background: #f2f6f2;
- .fav-list {
- padding: 24rpx 0;
- .fav-card {
- display: flex;
- background: #fff;
- border-radius: 18rpx;
- margin: 0 24rpx 24rpx 24rpx;
- box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
- padding: 20rpx;
- .fav-img {
- width: 140rpx;
- height: 140rpx;
- border-radius: 12rpx;
- object-fit: cover;
- flex-shrink: 0;
- }
- .fav-content {
- flex: 1;
- margin-left: 20rpx;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- .fav-header {
- display: flex;
- align-items: center;
- .avatar {
- width: 44rpx;
- height: 44rpx;
- border-radius: 50%;
- margin-right: 12rpx;
- }
- .nickname {
- font-weight: 400;
- font-size: 24rpx;
- color: #1f1f1f;
- font-family: "PingFang SC-Bold";
- max-width: 250rpx;
- margin-right: 12rpx;
- }
- .tag {
- font-size: 20rpx;
- color: #acf934;
- background: #1f1f1f;
- border-radius: 8rpx;
- padding: 2rpx 12rpx;
- margin-right: auto;
- margin-left: 4rpx;
- }
- .more-img {
- width: 36rpx;
- height: 36rpx;
- margin-left: 12rpx;
- }
- }
- .fav-title {
- font-size: 26rpx;
- color: #222;
- font-weight: 500;
- margin: 10rpx 0 0 0;
- overflow: hidden;
- text-overflow: ellipsis;
- width: 100%;
- }
- .fav-bottom {
- margin-top: 10rpx;
- display: flex;
- justify-content: flex-end;
- align-items: center;
- .amount {
- font-size: 22rpx;
- color: #bdbdbd;
- }
- .favorite-time {
- font-size: 22rpx;
- color: #bdbdbd;
- margin-left: 10rpx;
- }
- }
- }
- }
- }
- .dropdown-menu {
- position: absolute;
- top: calc(100% + 10rpx);
- right: 20rpx;
- background-color: #ffffff;
- border-radius: 20rpx;
- padding: 0;
- width: 150rpx;
- box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
- z-index: 100;
- transform-origin: top right;
- animation: dropdownAnimation 0.2s ease-out;
- overflow: hidden;
- .dropdown-item {
- padding: 15rpx 0;
- color: #333333;
- font-size: 24rpx;
- position: relative;
- text-align: center;
- &:not(:last-child)::after {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1rpx;
- background-color: #eeeeee;
- }
- &:active {
- background-color: #f8f8f8;
- }
- }
- }
- @keyframes dropdownAnimation {
- 0% {
- opacity: 0;
- transform: scale(0.95) translateY(-5rpx);
- }
- 100% {
- opacity: 1;
- transform: scale(1) translateY(0);
- }
- }
- .no-data {
- text-align: center;
- color: #bbb;
- font-size: 28rpx;
- padding: 80rpx 0 40rpx 0;
- }
- }
- </style>
|