surplus-list.vue 18 KB

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