surplus-list.vue 18 KB

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