taskList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <view class="task-page">
  3. <!-- 顶部积分信息 -->
  4. <view class="points-header">
  5. <view class="points-item">
  6. <view class="img">
  7. <u-avatar size="96rpx" default-url="/static/common/avatar.png" />
  8. </view>
  9. </view>
  10. <view class="points-item">
  11. <text class="points-value">{{ totalPoints }}</text>
  12. <text class="points-label">我的积分</text>
  13. </view>
  14. <view class="points-item">
  15. <text class="points-value">{{ completedTask }}</text>
  16. <text class="points-label">已完成任务</text>
  17. </view>
  18. <view class="points-item">
  19. <text class="points-value">{{ pendingTasks }}</text>
  20. <text class="points-label">待完成任务</text>
  21. </view>
  22. </view>
  23. <view class="container">
  24. <!-- 标签切换 -->
  25. <u-tabs
  26. :list="tabs"
  27. :current="type"
  28. @change="handleTabChange"
  29. lineWidth="60"
  30. lineColor="#20CAC2"
  31. :activeStyle="{
  32. color: '#303133',
  33. fontWeight: 'bold',
  34. transform: 'scale(1.05)'
  35. }"
  36. :inactiveStyle="{
  37. color: '#606266',
  38. transform: 'scale(1)'
  39. }"
  40. itemStyle="padding:0 55rpx; height: 72rpx;font-size:28rpx"
  41. class="tabs-container"
  42. ></u-tabs>
  43. <!-- 任务列表 -->
  44. <view class="tasks-container">
  45. <u-list
  46. ref="taskList"
  47. @scrolltolower="loadMore"
  48. style="height:calc(75vh - 60rpx)"
  49. >
  50. <u-list-item v-for="(task, index) in tasks" :key="index" class="task-item">
  51. <view class="task-icon">
  52. <image :src="getTaskIcon(task.taskName)" mode="aspectFill"></image>
  53. </view>
  54. <view class="task-info">
  55. <text class="task-name">{{ task.taskName }}</text>
  56. <view class="task-reward">
  57. <ImageItem src="/static/points/point.png"/>
  58. <text>+{{ task.rewardPoints }}</text>
  59. </view>
  60. </view>
  61. <view class="task-progress">
  62. <text class="progress-text">{{ task.completedCount }}/{{ task.triggerValue }}</text>
  63. <button
  64. :class="task.completedCount >= task.triggerValue ? 'task-btn' : 'no-task-btn'"
  65. @click.stop="handleTask(task)"
  66. :disabled="task.completedCount >= task.triggerValue"
  67. >
  68. {{ task.completedCount >= task.triggerValue ? '已完成' : '去完成' }}
  69. </button>
  70. </view>
  71. </u-list-item>
  72. <!-- 空数据状态 -->
  73. <u-empty
  74. v-if="tasks.length === 0 && !loading"
  75. icon="document"
  76. text="暂无任务"
  77. mode="page"
  78. ></u-empty>
  79. <!-- 加载中状态 -->
  80. <view v-if="loading && tasks.length === 0" class="loading-container">
  81. <u-loading-icon text="加载中..."></u-loading-icon>
  82. </view>
  83. <!-- 加载更多 -->
  84. <u-loadmore
  85. v-if="tasks.length > 0"
  86. :status="loading ? 'loading' : (hasMore ? 'more' : 'nomore')"
  87. loading-text="加载中..."
  88. nomore-text="没有更多任务了"
  89. @loadmore="loadMore"
  90. ></u-loadmore>
  91. </u-list>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. import ImageItem from "@/components/swiper/components/image.vue";
  98. import { mapState } from 'vuex';
  99. import {getPointTaskList} from '@/api/points'
  100. export default {
  101. name: "taskList",
  102. components: {ImageItem},
  103. computed: {
  104. ...mapState({
  105. myPoint: state => state.points.myPoint
  106. }),
  107. totalPoints() {
  108. return this.myPoint && this.myPoint.totalPoints || 0;
  109. },
  110. completedTask() {
  111. return this.myPoint && this.myPoint.completedTask || 0;
  112. },
  113. pendingTasks() {
  114. return this.myPoint && this.myPoint.pendingTasks || 0;
  115. },
  116. type() {
  117. return this.tabs.findIndex(item => item.key === this.activeTab)
  118. },
  119. },
  120. data() {
  121. return {
  122. // 标签数据
  123. tabs: [
  124. { key: '1', name: '新手任务' },
  125. { key: '2', name: '每日任务' },
  126. { key: '3', name: '每月任务' }
  127. ],
  128. // 当前选中的标签
  129. activeTab: '1',
  130. // 任务数据
  131. tasks: [],
  132. // 分页数据
  133. pageNum: 1,
  134. pageSize: 10,
  135. hasMore: true,
  136. loading: false,
  137. // 任务类型配置
  138. taskConfig: {
  139. order: {
  140. icon: '/static/points/task_order.png',
  141. action: this.handleOrderTask
  142. },
  143. merchant: {
  144. icon: '/static/points/task_shop.png',
  145. action: this.handleMerchantTask
  146. },
  147. dynamic: {
  148. icon: '/static/points/task_trend.png',
  149. action: this.handleDynamicTask
  150. },
  151. service: {
  152. icon: '/static/points/task_wx.png',
  153. action: this.handleServiceTask
  154. },
  155. recharge: {
  156. icon: '/static/points/task_account.png',
  157. action: this.handleRechargeTask
  158. }
  159. }
  160. }
  161. },
  162. onReady() {
  163. // 初始获取数据
  164. this.fetchTaskList()
  165. },
  166. methods: {
  167. // 切换标签
  168. handleTabChange(data) {
  169. this.activeTab = data.key
  170. // 重置分页数据
  171. this.pageNum = 1
  172. this.hasMore = true
  173. // 清空数据
  174. this.tasks = []
  175. // 重新获取数据
  176. this.fetchTaskList()
  177. },
  178. // 处理任务
  179. handleTask(task) {
  180. if (task.completedCount >= task.triggerValue) return;
  181. if (task.taskName.includes('订单')) {
  182. this.taskConfig.order.action();
  183. } else if (task.taskName.includes('商户')) {
  184. this.taskConfig.merchant.action();
  185. } else if (task.taskName.includes('动态')) {
  186. this.taskConfig.dynamic.action();
  187. } else if (task.taskName.includes('服务号')) {
  188. this.taskConfig.service.action();
  189. } else if (task.taskName.includes('账号充值')) {
  190. this.taskConfig.recharge.action();
  191. }
  192. },
  193. // 处理订单任务
  194. handleOrderTask() {
  195. uni.navigateTo({
  196. url: '/points/home/index?scrollToSearch=1'
  197. });
  198. },
  199. // 处理商户任务
  200. handleMerchantTask() {
  201. uni.switchTab({
  202. url: '/pages/identify/identify'
  203. });
  204. },
  205. // 处理动态任务
  206. handleDynamicTask() {
  207. uni.switchTab({
  208. url: '/pages/discover/discover'
  209. });
  210. },
  211. // 处理服务号任务
  212. handleServiceTask() {
  213. // 服务号任务处理逻辑
  214. },
  215. // 处理账号充值任务
  216. handleRechargeTask() {
  217. uni.navigateTo({
  218. url: '/pages/my/pay'
  219. });
  220. },
  221. // 加载更多数据
  222. loadMore() {
  223. if (this.loading || !this.hasMore) return
  224. this.pageNum++
  225. this.fetchTaskList(true)
  226. },
  227. // 获取任务列表数据
  228. async fetchTaskList(isLoadMore = false) {
  229. this.loading = true
  230. try {
  231. const res = await getPointTaskList({
  232. pageNum: this.pageNum,
  233. pageSize: this.pageSize,
  234. type: this.activeTab,
  235. cityCode: uni.getStorageSync('selectCitycode'),
  236. })
  237. if (res.code === 200) {
  238. if (isLoadMore) {
  239. this.tasks = [...this.tasks, ...res.rows]
  240. } else {
  241. this.tasks = res.rows
  242. }
  243. this.hasMore = this.tasks.length < res.total
  244. }
  245. this.loading = false
  246. } catch (error) {
  247. console.error('获取任务列表失败:', error)
  248. this.loading = false
  249. }
  250. },
  251. // 根据任务名称获取图标
  252. getTaskIcon(taskName) {
  253. if (taskName.includes('订单')) return this.taskConfig.order.icon;
  254. if (taskName.includes('商户')) return this.taskConfig.merchant.icon;
  255. if (taskName.includes('动态')) return this.taskConfig.dynamic.icon;
  256. if (taskName.includes('服务号')) return this.taskConfig.service.icon;
  257. if (taskName.includes('账号充值')) return this.taskConfig.recharge.icon;
  258. return ''
  259. }
  260. }
  261. }
  262. </script>
  263. <style scoped lang="scss">
  264. .task-page{
  265. width: 750rpx;
  266. min-height: 100vh;
  267. background-image: url("@/static/points/pointBg.png");
  268. background-size: 100%;
  269. background-repeat: no-repeat;
  270. background-color: #ffe5ca;
  271. padding-top: 48rpx;
  272. }
  273. .points-header{
  274. display: flex;
  275. justify-content: space-around;
  276. margin-bottom: 42rpx;
  277. padding: 0 36rpx;
  278. .points-item{
  279. display: flex;
  280. flex-direction: column;
  281. align-items: center;
  282. justify-content: center;
  283. .points-label{
  284. font-family: PingFang SC, PingFang SC;
  285. font-weight: 500;
  286. font-size: 24rpx;
  287. color: #FFFFFF;
  288. line-height: 24rpx;
  289. }
  290. .points-value{
  291. font-family: DIN, DIN;
  292. font-weight: 500;
  293. font-size: 40rpx;
  294. color: #FFFFFF;
  295. line-height: 32rpx;
  296. margin-bottom: 16rpx;
  297. display: block;
  298. }
  299. }
  300. }
  301. .container{
  302. width: 686rpx;
  303. height: 83vh;
  304. background: #FFFFFF;
  305. border-radius: 20rpx;
  306. margin: 0 auto;
  307. padding: 10rpx 0;
  308. .tabs-container{
  309. display: flex;
  310. overflow: hidden;
  311. margin-bottom: 32rpx;
  312. }
  313. }
  314. .tasks-container{
  315. .task-item{
  316. display: flex;
  317. align-items: center;
  318. padding: 24rpx 32rpx;
  319. flex-direction: row;
  320. .task-icon{
  321. width: 80rpx;
  322. height: 80rpx;
  323. margin-right: 24rpx;
  324. image{
  325. width: 100%;
  326. height: 100%;
  327. }
  328. }
  329. .task-info{
  330. flex: 1;
  331. .task-name{
  332. font-family: PingFang SC, PingFang SC;
  333. font-weight: 500;
  334. font-size: 28rpx;
  335. color: #333333;
  336. line-height: 28rpx;
  337. display: block;
  338. margin-bottom: 12rpx;
  339. }
  340. .task-reward {
  341. display: inline-flex;
  342. height: 32rpx;
  343. background: #FBF2E1;
  344. border-radius: 22rpx;
  345. padding-right: 12rpx;
  346. image{
  347. width: 32rpx;
  348. height: 32rpx;
  349. margin-right: 4rpx;
  350. }
  351. text{
  352. font-family: PingFang SC, PingFang SC;
  353. font-weight: 500;
  354. font-size: 24rpx;
  355. color: #FF9F00;
  356. line-height: 32rpx;
  357. }
  358. }
  359. }
  360. .task-progress{
  361. display: flex;
  362. flex-direction: row;
  363. .progress-text{
  364. font-family: PingFang SC, PingFang SC;
  365. font-weight: 500;
  366. font-size: 28rpx;
  367. color: #999999;
  368. line-height: 28rpx;
  369. margin-right: 8rpx;
  370. margin-top: 10rpx;
  371. }
  372. .task-btn {
  373. height: 48rpx;
  374. background: #EEEEEE;
  375. border-radius: 98rpx;
  376. font-family: PingFang SC, PingFang SC;
  377. font-weight: 500;
  378. font-size: 26rpx;
  379. color: #999999;
  380. line-height: 48rpx;
  381. border: 1px solid #EEEEEE;
  382. margin: 0;
  383. padding: 0 20rpx;
  384. }
  385. .no-task-btn {
  386. height: 48rpx;
  387. background: #03C1B8;
  388. border-radius: 98rpx;
  389. font-family: PingFang SC, PingFang SC;
  390. font-weight: 500;
  391. font-size: 26rpx;
  392. color: #FFFFFF;
  393. line-height: 48rpx;
  394. margin: 0;
  395. padding: 0 20rpx;
  396. }
  397. }
  398. }
  399. .u-empty{
  400. margin-top: 20vh!important;
  401. }
  402. /* 加载中容器 */
  403. .loading-container {
  404. margin-top: 20vh!important;
  405. }
  406. }
  407. </style>