surplus-list.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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 class="btn btn-primary waves-effect waves-light" 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 class="btn btn-dark waves-effect waves-light btn-outline-dark1" v-if="item.status === 1" @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, onUnmounted } 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. onUnmounted(() => {
  289. searchFunc()
  290. })
  291. // 原 watch(保留)
  292. watch(
  293. () => search.value.type,
  294. () => {
  295. searchFunc()
  296. }
  297. )
  298. </script>
  299. <style lang="scss" scoped>
  300. @import "@/uni.scss";
  301. #custom_history {
  302. width: 100%;
  303. height: 100%;
  304. .no-data-container {
  305. display: flex;
  306. justify-content: center;
  307. align-items: center;
  308. height: px2rpx(300);
  309. .no-data-content {
  310. text-align: center;
  311. color: var(--bs-heading-color);
  312. i {
  313. font-size: px2rpx(48);
  314. margin-bottom: px2rpx(16);
  315. display: block;
  316. }
  317. p {
  318. font-size: px2rpx(16);
  319. margin: 0;
  320. }
  321. }
  322. }
  323. .main-content {
  324. width: 100%;
  325. height: calc(100% - 50px);
  326. // @include bg_white();
  327. padding: px2rpx(20);
  328. box-sizing: border-box;
  329. overflow: hidden;
  330. overflow-y: auto;
  331. }
  332. .state.btn {
  333. background: #eb3f57;
  334. color: white;
  335. padding: px2rpx(3) px2rpx(15);
  336. border-radius: px2rpx(4);
  337. }
  338. .action-buttons {
  339. display: flex;
  340. flex-direction: column;
  341. gap: px2rpx(8);
  342. align-items: center;
  343. .el-button {
  344. min-width: px2rpx(80);
  345. font-size: px2rpx(12);
  346. }
  347. .status-text {
  348. font-size: px2rpx(14);
  349. color: var(--bs-heading-color);
  350. font-weight: 500;
  351. }
  352. }
  353. // 外层卡片样式
  354. .outer-card {
  355. background: #ffffff;
  356. border-radius: px2rpx(16);
  357. padding: px2rpx(24);
  358. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  359. border: 1px solid #f0f0f0;
  360. margin-bottom: px2rpx(30);
  361. }
  362. // 数据卡片样式
  363. .data-cards {
  364. display: flex;
  365. flex-direction: column;
  366. gap: px2rpx(20);
  367. .total-data-row {
  368. display: grid;
  369. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  370. gap: px2rpx(15);
  371. }
  372. .sub-data-row {
  373. display: grid;
  374. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  375. gap: px2rpx(15);
  376. }
  377. .data-card {
  378. background: #ffffff;
  379. border-radius: px2rpx(12);
  380. padding: px2rpx(24);
  381. // box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  382. border: 1px solid #f0f0f0;
  383. transition: all 0.3s ease;
  384. text-align: center;
  385. &:hover {
  386. transform: translateY(-2px);
  387. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  388. }
  389. // 根据状态设置背景色
  390. &.status-1 {
  391. background: #fff7e6; // 任务中 - 黄色背景
  392. border-color: #ffd591;
  393. }
  394. &.status-2 {
  395. background: #f6ffed; // 已完成 - 绿色背景
  396. border-color: #b7eb8f;
  397. }
  398. &.status-3,
  399. &.status-4 {
  400. background: #f5f5f5; // 已取消/已结束 - 灰色背景
  401. border-color: #d9d9d9;
  402. }
  403. &.total-card {
  404. background: #ffffff;
  405. color: var(--bs-heading-color);
  406. // border: 1px solid gray;
  407. .card-value {
  408. color: var(--bs-heading-color);
  409. }
  410. .card-desc {
  411. color: var(--bs-heading-color);
  412. }
  413. // 状态卡片的特殊样式
  414. &.status-1 {
  415. background: #fff7e6;
  416. border-color: #ffd591;
  417. }
  418. &.status-2 {
  419. background: #f6ffed;
  420. border-color: #b7eb8f;
  421. }
  422. &.status-3,
  423. &.status-4 {
  424. background: #f5f5f5;
  425. border-color: #d9d9d9;
  426. }
  427. }
  428. &.sub-card {
  429. background: #ffffff;
  430. border-left: px2rpx(4) solid #667eea;
  431. &:nth-child(2) {
  432. border-left-color: #52c41a;
  433. }
  434. &:nth-child(3) {
  435. border-left-color: #faad14;
  436. }
  437. &:nth-child(4) {
  438. border-left-color: #ff4d4f;
  439. }
  440. }
  441. .card-content {
  442. .card-title {
  443. font-size: px2rpx(16);
  444. color: var(--bs-heading-color);
  445. margin-bottom: px2rpx(8);
  446. font-weight: 500;
  447. }
  448. .card-value {
  449. font-size: px2rpx(18);
  450. font-weight: 700;
  451. color: var(--bs-heading-color);
  452. margin-bottom: px2rpx(4);
  453. line-height: 1;
  454. }
  455. .card-desc {
  456. font-size: px2rpx(12);
  457. color: var(--bs-heading-color);
  458. line-height: 1.4;
  459. }
  460. }
  461. }
  462. .btn-card {
  463. display: flex;
  464. justify-content: center;
  465. align-items: center;
  466. flex-direction: column;
  467. gap: px2rpx(10);
  468. button {
  469. width: 100%;
  470. }
  471. }
  472. }
  473. // 响应式设计
  474. @media (max-width: 768px) {
  475. .data-cards {
  476. .total-data-row,
  477. .sub-data-row {
  478. grid-template-columns: 1fr;
  479. }
  480. .data-card {
  481. padding: px2rpx(16);
  482. .card-content {
  483. .card-value {
  484. font-size: px2rpx(24);
  485. }
  486. }
  487. }
  488. }
  489. }
  490. }
  491. </style>