favorites.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="favorites-page">
  3. <!-- 列表 -->
  4. <view class="fav-list">
  5. <view
  6. class="fav-card"
  7. v-for="(item, idx) in list"
  8. :key="idx"
  9. >
  10. <image
  11. :src="item.main_image"
  12. class="fav-img"
  13. ></image>
  14. <view class="fav-content">
  15. <view class="fav-header">
  16. <image
  17. :src="item.creator_avatar"
  18. class="avatar"
  19. ></image>
  20. <text class="nickname">{{ item.creator_username }}</text>
  21. <text class="tag">发起人</text>
  22. <view style="position: relative;left: 0;top: 0;">
  23. <image
  24. src="/static/crowdFunding/more.png"
  25. class="more-img"
  26. @click="toggleDropdown(idx)"
  27. ></image>
  28. <view
  29. class="dropdown-menu"
  30. v-if="currentDropdownIndex === idx"
  31. >
  32. <view
  33. class="dropdown-item"
  34. @tap="handleOption('cancelCollection', idx)"
  35. >取消收藏</view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="fav-title two-omit">{{ item.title }}</view>
  40. <view class="fav-bottom">
  41. <text class="amount">已筹 ¥{{ item.current_amount }}</text>
  42. <!-- <text class="favorite-time">收藏于{{ item.favorite_time }}</text> -->
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view v-if="!isLoading && list.length === 0" class="no-data">
  48. <text>暂无数据</text>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. list: [],
  57. page: 1,
  58. pageSize: 20,
  59. total: 0,
  60. isLoading: false,
  61. hasMore: true,
  62. currentDropdownIndex: null,
  63. };
  64. },
  65. onLoad() {
  66. this.page = 1;
  67. this.list = [];
  68. this.hasMore = true;
  69. this.getList();
  70. },
  71. onPullDownRefresh() {
  72. this.page = 1;
  73. this.list = [];
  74. this.hasMore = true;
  75. this.getList(() => uni.stopPullDownRefresh());
  76. },
  77. onReachBottom() {
  78. if (this.hasMore && !this.isLoading) {
  79. this.getList();
  80. }
  81. },
  82. methods: {
  83. getList(cb) {
  84. if (this.isLoading) return;
  85. this.isLoading = true;
  86. uni.request({
  87. url: this.$apiHost + '/crowdfund/favorites',
  88. method: 'GET',
  89. data: {
  90. page: this.page,
  91. pageSize: this.pageSize,
  92. uuid: getApp().globalData.uuid,
  93. skey: getApp().globalData.skey,
  94. },
  95. success: (res) => {
  96. if (res.data && res.data.success === 'yes' && res.data.data) {
  97. var { list, total } = res.data.data;
  98. if(!Array.isArray(list)) {
  99. list = [];
  100. }
  101. if (this.page === 1) {
  102. this.list = list;
  103. } else {
  104. this.list = [...this.list, ...list];
  105. }
  106. this.total = total;
  107. this.hasMore =this.list&&this.list.length < total;
  108. if (this.hasMore) this.page++;
  109. }
  110. },
  111. complete: () => {
  112. this.isLoading = false;
  113. cb && cb();
  114. }
  115. });
  116. },
  117. goBack() {
  118. uni.navigateBack();
  119. },
  120. toggleDropdown(idx) {
  121. this.currentDropdownIndex = this.currentDropdownIndex === idx ? null : idx;
  122. },
  123. // 处理下拉菜单选项点击
  124. handleOption(type, idx) {
  125. this.currentDropdownIndex = null;
  126. if (type === "cancelCollection") {
  127. const item = this.list[idx];
  128. uni.request({
  129. url: this.$apiHost + '/crowdfund/favorite',
  130. method: 'POST',
  131. header: {
  132. 'content-type': 'application/x-www-form-urlencoded',
  133. },
  134. data: {
  135. crowdfund_id: item.id,
  136. action: 'remove',
  137. uuid: getApp().globalData.uuid,
  138. skey: getApp().globalData.skey,
  139. },
  140. success: (res) => {
  141. if (res.data && res.data.success && res.data.success === 'yes') {
  142. this.list.splice(idx, 1);
  143. uni.showToast({
  144. title: '取消收藏成功',
  145. icon: 'none',
  146. duration: 2000
  147. });
  148. } else {
  149. uni.showToast({
  150. title: res.data.msg || '取消失败',
  151. icon: 'none',
  152. duration: 2000
  153. });
  154. }
  155. },
  156. fail: () => {
  157. uni.showToast({
  158. title: '网络错误',
  159. icon: 'none',
  160. duration: 2000
  161. });
  162. }
  163. });
  164. }
  165. },
  166. },
  167. };
  168. </script>
  169. <style lang="scss" scoped>
  170. .favorites-page {
  171. min-height: 100vh;
  172. background: #f2f6f2;
  173. .fav-list {
  174. padding: 24rpx 0;
  175. .fav-card {
  176. display: flex;
  177. background: #fff;
  178. border-radius: 18rpx;
  179. margin: 0 24rpx 24rpx 24rpx;
  180. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  181. padding: 20rpx;
  182. .fav-img {
  183. width: 140rpx;
  184. height: 140rpx;
  185. border-radius: 12rpx;
  186. object-fit: cover;
  187. flex-shrink: 0;
  188. }
  189. .fav-content {
  190. flex: 1;
  191. margin-left: 20rpx;
  192. display: flex;
  193. flex-direction: column;
  194. justify-content: space-between;
  195. .fav-header {
  196. display: flex;
  197. align-items: center;
  198. .avatar {
  199. width: 44rpx;
  200. height: 44rpx;
  201. border-radius: 50%;
  202. margin-right: 12rpx;
  203. }
  204. .nickname {
  205. font-weight: 400;
  206. font-size: 24rpx;
  207. color: #1f1f1f;
  208. font-family: "PingFang SC-Bold";
  209. max-width: 250rpx;
  210. margin-right: 12rpx;
  211. }
  212. .tag {
  213. font-size: 20rpx;
  214. color: #acf934;
  215. background: #1f1f1f;
  216. border-radius: 8rpx;
  217. padding: 2rpx 12rpx;
  218. margin-right: auto;
  219. margin-left: 4rpx;
  220. }
  221. .more-img {
  222. width: 36rpx;
  223. height: 36rpx;
  224. margin-left: 12rpx;
  225. }
  226. }
  227. .fav-title {
  228. font-size: 26rpx;
  229. color: #222;
  230. font-weight: 500;
  231. margin: 10rpx 0 0 0;
  232. overflow: hidden;
  233. text-overflow: ellipsis;
  234. width: 100%;
  235. }
  236. .fav-bottom {
  237. margin-top: 10rpx;
  238. display: flex;
  239. justify-content: flex-end;
  240. align-items: center;
  241. .amount {
  242. font-size: 22rpx;
  243. color: #bdbdbd;
  244. }
  245. .favorite-time {
  246. font-size: 22rpx;
  247. color: #bdbdbd;
  248. margin-left: 10rpx;
  249. }
  250. }
  251. }
  252. }
  253. }
  254. .dropdown-menu {
  255. position: absolute;
  256. top: calc(100% + 10rpx);
  257. right: 20rpx;
  258. background-color: #ffffff;
  259. border-radius: 20rpx;
  260. padding: 0;
  261. width: 150rpx;
  262. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  263. z-index: 100;
  264. transform-origin: top right;
  265. animation: dropdownAnimation 0.2s ease-out;
  266. overflow: hidden;
  267. .dropdown-item {
  268. padding: 15rpx 0;
  269. color: #333333;
  270. font-size: 24rpx;
  271. position: relative;
  272. text-align: center;
  273. &:not(:last-child)::after {
  274. content: "";
  275. position: absolute;
  276. left: 0;
  277. right: 0;
  278. bottom: 0;
  279. height: 1rpx;
  280. background-color: #eeeeee;
  281. }
  282. &:active {
  283. background-color: #f8f8f8;
  284. }
  285. }
  286. }
  287. @keyframes dropdownAnimation {
  288. 0% {
  289. opacity: 0;
  290. transform: scale(0.95) translateY(-5rpx);
  291. }
  292. 100% {
  293. opacity: 1;
  294. transform: scale(1) translateY(0);
  295. }
  296. }
  297. .no-data {
  298. text-align: center;
  299. color: #bbb;
  300. font-size: 28rpx;
  301. padding: 80rpx 0 40rpx 0;
  302. }
  303. }
  304. </style>