task.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <u-popup :show="showTask" @close="handleClose" @open="handleOpen" round="32rpx" bgColor="#ffffff" zIndex="10077">
  3. <view class="content">
  4. <!-- 头部 -->
  5. <view class="header">
  6. <view class="row bg">
  7. <image class="w40 h40" src="/static/images/answer_icon.png"></image>
  8. <image class="w428 h64" src="/static/images/collecting_coins_title.png"></image>
  9. <image class="w40 h40" src="/static/images/pop_close_icon.png" @click="showTask=false"></image>
  10. </view>
  11. <!-- 积分信息 -->
  12. <view class="row mtb48 plr24">
  13. <view class="points row">
  14. <text class="lable">我的积分</text>
  15. <text class="num">3688</text>
  16. </view>
  17. <view class="shop row">
  18. <image class="w48 h48" src="/static/images/fanghua_coin_icon.png"></image>
  19. <text class="shop-txt">芳华币商城</text>
  20. <image class="w24 h24" src="/static/images/coin_arrow.png"></image>
  21. </view>
  22. </view>
  23. </view>
  24. <!-- 可滚动列表区域 -->
  25. <scroll-view scroll-y class="list" :style="{ height: scrollHeight + 'px' }" @scroll="handleScroll">
  26. <!-- 列表项 - 这里应该用 v-for 循环,简化代码 -->
  27. <view v-for="(item, index) in taskList" :key="index" class="list-item">
  28. <view class="row">
  29. <view class="left">
  30. <image class="w88 h88 mr24" src="/static/images/img.png"></image>
  31. <view>
  32. <view class="mb8 row">
  33. <text class="title">{{ item.title }}({{ item.current }}/{{ item.total }})</text>
  34. <image class="w40 h40 mr4 ml8" src="/static/images/fanghua_coin_icon.png"></image>
  35. <text class="num">+{{ item.points }}</text>
  36. </view>
  37. <view class="txt">{{ item.desc }}</view>
  38. </view>
  39. </view>
  40. <view class="button" @click="handleTaskClick(item)">
  41. {{ item.buttonText }}
  42. </view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. </u-popup>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. showTask: true,
  54. scrollHeight: 400, // 根据实际情况调整
  55. taskList: [{
  56. title: '点赞内容',
  57. current: 0,
  58. total: 1,
  59. points: 1,
  60. desc: '最多1条得芳华币',
  61. buttonText: '去完成'
  62. }, {
  63. title: '点赞内容',
  64. current: 0,
  65. total: 1,
  66. points: 1,
  67. desc: '最多1条得芳华币',
  68. buttonText: '去完成'
  69. }, {
  70. title: '点赞内容',
  71. current: 0,
  72. total: 1,
  73. points: 1,
  74. desc: '最多1条得芳华币',
  75. buttonText: '去完成'
  76. }, {
  77. title: '点赞内容',
  78. current: 0,
  79. total: 1,
  80. points: 1,
  81. desc: '最多1条得芳华币',
  82. buttonText: '去完成'
  83. }, {
  84. title: '点赞内容',
  85. current: 0,
  86. total: 1,
  87. points: 1,
  88. desc: '最多1条得芳华币',
  89. buttonText: '去完成'
  90. }, {
  91. title: '点赞内容',
  92. current: 0,
  93. total: 1,
  94. points: 1,
  95. desc: '最多1条得芳华币',
  96. buttonText: '去完成'
  97. }, {
  98. title: '点赞内容',
  99. current: 0,
  100. total: 1,
  101. points: 1,
  102. desc: '最多1条得芳华币',
  103. buttonText: '去完成'
  104. }, {
  105. title: '点赞内容',
  106. current: 0,
  107. total: 1,
  108. points: 1,
  109. desc: '最多1条得芳华币',
  110. buttonText: '去完成'
  111. }, {
  112. title: '点赞内容',
  113. current: 0,
  114. total: 1,
  115. points: 1,
  116. desc: '最多1条得芳华币',
  117. buttonText: '去完成'
  118. }, {
  119. title: '点赞内容',
  120. current: 0,
  121. total: 1,
  122. points: 1,
  123. desc: '最多1条得芳华币',
  124. buttonText: '去完成'
  125. },
  126. ]
  127. }
  128. },
  129. mounted() {
  130. this.calcScrollHeight();
  131. },
  132. methods: {
  133. handleScroll(event) {
  134. // 更新当前滚动位置
  135. this.scrollTop = event.detail.scrollTop;
  136. // 判断是否显示返回顶部按钮
  137. this.showBackTop = this.scrollTop > 300;
  138. // 判断是否滚动到底部(需要加载更多)
  139. if (!this.loadingMore && this.hasMore) {
  140. const {
  141. scrollHeight
  142. } = event.detail;
  143. const scrollViewHeight = this.scrollHeight; // scroll-view 的高度
  144. // 距离底部50rpx时触发加载
  145. if (scrollHeight - this.scrollTop - scrollViewHeight < 50) {
  146. this.loadMoreData();
  147. }
  148. }
  149. },
  150. async loadMoreData() {
  151. if (this.loadingMore || !this.hasMore) return;
  152. this.loadingMore = true;
  153. try {
  154. // 调用API加载更多数据
  155. const newData = await this.fetchMoreTasks();
  156. if (newData.length > 0) {
  157. this.taskList.push(...newData);
  158. } else {
  159. this.hasMore = false;
  160. }
  161. } catch (error) {
  162. console.error('加载失败:', error);
  163. } finally {
  164. this.loadingMore = false;
  165. }
  166. },
  167. calcScrollHeight() {
  168. // 计算屏幕可用高度
  169. const systemInfo = uni.getSystemInfoSync();
  170. // 根据实际情况计算,这里减去头部高度
  171. this.scrollHeight = systemInfo.windowHeight * 0.6; // 示例值
  172. },
  173. handleTaskClick(item) {
  174. console.log('点击任务:', item);
  175. // 处理任务点击逻辑
  176. },
  177. handleClose() {
  178. console.log("关闭")
  179. // 关闭弹窗
  180. },
  181. handleOpen() {
  182. // 打开弹窗
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss" scoped>
  188. .content {
  189. height: 1000rpx;
  190. background: #FFFFFF;
  191. border-radius: 32rpx 32rpx 0rpx 0rpx;
  192. overflow: hidden;
  193. display: flex;
  194. flex-direction: column;
  195. .bg {
  196. padding: 36rpx 24rpx;
  197. background: linear-gradient(180deg, #FFDFCD 0%, #FFFFFF 100%);
  198. }
  199. .row {
  200. display: flex;
  201. justify-content: space-between;
  202. align-items: center;
  203. }
  204. .points {
  205. font-weight: 400;
  206. font-size: 28rpx;
  207. color: #333333;
  208. .num {
  209. font-weight: 500;
  210. font-size: 40rpx;
  211. color: #222426;
  212. margin-left: 4rpx;
  213. }
  214. }
  215. .shop {
  216. .shop-txt {
  217. font-weight: 500;
  218. font-size: 28rpx;
  219. color: #FF5C03;
  220. margin: 0 12rpx;
  221. }
  222. }
  223. .list {
  224. display: flex;
  225. justify-content: space-between;
  226. flex-wrap: wrap;
  227. padding: 0 24rpx;
  228. box-sizing: border-box;
  229. flex: 1;
  230. overflow: hidden;
  231. .list-item {
  232. width: 100%;
  233. margin-bottom: 32rpx;
  234. .button {
  235. width: 132rpx;
  236. height: 64rpx;
  237. background: #FF5C03;
  238. border-radius: 32rpx 32rpx 32rpx 32rpx;
  239. text-align: center;
  240. line-height: 64rpx;
  241. color: #FFFFFF;
  242. font-weight: 500;
  243. font-size: 28rpx;
  244. }
  245. .left {
  246. display: flex;
  247. .title {
  248. font-weight: 500;
  249. font-size: 30rpx;
  250. color: #333333;
  251. }
  252. .num {
  253. font-weight: 600;
  254. font-size: 28rpx;
  255. color: #FF5C03;
  256. }
  257. .txt {
  258. font-size: 24rpx;
  259. color: #999999;
  260. }
  261. }
  262. }
  263. }
  264. }
  265. </style>