surplus-list.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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. <cwg-empty-state v-if="!tableData || tableData.length === 0" title="UtaskList.item12" />
  8. <!-- 数据卡片展示 -->
  9. <view class="outer-card" v-for="(item, index) in tableData" :key="index"
  10. v-show="tableData && tableData.length > 0">
  11. <view class="data-cards">
  12. <!-- 第一行:总数据 -->
  13. <view class="total-data-row">
  14. <view class="data-card total-card">
  15. <view class="card-content">
  16. <view class="card-title">{{ t("UtaskList.item13") }}</view>
  17. <view class="card-value" style="color: #ff4d4f">
  18. {{ item.depositAmount || 0 }}
  19. </view>
  20. </view>
  21. </view>
  22. <view class="data-card total-card">
  23. <view class="card-content">
  24. <view class="card-title">{{ t("UtaskList.item3") }}</view>
  25. <view class="card-value" style="color: #ff4d4f">
  26. {{ item.completeVolume || 0 }}
  27. </view>
  28. </view>
  29. </view>
  30. <view class="data-card total-card">
  31. <view class="card-content">
  32. <view class="card-title">{{ t("surplusList.item8") }}</view>
  33. <view class="card-value" style="color: #ff4d4f">
  34. {{ item.amount }}
  35. </view>
  36. </view>
  37. </view>
  38. <view class="data-card total-card">
  39. <view class="card-content">
  40. <view class="card-title">{{ t("Label.State") }}</view>
  41. <view class="card-value" :style="item.status == 1 ? 'color: #ffd591;' : 'color: #52c41a;'
  42. ">
  43. {{ item.status == 1 ? t("State.Ongoing") : t("State.Completed") }}
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 第二行:分数据 -->
  49. <view class="sub-data-row">
  50. <view class="data-card">
  51. <view class="card-content">
  52. <view class="card-value">{{ item.revokeCredit == 1 ? t("surplusList.Item5") :
  53. t("surplusList.item6") }}</view>
  54. <view class="card-desc">{{ t("surplusList.item4") }}</view>
  55. </view>
  56. </view>
  57. <view class="data-card">
  58. <view class="card-content">
  59. <view class="card-value">{{ item.needVolume || 0 }}</view>
  60. <view class="card-desc">{{ t("UtaskList.Item5") }}</view>
  61. </view>
  62. </view>
  63. <view class="data-card">
  64. <view class="card-content">
  65. <view class="card-value">{{ item.amount }}</view>
  66. <view class="card-desc">{{ t("UtaskList.item14") }}</view>
  67. </view>
  68. </view>
  69. <view class="data-card">
  70. <view class="card-content">
  71. <view class="card-value">{{ item.endTime }}</view>
  72. <view class="card-desc">{{ t("wallet.item55") }}</view>
  73. </view>
  74. </view>
  75. <view class="data-card">
  76. <view class="card-content">
  77. <view class="card-value">{{ item.endDate }}</view>
  78. <view class="card-desc">{{ t("UtaskList.item10") }}</view>
  79. </view>
  80. </view>
  81. <view class="data-card" v-show="shouldShowCard(item, item)">
  82. <button v-if="item.status === 1 && item.revokeCredit === 2" type="primary" size="small"
  83. @click="completeTask(item.id)" :loading="loadingStates[item.id] === 'complete'">
  84. {{ t("surplusList.item7") }}
  85. </button>
  86. <button v-if="item.status === 1" type="danger" size="small" @click="cancelTask(item.id)"
  87. :loading="loadingStates[item.id] === 'cancel'">
  88. {{ t("Btn.Cancel") }}
  89. </button>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. <cwg-confirm-popup />
  97. </cwg-page-wrapper>
  98. </template>
  99. <script setup lang="ts">
  100. import { ref, computed, onMounted, watch } from 'vue'
  101. import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  102. import { useI18n } from 'vue-i18n'
  103. import { activityApi } from "@/service/activity"
  104. import Config from "@/config/index"
  105. import { useConfirm } from '@/hooks/useConfirm'
  106. const confirm = useConfirm()
  107. const { t, locale } = useI18n()
  108. let { Code } = Config
  109. // ---------- 存储辅助函数(模拟原 Session) ----------
  110. const Session = {
  111. Get(key: string, parse = false) {
  112. const value = uni.getStorageSync(key)
  113. if (parse && value) {
  114. try {
  115. return JSON.parse(value)
  116. } catch {
  117. return value
  118. }
  119. }
  120. return value
  121. }
  122. }
  123. // ---------- 响应式数据 ----------
  124. const flag = ref(false)
  125. const reasons = ref({})
  126. const pictLoading = ref(false)
  127. const tableData = ref<any[]>([])
  128. const time = ref("")
  129. const loadingStates = ref<Record<string, string | null>>({})
  130. // 卡片数据
  131. const totalTasks = ref(0)
  132. const totalRewards = ref(0)
  133. const completionRate = ref("0")
  134. const inProgressTasks = ref(0)
  135. const completedTasks = ref(0)
  136. const expiredTasks = ref(0)
  137. const rejectedTasks = ref(0)
  138. const todayRewards = ref(0)
  139. const weekRewards = ref(0)
  140. const monthRewards = ref(0)
  141. const activityLevel = ref("0")
  142. // 原 watch 中依赖的 search(保留)
  143. const search = ref({ type: "" })
  144. // ---------- 计算属性 ----------
  145. const expireTime = computed(() => {
  146. return JSON.parse(Session.Get("user", true))
  147. })
  148. // 注意:document.body.clientWidth 在 uni-app 中不可用,改为获取屏幕宽度
  149. const getScreenWidth = () => {
  150. const systemInfo = uni.getSystemInfoSync()
  151. return systemInfo.windowWidth
  152. }
  153. const lang = computed(() => {
  154. return (Session.Get("lang") == "en" && getScreenWidth() < 1330)
  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 canPerformAction = (task: any) => {
  169. return task.status === 1 || (task.status === 2 && task.withdrawStatus === 1)
  170. }
  171. const shouldShowCard = (el: any) => {
  172. const hasRecoverCreditButton = el.status === 1 && el.revokeCredit === 2
  173. const hasCancelButton = el.status === 1
  174. return hasRecoverCreditButton || hasCancelButton
  175. }
  176. // 恢复信用
  177. const completeTask = async (id: number) => {
  178. try {
  179. await confirm({
  180. title: t("Msg.SystemPrompt"),
  181. content: t("surplusList.item9"),
  182. confirmText: t("Btn.Confirm"),
  183. cancelText: t("Btn.Cancel"),
  184. })
  185. const res = await activityApi.ActivitySurplusRecoverCredit({ id })
  186. if (res.code == Code.StatusOK) {
  187. uni.showToast({ title: t("UtaskList.item9"), icon: "success" })
  188. searchFunc()
  189. } else {
  190. uni.showToast({ title: res.msg, icon: "none" })
  191. }
  192. } catch (error) {
  193. if (error?.msg) uni.showToast({ title: error.msg, icon: "none" })
  194. }
  195. }
  196. // 提现
  197. const withdrawTask = async (id: number) => {
  198. return new Promise(async (resolve) => {
  199. const resConfirm = await uni.showModal({
  200. title: t("Msg.SystemPrompt"),
  201. content: t("UtaskList.item15"),
  202. confirmText: t("Btn.Confirm"),
  203. cancelText: t("Btn.Cancel"),
  204. })
  205. if (!resConfirm.confirm) return resolve(null)
  206. loadingStates.value[id] = "withdraw"
  207. try {
  208. const res = await activityApi.UcoinWithdraw({ id })
  209. if (res.code == Code.StatusOK) {
  210. uni.showToast({ title: t("Msg.Success"), icon: "success" })
  211. searchFunc()
  212. } else {
  213. uni.showToast({ title: res.msg, icon: "none" })
  214. }
  215. } catch (error) {
  216. uni.showToast({ title: t("Msg.Fail"), icon: "none" })
  217. } finally {
  218. loadingStates.value[id] = null
  219. resolve(null)
  220. }
  221. })
  222. }
  223. // 取消任务
  224. const cancelTask = async (id: number) => {
  225. try {
  226. await confirm({
  227. title: t("Msg.SystemPrompt"),
  228. content: t("UtaskList.item8"),
  229. confirmText: t("Btn.Confirm"),
  230. cancelText: t("Btn.Cancel"),
  231. })
  232. const res = await activityApi.ActivityMonthlyCancel({ id })
  233. if (res.code == Code.StatusOK) {
  234. uni.showToast({ title: t("UtaskList.item9"), icon: "success" })
  235. searchFunc()
  236. } else {
  237. uni.showToast({ title: res.msg, icon: "none" })
  238. }
  239. } catch (error) {
  240. if (error?.msg) uni.showToast({ title: error.msg, icon: "none" })
  241. }
  242. }
  243. // 查看任务进度
  244. const viewTaskProgress = async (id: number) => {
  245. loadingStates.value[id] = "progress"
  246. try {
  247. const res = await activityApi.UcoinProgress()
  248. if (res.code == Code.StatusOK) {
  249. uni.showToast({ title: res.msg, icon: "none" })
  250. } else {
  251. uni.showToast({ title: res.msg, icon: "none" })
  252. }
  253. } catch (error) {
  254. uni.showToast({ title: t("Msg.Fail"), icon: "none" })
  255. } finally {
  256. loadingStates.value[id] = null
  257. }
  258. }
  259. // 计算卡片数据
  260. const calculateCardData = () => {
  261. // 可根据需求实现
  262. }
  263. // 返回活动
  264. const backActivity = () => {
  265. uni.navigateTo({ url: "/customer/activities" })
  266. }
  267. // 获取列表
  268. const searchFunc = async () => {
  269. if (flag.value) return
  270. flag.value = true
  271. pictLoading.value = true
  272. let res = await activityApi.ActivitySurplusTaskList()
  273. if (res.code == Code.StatusOK) {
  274. tableData.value = res.data
  275. calculateCardData()
  276. pictLoading.value = false
  277. flag.value = false
  278. } else {
  279. uni.showToast({ title: res.msg, icon: "none" })
  280. pictLoading.value = false
  281. flag.value = false
  282. }
  283. }
  284. // ---------- 生命周期与监听 ----------
  285. onMounted(() => {
  286. searchFunc()
  287. })
  288. // 原 watch(保留)
  289. watch(
  290. () => search.value.type,
  291. () => {
  292. searchFunc()
  293. }
  294. )
  295. </script>
  296. <style lang="scss" scoped>
  297. @import "@/uni.scss";
  298. #custom_history {
  299. width: 100%;
  300. height: 100%;
  301. .no-data-container {
  302. display: flex;
  303. justify-content: center;
  304. align-items: center;
  305. height: px2rpx(300);
  306. .no-data-content {
  307. text-align: center;
  308. color: var(--bs-heading-color);
  309. i {
  310. font-size: px2rpx(48);
  311. margin-bottom: px2rpx(16);
  312. display: block;
  313. }
  314. p {
  315. font-size: px2rpx(16);
  316. margin: 0;
  317. }
  318. }
  319. }
  320. .main-content {
  321. width: 100%;
  322. height: calc(100% - 50px);
  323. // @include bg_white();
  324. padding: px2rpx(20);
  325. box-sizing: border-box;
  326. overflow: hidden;
  327. overflow-y: auto;
  328. }
  329. .state.btn {
  330. background: #eb3f57;
  331. color: white;
  332. padding: px2rpx(3) px2rpx(15);
  333. border-radius: px2rpx(4);
  334. }
  335. .action-buttons {
  336. display: flex;
  337. flex-direction: column;
  338. gap: px2rpx(8);
  339. align-items: center;
  340. .el-button {
  341. min-width: px2rpx(80);
  342. font-size: px2rpx(12);
  343. }
  344. .status-text {
  345. font-size: px2rpx(14);
  346. color: var(--bs-heading-color);
  347. font-weight: 500;
  348. }
  349. }
  350. // 外层卡片样式
  351. .outer-card {
  352. background: #ffffff;
  353. border-radius: px2rpx(16);
  354. padding: px2rpx(24);
  355. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  356. border: 1px solid #f0f0f0;
  357. margin-bottom: px2rpx(30);
  358. }
  359. // 数据卡片样式
  360. .data-cards {
  361. display: flex;
  362. flex-direction: column;
  363. gap: px2rpx(20);
  364. .total-data-row {
  365. display: grid;
  366. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  367. gap: px2rpx(15);
  368. }
  369. .sub-data-row {
  370. display: grid;
  371. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  372. gap: px2rpx(15);
  373. }
  374. .data-card {
  375. background: #ffffff;
  376. border-radius: px2rpx(12);
  377. padding: px2rpx(24);
  378. // box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  379. border: 1px solid #f0f0f0;
  380. transition: all 0.3s ease;
  381. text-align: center;
  382. &:hover {
  383. transform: translateY(-2px);
  384. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  385. }
  386. // 根据状态设置背景色
  387. &.status-1 {
  388. background: #fff7e6; // 任务中 - 黄色背景
  389. border-color: #ffd591;
  390. }
  391. &.status-2 {
  392. background: #f6ffed; // 已完成 - 绿色背景
  393. border-color: #b7eb8f;
  394. }
  395. &.status-3,
  396. &.status-4 {
  397. background: #f5f5f5; // 已取消/已结束 - 灰色背景
  398. border-color: #d9d9d9;
  399. }
  400. &.total-card {
  401. background: #ffffff;
  402. color: var(--bs-heading-color);
  403. // border: 1px solid gray;
  404. .card-value {
  405. color: var(--bs-heading-color);
  406. }
  407. .card-desc {
  408. color: var(--bs-heading-color);
  409. }
  410. // 状态卡片的特殊样式
  411. &.status-1 {
  412. background: #fff7e6;
  413. border-color: #ffd591;
  414. }
  415. &.status-2 {
  416. background: #f6ffed;
  417. border-color: #b7eb8f;
  418. }
  419. &.status-3,
  420. &.status-4 {
  421. background: #f5f5f5;
  422. border-color: #d9d9d9;
  423. }
  424. }
  425. &.sub-card {
  426. background: #ffffff;
  427. border-left: px2rpx(4) solid #667eea;
  428. &:nth-child(2) {
  429. border-left-color: #52c41a;
  430. }
  431. &:nth-child(3) {
  432. border-left-color: #faad14;
  433. }
  434. &:nth-child(4) {
  435. border-left-color: #ff4d4f;
  436. }
  437. }
  438. .card-content {
  439. .card-title {
  440. font-size: px2rpx(16);
  441. color: var(--bs-heading-color);
  442. margin-bottom: px2rpx(8);
  443. font-weight: 500;
  444. }
  445. .card-value {
  446. font-size: px2rpx(18);
  447. font-weight: 700;
  448. color: var(--bs-heading-color);
  449. margin-bottom: px2rpx(4);
  450. line-height: 1;
  451. }
  452. .card-desc {
  453. font-size: px2rpx(12);
  454. color: var(--bs-heading-color);
  455. line-height: 1.4;
  456. }
  457. }
  458. }
  459. .btn-card {
  460. display: flex;
  461. justify-content: center;
  462. align-items: center;
  463. flex-direction: column;
  464. gap: px2rpx(10);
  465. button {
  466. width: 100%;
  467. }
  468. }
  469. }
  470. // 响应式设计
  471. @media (max-width: 768px) {
  472. .data-cards {
  473. .total-data-row,
  474. .sub-data-row {
  475. grid-template-columns: 1fr;
  476. }
  477. .data-card {
  478. padding: px2rpx(16);
  479. .card-content {
  480. .card-value {
  481. font-size: px2rpx(24);
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. </style>