surplus-list.vue 17 KB

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