task.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <u-popup :show="show" @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. <!-- 修改这里:改为调用 handleClose 方法 -->
  10. <image class="w40 h40" src="/static/images/pop_close_icon.png" @click="handleClose"></image>
  11. </view>
  12. <!-- 积分信息 -->
  13. <view class="row mtb48 plr24">
  14. <view class="points row">
  15. <text class="lable">我的积分</text>
  16. <text class="num">3688</text>
  17. </view>
  18. <view class="shop row">
  19. <image class="w48 h48" src="/static/images/fanghua_coin_icon.png"></image>
  20. <text class="shop-txt">芳华币商城</text>
  21. <image class="w24 h24" src="/static/images/coin_arrow.png"></image>
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 可滚动列表区域 -->
  26. <scroll-view scroll-y class="list" :style="{ height: scrollHeight + 'px' }" @scroll="handleScroll">
  27. <!-- 列表项 -->
  28. <view v-for="(item, index) in taskList" :key="index" class="list-item">
  29. <view class="row">
  30. <view class="left">
  31. <image class="w88 h88 mr24" src="/static/images/img.png"></image>
  32. <view>
  33. <view class="mb8 row">
  34. <text class="title">{{ item.title }}({{ item.current }}/{{ item.total }})</text>
  35. <image class="w40 h40 mr4 ml8" src="/static/images/fanghua_coin_icon.png"></image>
  36. <text class="num">+{{ item.points }}</text>
  37. </view>
  38. <view class="txt">{{ item.desc }}</view>
  39. </view>
  40. </view>
  41. <view class="button" @click="handleTaskClick(item)">
  42. {{ item.buttonText }}
  43. </view>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. </u-popup>
  49. </template>
  50. <script>
  51. export default {
  52. props: {
  53. show: {
  54. type: Boolean,
  55. default: false
  56. }
  57. },
  58. data() {
  59. return {
  60. scrollHeight: 400,
  61. scrollTop: 0,
  62. showBackTop: false,
  63. loadingMore: false,
  64. hasMore: true,
  65. taskList: [
  66. {
  67. title: '点赞内容',
  68. current: 0,
  69. total: 1,
  70. points: 1,
  71. desc: '最多1条得芳华币',
  72. buttonText: '去完成'
  73. }, {
  74. title: '点赞内容',
  75. current: 0,
  76. total: 1,
  77. points: 1,
  78. desc: '最多1条得芳华币',
  79. buttonText: '去完成'
  80. }, {
  81. title: '点赞内容',
  82. current: 0,
  83. total: 1,
  84. points: 1,
  85. desc: '最多1条得芳华币',
  86. buttonText: '去完成'
  87. }, {
  88. title: '点赞内容',
  89. current: 0,
  90. total: 1,
  91. points: 1,
  92. desc: '最多1条得芳华币',
  93. buttonText: '去完成'
  94. }, {
  95. title: '点赞内容',
  96. current: 0,
  97. total: 1,
  98. points: 1,
  99. desc: '最多1条得芳华币',
  100. buttonText: '去完成'
  101. }, {
  102. title: '点赞内容',
  103. current: 0,
  104. total: 1,
  105. points: 1,
  106. desc: '最多1条得芳华币',
  107. buttonText: '去完成'
  108. }, {
  109. title: '点赞内容',
  110. current: 0,
  111. total: 1,
  112. points: 1,
  113. desc: '最多1条得芳华币',
  114. buttonText: '去完成'
  115. },
  116. // ... 其他数据项
  117. ]
  118. }
  119. },
  120. mounted() {
  121. this.calcScrollHeight();
  122. },
  123. methods: {
  124. handleClose() {
  125. // 通知父组件关闭弹窗
  126. console.log("关闭弹窗");
  127. this.$emit('close');
  128. },
  129. handleOpen() {
  130. // 弹窗打开时的逻辑
  131. console.log("弹窗打开");
  132. },
  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 { scrollHeight } = event.detail;
  141. const scrollViewHeight = this.scrollHeight;
  142. // 距离底部50rpx时触发加载
  143. if (scrollHeight - this.scrollTop - scrollViewHeight < 50) {
  144. this.loadMoreData();
  145. }
  146. }
  147. },
  148. async loadMoreData() {
  149. if (this.loadingMore || !this.hasMore) return;
  150. this.loadingMore = true;
  151. try {
  152. // 调用API加载更多数据
  153. // const newData = await this.fetchMoreTasks();
  154. // 这里模拟加载数据
  155. const newData = await new Promise(resolve => {
  156. setTimeout(() => {
  157. resolve([
  158. {
  159. title: '新任务',
  160. current: 0,
  161. total: 1,
  162. points: 2,
  163. desc: '新增任务',
  164. buttonText: '去完成'
  165. }
  166. ]);
  167. }, 1000);
  168. });
  169. if (newData.length > 0) {
  170. this.taskList.push(...newData);
  171. } else {
  172. this.hasMore = false;
  173. }
  174. } catch (error) {
  175. console.error('加载失败:', error);
  176. } finally {
  177. this.loadingMore = false;
  178. }
  179. },
  180. calcScrollHeight() {
  181. // 计算屏幕可用高度
  182. const systemInfo = uni.getSystemInfoSync();
  183. // 弹窗高度设置为屏幕高度的70%
  184. this.scrollHeight = systemInfo.windowHeight * 0.7;
  185. },
  186. handleTaskClick(item) {
  187. console.log('点击任务:', item);
  188. // 处理任务点击逻辑
  189. uni.showToast({
  190. title: `点击了${item.title}`,
  191. icon: 'none'
  192. });
  193. }
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. .content {
  199. height: 1000rpx;
  200. background: #FFFFFF;
  201. border-radius: 32rpx 32rpx 0rpx 0rpx;
  202. overflow: hidden;
  203. display: flex;
  204. flex-direction: column;
  205. .bg {
  206. padding: 36rpx 24rpx;
  207. background: linear-gradient(180deg, #FFDFCD 0%, #FFFFFF 100%);
  208. }
  209. .row {
  210. display: flex;
  211. justify-content: space-between;
  212. align-items: center;
  213. }
  214. .mtb48 {
  215. margin-top: 48rpx;
  216. margin-bottom: 48rpx;
  217. }
  218. .plr24 {
  219. padding-left: 24rpx;
  220. padding-right: 24rpx;
  221. }
  222. .mr24 {
  223. margin-right: 24rpx;
  224. }
  225. .mr4 {
  226. margin-right: 4rpx;
  227. }
  228. .ml8 {
  229. margin-left: 8rpx;
  230. }
  231. .mb8 {
  232. margin-bottom: 8rpx;
  233. }
  234. .points {
  235. font-weight: 400;
  236. font-size: 28rpx;
  237. color: #333333;
  238. .num {
  239. font-weight: 500;
  240. font-size: 40rpx;
  241. color: #222426;
  242. margin-left: 4rpx;
  243. }
  244. }
  245. .shop {
  246. .shop-txt {
  247. font-weight: 500;
  248. font-size: 28rpx;
  249. color: #FF5C03;
  250. margin: 0 12rpx;
  251. }
  252. }
  253. .list {
  254. display: flex;
  255. justify-content: space-between;
  256. flex-wrap: wrap;
  257. padding: 0 24rpx;
  258. box-sizing: border-box;
  259. flex: 1;
  260. overflow: hidden;
  261. .list-item {
  262. width: 100%;
  263. margin-bottom: 32rpx;
  264. .button {
  265. width: 132rpx;
  266. height: 64rpx;
  267. background: #FF5C03;
  268. border-radius: 32rpx 32rpx 32rpx 32rpx;
  269. text-align: center;
  270. line-height: 64rpx;
  271. color: #FFFFFF;
  272. font-weight: 500;
  273. font-size: 28rpx;
  274. }
  275. .left {
  276. display: flex;
  277. .title {
  278. font-weight: 500;
  279. font-size: 30rpx;
  280. color: #333333;
  281. }
  282. .num {
  283. font-weight: 600;
  284. font-size: 28rpx;
  285. color: #FF5C03;
  286. }
  287. .txt {
  288. font-size: 24rpx;
  289. color: #999999;
  290. }
  291. }
  292. }
  293. }
  294. // 添加图标尺寸类
  295. .w40 { width: 40rpx; }
  296. .h40 { height: 40rpx; }
  297. .w428 { width: 428rpx; }
  298. .h64 { height: 64rpx; }
  299. .w48 { width: 48rpx; }
  300. .h48 { height: 48rpx; }
  301. .w24 { width: 24rpx; }
  302. .h24 { height: 24rpx; }
  303. .w88 { width: 88rpx; }
  304. .h88 { height: 88rpx; }
  305. }
  306. </style>