monthly-list.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="t('wallet.item52')" />
  4. <view id="custom_history" class="">
  5. <view class="main-content">
  6. <!-- 无任务列表提示 -->
  7. <view class="list-empty-state" v-if="!tableData || tableData.length === 0">
  8. <cwg-empty-state title="UtaskList.item12" />
  9. </view>
  10. <!-- 数据卡片展示 -->
  11. <view class="outer-card" v-for="(item, index) in tableData" :key="index"
  12. v-show="tableData && tableData.length > 0">
  13. <view class="data-cards">
  14. <!-- 第一行:总数据 -->
  15. <view class="total-data-row">
  16. <view class="data-card total-card">
  17. <view class="card-content">
  18. <view class="card-title">{{ t("UtaskList.item13") }}</view>
  19. <view class="card-value" style="color: #ff4d4f">
  20. {{ item.depositAmount || 0 }}
  21. </view>
  22. </view>
  23. </view>
  24. <view class="data-card total-card">
  25. <view class="card-content">
  26. <view class="card-title">{{ t("UtaskList.item3") }}</view>
  27. <view class="card-value" style="color: #ff4d4f">
  28. {{ item.completeVolume || 0 }}
  29. </view>
  30. </view>
  31. </view>
  32. <view class="data-card total-card">
  33. <view class="card-content">
  34. <view class="card-title">{{ t("Label.State") }}</view>
  35. <view class="card-value" :style="getStatusStyle(item.status)">
  36. {{ getStatusText(item.status) }}
  37. </view>
  38. </view>
  39. </view>
  40. <view class="data-card total-card" v-if="item.status === 2">
  41. <view class="card-content">
  42. <view class="card-title">
  43. {{ t("MonthlyActivities.item4") }}
  44. </view>
  45. <view class="card-value" :style="getGiveStatusStyle(item.giveStatus)">
  46. {{ getGiveStatusText(item.giveStatus) }}
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 第二行:分数据 -->
  52. <view class="sub-data-row">
  53. <view class="data-card">
  54. <view class="card-content">
  55. <view class="card-value">{{ item.endDate }}</view>
  56. <view class="card-desc">{{ t("UtaskList.item10") }}</view>
  57. </view>
  58. </view>
  59. <view class="data-card" v-if="item.status === 2">
  60. <view class="card-content">
  61. <view class="card-value">{{ item.applyTime }}</view>
  62. <view class="card-desc">{{ t("MonthlyActivities.item6") }}</view>
  63. </view>
  64. </view>
  65. <view class="data-card" v-if="item.status === 2">
  66. <view class="card-content">
  67. <view class="card-value">{{ item.grantTime }}</view>
  68. <view class="card-desc">{{ t("MonthlyActivities.item7") }}</view>
  69. </view>
  70. </view>
  71. <view class="data-card" v-if="item.logisticsOrder">
  72. <view class="card-content">
  73. <view class="card-value">{{ item.logisticsOrder }}</view>
  74. <view class="card-desc">{{ t("MonthlyActivities.item9") }}</view>
  75. </view>
  76. </view>
  77. <view class="data-card btn-card" v-show="shouldShowCard(item, item)">
  78. <!-- 取消按钮 - status为1时显示 -->
  79. <button v-if="item.status === 1" class="btn btn-dark btn-sm waves-effect waves-light btn-outline-dark1" @click="cancelTask(item.id)"
  80. :loading="loadingStates[item.id] === 'cancel'">
  81. {{ t("Btn.Cancel") }}
  82. </button>
  83. <!-- 礼物申请按钮 - status为2且giveStatus为1时显示 -->
  84. <button class="btn btn-danger btn-sm waves-effect waves-light" v-if="item.status === 2 && item.giveStatus === 1 && lang1" @click="applyGift(item.id)"
  85. :loading="loadingStates[item.id] === 'applyGift'">
  86. {{ t("Btn.Application") }}
  87. </button>
  88. </view>
  89. </view>
  90. <!-- 提示信息 -->
  91. <view class="tip-info" style="padding: 10px 0; color: #909399; font-size: 14px">
  92. {{ t("MonthlyActivities.item10") }}
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. <!-- 礼物申请对话框 -->
  98. <GiftApplicationPopup v-model:visible="dialogGiftApplication" :title="t('Btn.Application')"
  99. :giftList="giftList" :giftForm="giftForm" @confirm="submitGiftApply" />
  100. </view>
  101. <cwg-confirm-popup />
  102. </cwg-page-wrapper>
  103. </template>
  104. <script setup lang="ts">
  105. import { ref, computed, onMounted, watch } from 'vue'
  106. import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  107. import { useI18n } from 'vue-i18n'
  108. import { activityApi } from "@/service/activity"
  109. import Config from "@/config/index"
  110. import GiftApplicationPopup from "./components/GiftApplicationPopup.vue"
  111. import useUserStore from "@/stores/use-user-store";
  112. const userStore = useUserStore();
  113. import { useConfirm } from '@/hooks/useConfirm'
  114. const confirm = useConfirm()
  115. const { t, locale } = useI18n()
  116. let { Code } = Config
  117. // ---------- 响应式数据 ----------
  118. const flag = ref(false)
  119. const reasons = ref({})
  120. const pictLoading = ref(false)
  121. const tableData = ref<any[]>([])
  122. const time = ref("")
  123. const loadingStates = ref<Record<string, string | null>>({}) // 用于跟踪每个任务的加载状态
  124. // 卡片数据
  125. const totalTasks = ref(0)
  126. const totalRewards = ref(0)
  127. const completionRate = ref("0")
  128. const inProgressTasks = ref(0)
  129. const completedTasks = ref(0)
  130. const expiredTasks = ref(0)
  131. const rejectedTasks = ref(0)
  132. const todayRewards = ref(0)
  133. const weekRewards = ref(0)
  134. const monthRewards = ref(0)
  135. const activityLevel = ref("0")
  136. // 礼物申请对话框相关
  137. const dialogGiftApplication = ref(false)
  138. const giftList = ref<any[]>([])
  139. const giftForm = ref({
  140. id: null as number | null,
  141. giveCode: "",
  142. giveName: "",
  143. giveAddress: "",
  144. givePhone: "",
  145. giveAcceptName: "",
  146. })
  147. const giftSubmitting = ref(false)
  148. // 原 watch 中依赖的 search(保留)
  149. const search = ref({ type: "" })
  150. // ---------- 计算属性 ----------
  151. // 注意:document 在 uni-app 中不可用,此处保留原逻辑但需注意运行环境
  152. // 若需兼容,可改用 uni.getSystemInfoSync().windowWidth
  153. const lang1 = computed(() => {
  154. return userStore?.userInfo?.customInfo?.country == "CN"
  155. })
  156. // ---------- 方法 ----------
  157. const getStatus = (status: number) => {
  158. if (status == 1) {
  159. return t("State.Ongoing")
  160. } else if (status == 2) {
  161. return t("State.Completed")
  162. } else if (status == 3) {
  163. return t("State.Cancelled")
  164. } else if (status == 4) {
  165. return t("State.expireTime")
  166. }
  167. }
  168. const getStatusText = (status: number) => {
  169. if (status == 1) {
  170. return t("State.InTask")
  171. } else if (status == 2) {
  172. return t("UtaskList.item6")
  173. } else if (status == 3) {
  174. return t("State.Cancelled")
  175. } else if (status == 4) {
  176. return t("State.Ended")
  177. }
  178. return ""
  179. }
  180. const getStatusStyle = (status: number) => {
  181. if (status == 1) {
  182. return "color: #ffd591;"
  183. } else if (status == 2) {
  184. return "color: #52c41a;"
  185. } else if (status == 3) {
  186. return "color: #999999;"
  187. } else if (status == 4) {
  188. return "color: #999999;"
  189. }
  190. return "color: var(--bs-heading-color);"
  191. }
  192. const getGiveStatusText = (giveStatus: number) => {
  193. if (giveStatus == 1) {
  194. return t("State.NotApply")
  195. } else if (giveStatus == 2) {
  196. return t("State.Applied")
  197. } else if (giveStatus == 3) {
  198. return t("State.Granted")
  199. }
  200. return ""
  201. }
  202. const getGiveStatusStyle = (giveStatus: number) => {
  203. if (giveStatus == 1) {
  204. return "color: #999999;"
  205. } else if (giveStatus == 2) {
  206. return "color: #1890ff;"
  207. } else if (giveStatus == 3) {
  208. return "color: #52c41a;"
  209. }
  210. return "color: var(--bs-heading-color);"
  211. }
  212. const canPerformAction = (task: any) => {
  213. return task.status === 1 || (task.status === 2 && task.withdrawStatus === 1)
  214. }
  215. const shouldShowCard = (el: any) => {
  216. const hasCancelButton = el.status === 1
  217. const hasGiftApplyButton = el.status === 2 && el.giveStatus === 1 && lang1.value
  218. return hasCancelButton || hasGiftApplyButton
  219. }
  220. // 恢复信用(原 completeTask)
  221. const completeTask = async (id: number) => {
  222. return new Promise(async (resolve) => {
  223. const resConfirm = await uni.showModal({
  224. title: t("Msg.SystemPrompt"),
  225. content: t("surplusList.item9"),
  226. confirmText: t("Btn.Confirm"),
  227. cancelText: t("Btn.Cancel"),
  228. })
  229. if (!resConfirm.confirm) return resolve(null)
  230. loadingStates.value[id] = "complete"
  231. try {
  232. const res = await activityApi.ActivitySurplusRecoverCredit({ id })
  233. if (res.code == Code.StatusOK) {
  234. // uni.showToast({ title: t("Msg.Success"), icon: "success" })
  235. searchFunc()
  236. } else {
  237. uni.showToast({ title: res.msg, icon: "none" })
  238. }
  239. } catch (error) {
  240. uni.showToast({ title: t("Msg.Fail"), icon: "none" })
  241. } finally {
  242. loadingStates.value[id] = null
  243. resolve(null)
  244. }
  245. })
  246. }
  247. // 提现
  248. const withdrawTask = async (id: number) => {
  249. return new Promise(async (resolve) => {
  250. const resConfirm = await uni.showModal({
  251. title: t("Msg.SystemPrompt"),
  252. content: t("UtaskList.item15"),
  253. confirmText: t("Btn.Confirm"),
  254. cancelText: t("Btn.Cancel"),
  255. })
  256. if (!resConfirm.confirm) return resolve(null)
  257. loadingStates.value[id] = "withdraw"
  258. try {
  259. const res = await activityApi.UcoinWithdraw({ id })
  260. if (res.code == Code.StatusOK) {
  261. searchFunc()
  262. } else {
  263. uni.showToast({ title: res.msg, icon: "none" })
  264. }
  265. } catch (error) {
  266. uni.showToast({ title: t("Msg.Fail"), icon: "none" })
  267. } finally {
  268. loadingStates.value[id] = null
  269. resolve(null)
  270. }
  271. })
  272. }
  273. // 取消任务
  274. const cancelTask = async (id: number) => {
  275. try {
  276. await confirm({
  277. title: t("Msg.SystemPrompt"),
  278. content: t("UtaskList.item8"),
  279. confirmText: t("Btn.Confirm"),
  280. cancelText: t("Btn.Cancel"),
  281. })
  282. const res = await activityApi.ActivityMonthlyCancel({ id })
  283. if (res.code == Code.StatusOK) {
  284. uni.showToast({ title: t("UtaskList.item9"), icon: "success" })
  285. searchFunc()
  286. } else {
  287. uni.showToast({ title: res.msg, icon: "none" })
  288. }
  289. } catch (error) {
  290. if (error?.msg) uni.showToast({ title: error.msg, icon: "none" })
  291. }
  292. }
  293. // 礼物申请 - 打开对话框并获取礼品列表
  294. const applyGift = async (id: number) => {
  295. // 重置表单
  296. giftForm.value = {
  297. id: id,
  298. giveCode: "",
  299. giveName: "",
  300. giveAddress: "",
  301. givePhone: "",
  302. giveAcceptName: "",
  303. }
  304. giftList.value = []
  305. // 获取礼品列表
  306. try {
  307. const res = await activityApi.ActivityMonthlyGiveList({ id })
  308. if (res.code == Code.StatusOK) {
  309. giftList.value = res.data || []
  310. dialogGiftApplication.value = true
  311. } else {
  312. uni.showToast({ title: res.msg, icon: "none" })
  313. }
  314. } catch (error) {
  315. uni.showToast({ title: t("Msg.Fail"), icon: "none" })
  316. }
  317. }
  318. // 处理礼品选择变化
  319. const handleGiftChange = (giveCode: string) => {
  320. const selectedGift = giftList.value.find(gift => gift.giveCode === giveCode)
  321. if (selectedGift) {
  322. giftForm.value.giveName = selectedGift.giveName
  323. }
  324. }
  325. // 提交礼物申请
  326. const submitGiftApply = async (form) => {
  327. // 表单验证(假设模板中有 ref="giftForm" 的 uni-forms 组件)
  328. // 这里需要适配实际验证方式,简化起见调用一个验证函数,若验证失败则返回
  329. // 由于 uni-app 中没有直接提供 validate,需根据实际组件实现,此处保留原逻辑结构
  330. // 实际使用时请配合 uni-forms 或自定义验证
  331. const valid = true // 占位,实际需调用 this.$refs.giftForm.validate()
  332. if (!valid) return
  333. const resConfirm = await uni.showModal({
  334. title: t("Msg.SystemPrompt"),
  335. content: t("MonthlyActivities.item10"),
  336. confirmText: t("Btn.Confirm"),
  337. cancelText: t("Btn.Cancel"),
  338. })
  339. if (!resConfirm.confirm) return
  340. giftSubmitting.value = true
  341. try {
  342. const res = await activityApi.ActivityMonthlyGiveApply({
  343. id: giftForm.value.id,
  344. giveCode: form.giveCode,
  345. giveName: form.giveName,
  346. giveAddress: form.giveAddress.trim(),
  347. givePhone: form.givePhone.trim(),
  348. })
  349. if (res.code == Code.StatusOK) {
  350. // uni.showToast({ title: t("Msg.Success"), icon: "success" })
  351. dialogGiftApplication.value = false
  352. searchFunc()
  353. } else {
  354. uni.showToast({ title: res.msg, icon: "none" })
  355. }
  356. } catch (error) {
  357. uni.showToast({ title: t("Msg.Fail"), icon: "none" })
  358. } finally {
  359. giftSubmitting.value = false
  360. }
  361. }
  362. // 查看任务进度
  363. const viewTaskProgress = async (id: number) => {
  364. loadingStates.value[id] = "progress"
  365. try {
  366. const res = await activityApi.UcoinProgress()
  367. if (res.code == Code.StatusOK) {
  368. uni.showToast({ title: res.msg, icon: "none" })
  369. } else {
  370. uni.showToast({ title: res.msg, icon: "none" })
  371. }
  372. } catch (error) {
  373. uni.showToast({ title: t("Msg.Fail"), icon: "none" })
  374. } finally {
  375. loadingStates.value[id] = null
  376. }
  377. }
  378. // 计算卡片数据(保留原方法体)
  379. const calculateCardData = () => {
  380. // 可根据需求实现
  381. }
  382. // 返回活动
  383. const backActivity = () => {
  384. uni.navigateBack()
  385. }
  386. // 获取列表
  387. const searchFunc = async () => {
  388. if (flag.value) return
  389. flag.value = true
  390. pictLoading.value = true
  391. let res = await activityApi.ActivityMonthlyTaskList()
  392. if (res.code == Code.StatusOK) {
  393. tableData.value = res.data
  394. calculateCardData()
  395. // uni.showToast({ title: t("Msg.SearchSuccess"), icon: "success" })
  396. pictLoading.value = false
  397. flag.value = false
  398. } else {
  399. uni.showToast({ title: res.msg, icon: "none" })
  400. pictLoading.value = false
  401. flag.value = false
  402. }
  403. }
  404. // ---------- 生命周期与监听 ----------
  405. onMounted(() => {
  406. searchFunc()
  407. })
  408. // 原 watch(保留)
  409. watch(
  410. () => search.value.type,
  411. () => {
  412. searchFunc()
  413. }
  414. )
  415. // 若需要 uni-app 页面生命周期可额外添加 onShow 等
  416. // onShow(() => {})
  417. </script>
  418. <style lang="scss" scoped>
  419. @import "@/uni.scss";
  420. .tip-info{
  421. line-height: px2rpx(18);
  422. }
  423. #custom_history {
  424. width: 100%;
  425. height: 100%;
  426. .no-data-container {
  427. display: flex;
  428. justify-content: center;
  429. align-items: center;
  430. height: px2rpx(300);
  431. .no-data-content {
  432. text-align: center;
  433. color: var(--bs-heading-color);
  434. i {
  435. font-size: px2rpx(48);
  436. margin-bottom: px2rpx(16);
  437. display: block;
  438. }
  439. p {
  440. font-size: px2rpx(16);
  441. margin: 0;
  442. }
  443. }
  444. }
  445. .main-content {
  446. width: 100%;
  447. height: calc(100% - 50px);
  448. // @include bg_white();
  449. padding: px2rpx(20);
  450. box-sizing: border-box;
  451. overflow: hidden;
  452. overflow-y: auto;
  453. }
  454. .state.btn {
  455. background: #eb3f57;
  456. color: white;
  457. padding: px2rpx(3) px2rpx(15);
  458. border-radius: px2rpx(4);
  459. }
  460. .action-buttons {
  461. display: flex;
  462. flex-direction: column;
  463. gap: px2rpx(8);
  464. align-items: center;
  465. .el-button {
  466. min-width: px2rpx(80);
  467. font-size: px2rpx(12);
  468. }
  469. .status-text {
  470. font-size: px2rpx(14);
  471. color: var(--bs-heading-color);
  472. font-weight: 500;
  473. }
  474. }
  475. // 外层卡片样式
  476. .outer-card {
  477. background: #ffffff;
  478. border-radius: px2rpx(16);
  479. padding: px2rpx(24);
  480. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  481. border: 1px solid #f0f0f0;
  482. margin-bottom: px2rpx(30);
  483. }
  484. // 数据卡片样式
  485. .data-cards {
  486. display: flex;
  487. flex-direction: column;
  488. gap: px2rpx(20);
  489. .total-data-row {
  490. display: grid;
  491. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  492. gap: px2rpx(15);
  493. }
  494. .sub-data-row {
  495. display: grid;
  496. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  497. gap: px2rpx(15);
  498. }
  499. .data-card {
  500. background: #ffffff;
  501. border-radius: px2rpx(12);
  502. padding: px2rpx(24);
  503. // box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  504. border: 1px solid #f0f0f0;
  505. transition: all 0.3s ease;
  506. text-align: center;
  507. &:hover {
  508. transform: translateY(-2px);
  509. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  510. }
  511. // 根据状态设置背景色
  512. &.status-1 {
  513. background: #fff7e6; // 任务中 - 黄色背景
  514. border-color: #ffd591;
  515. }
  516. &.status-2 {
  517. background: #f6ffed; // 已完成 - 绿色背景
  518. border-color: #b7eb8f;
  519. }
  520. &.status-3,
  521. &.status-4 {
  522. background: #f5f5f5; // 已取消/已结束 - 灰色背景
  523. border-color: #d9d9d9;
  524. }
  525. &.total-card {
  526. background: #ffffff;
  527. color: var(--bs-heading-color);
  528. // border: 1px solid gray;
  529. .card-value {
  530. color: var(--bs-heading-color);
  531. }
  532. .card-desc {
  533. color: var(--bs-heading-color);
  534. }
  535. // 状态卡片的特殊样式
  536. &.status-1 {
  537. background: #fff7e6;
  538. border-color: #ffd591;
  539. }
  540. &.status-2 {
  541. background: #f6ffed;
  542. border-color: #b7eb8f;
  543. }
  544. &.status-3,
  545. &.status-4 {
  546. background: #f5f5f5;
  547. border-color: #d9d9d9;
  548. }
  549. }
  550. &.sub-card {
  551. background: #ffffff;
  552. border-left: px2rpx(4) solid #667eea;
  553. &:nth-child(2) {
  554. border-left-color: #52c41a;
  555. }
  556. &:nth-child(3) {
  557. border-left-color: #faad14;
  558. }
  559. &:nth-child(4) {
  560. border-left-color: #ff4d4f;
  561. }
  562. }
  563. .card-content {
  564. .card-title {
  565. font-size: px2rpx(16);
  566. color: var(--bs-heading-color);
  567. margin-bottom: px2rpx(8);
  568. font-weight: 500;
  569. }
  570. .card-value {
  571. font-size: px2rpx(18);
  572. font-weight: 700;
  573. color: var(--bs-heading-color);
  574. margin-bottom: px2rpx(4);
  575. line-height: 1;
  576. }
  577. .card-desc {
  578. font-size: px2rpx(12);
  579. color: var(--bs-heading-color);
  580. line-height: 1.4;
  581. }
  582. }
  583. }
  584. .btn-card {
  585. display: flex;
  586. justify-content: center;
  587. align-items: center;
  588. flex-direction: column;
  589. gap: px2rpx(10);
  590. button {
  591. width: 100%;
  592. }
  593. }
  594. }
  595. // 响应式设计
  596. @media (max-width: 768px) {
  597. .data-cards {
  598. .total-data-row,
  599. .sub-data-row {
  600. grid-template-columns: 1fr;
  601. }
  602. .data-card {
  603. padding: px2rpx(16);
  604. .card-content {
  605. .card-value {
  606. font-size: px2rpx(24);
  607. }
  608. }
  609. }
  610. }
  611. }
  612. }
  613. </style>