| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550 |
- <template>
- <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
- <cwg-header :title="t('wallet.item52')" />
- <view id="custom_history" class="">
- <view class="main-content">
- <!-- 无任务列表提示 -->
- <cwg-empty-state v-if="!tableData || tableData.length === 0" title="UtaskList.item12" />
- <!-- 数据卡片展示 -->
- <view class="outer-card" v-for="(item, index) in tableData" :key="index"
- v-show="tableData && tableData.length > 0">
- <view class="data-cards">
- <!-- 第一行:总数据 -->
- <view class="total-data-row">
- <view class="data-card total-card">
- <view class="card-content">
- <view class="card-title">{{ t("UtaskList.item13") }}</view>
- <view class="card-value" style="color: #ff4d4f">
- {{ item.depositAmount || 0 }}
- </view>
- </view>
- </view>
- <view class="data-card total-card">
- <view class="card-content">
- <view class="card-title">{{ t("UtaskList.item3") }}</view>
- <view class="card-value" style="color: #ff4d4f">
- {{ item.completeVolume || 0 }}
- </view>
- </view>
- </view>
- <view class="data-card total-card">
- <view class="card-content">
- <view class="card-title">{{ t("surplusList.item8") }}</view>
- <view class="card-value" style="color: #ff4d4f">
- {{ item.amount }}
- </view>
- </view>
- </view>
- <view class="data-card total-card">
- <view class="card-content">
- <view class="card-title">{{ t("Label.State") }}</view>
- <view class="card-value" :style="item.status == 1 ? 'color: #ffd591;' : 'color: #52c41a;'
- ">
- {{ item.status == 1 ? t("State.Ongoing") : t("State.Completed") }}
- </view>
- </view>
- </view>
- </view>
- <!-- 第二行:分数据 -->
- <view class="sub-data-row">
- <view class="data-card">
- <view class="card-content">
- <view class="card-value">{{ item.revokeCredit == 1 ? t("surplusList.Item5") :
- t("surplusList.item6") }}</view>
- <view class="card-desc">{{ t("surplusList.item4") }}</view>
- </view>
- </view>
- <view class="data-card">
- <view class="card-content">
- <view class="card-value">{{ item.needVolume || 0 }}</view>
- <view class="card-desc">{{ t("UtaskList.Item5") }}</view>
- </view>
- </view>
- <view class="data-card">
- <view class="card-content">
- <view class="card-value">{{ item.amount }}</view>
- <view class="card-desc">{{ t("UtaskList.item14") }}</view>
- </view>
- </view>
- <view class="data-card">
- <view class="card-content">
- <view class="card-value">{{ item.endTime }}</view>
- <view class="card-desc">{{ t("wallet.item55") }}</view>
- </view>
- </view>
- <view class="data-card">
- <view class="card-content">
- <view class="card-value">{{ item.endDate }}</view>
- <view class="card-desc">{{ t("UtaskList.item10") }}</view>
- </view>
- </view>
- <view class="data-card" v-show="shouldShowCard(item, item)">
- <button v-if="item.status === 1 && item.revokeCredit === 2" type="primary" size="small"
- @click="completeTask(item.id)" :loading="loadingStates[item.id] === 'complete'">
- {{ t("surplusList.item7") }}
- </button>
- <button v-if="item.status === 1" type="danger" size="small" @click="cancelTask(item.id)"
- :loading="loadingStates[item.id] === 'cancel'">
- {{ t("Btn.Cancel") }}
- </button>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <cwg-confirm-popup />
- </cwg-page-wrapper>
- </template>
- <script setup lang="ts">
- import { ref, computed, onMounted, watch } from 'vue'
- import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
- import { useI18n } from 'vue-i18n'
- import { activityApi } from "@/service/activity"
- import Config from "@/config/index"
- import { useConfirm } from '@/hooks/useConfirm'
- const confirm = useConfirm()
- const { t, locale } = useI18n()
- let { Code } = Config
- // ---------- 存储辅助函数(模拟原 Session) ----------
- const Session = {
- Get(key: string, parse = false) {
- const value = uni.getStorageSync(key)
- if (parse && value) {
- try {
- return JSON.parse(value)
- } catch {
- return value
- }
- }
- return value
- }
- }
- // ---------- 响应式数据 ----------
- const flag = ref(false)
- const reasons = ref({})
- const pictLoading = ref(false)
- const tableData = ref<any[]>([])
- const time = ref("")
- const loadingStates = ref<Record<string, string | null>>({})
- // 卡片数据
- const totalTasks = ref(0)
- const totalRewards = ref(0)
- const completionRate = ref("0")
- const inProgressTasks = ref(0)
- const completedTasks = ref(0)
- const expiredTasks = ref(0)
- const rejectedTasks = ref(0)
- const todayRewards = ref(0)
- const weekRewards = ref(0)
- const monthRewards = ref(0)
- const activityLevel = ref("0")
- // 原 watch 中依赖的 search(保留)
- const search = ref({ type: "" })
- // ---------- 计算属性 ----------
- const expireTime = computed(() => {
- return JSON.parse(Session.Get("user", true))
- })
- // 注意:document.body.clientWidth 在 uni-app 中不可用,改为获取屏幕宽度
- const getScreenWidth = () => {
- const systemInfo = uni.getSystemInfoSync()
- return systemInfo.windowWidth
- }
- const lang = computed(() => {
- return (Session.Get("lang") == "en" && getScreenWidth() < 1330)
- })
- // ---------- 方法 ----------
- const getStatus = (status: number) => {
- if (status == 1) {
- return t("State.Ongoing")
- } else if (status == 2) {
- return t("State.Completed")
- } else if (status == 3) {
- return t("State.Cancelled")
- } else if (status == 4) {
- return t("State.expireTime")
- }
- }
- const canPerformAction = (task: any) => {
- return task.status === 1 || (task.status === 2 && task.withdrawStatus === 1)
- }
- const shouldShowCard = (el: any) => {
- const hasRecoverCreditButton = el.status === 1 && el.revokeCredit === 2
- const hasCancelButton = el.status === 1
- return hasRecoverCreditButton || hasCancelButton
- }
- // 恢复信用
- const completeTask = async (id: number) => {
- try {
- await confirm({
- title: t("Msg.SystemPrompt"),
- content: t("surplusList.item9"),
- confirmText: t("Btn.Confirm"),
- cancelText: t("Btn.Cancel"),
- })
- const res = await activityApi.ActivitySurplusRecoverCredit({ id })
- if (res.code == Code.StatusOK) {
- uni.showToast({ title: t("UtaskList.item9"), icon: "success" })
- searchFunc()
- } else {
- uni.showToast({ title: res.msg, icon: "none" })
- }
- } catch (error) {
- if (error?.msg) uni.showToast({ title: error.msg, icon: "none" })
- }
- }
- // 提现
- const withdrawTask = async (id: number) => {
- return new Promise(async (resolve) => {
- const resConfirm = await uni.showModal({
- title: t("Msg.SystemPrompt"),
- content: t("UtaskList.item15"),
- confirmText: t("Btn.Confirm"),
- cancelText: t("Btn.Cancel"),
- })
- if (!resConfirm.confirm) return resolve(null)
- loadingStates.value[id] = "withdraw"
- try {
- const res = await activityApi.UcoinWithdraw({ id })
- if (res.code == Code.StatusOK) {
- uni.showToast({ title: t("Msg.Success"), icon: "success" })
- searchFunc()
- } else {
- uni.showToast({ title: res.msg, icon: "none" })
- }
- } catch (error) {
- uni.showToast({ title: t("Msg.Fail"), icon: "none" })
- } finally {
- loadingStates.value[id] = null
- resolve(null)
- }
- })
- }
- // 取消任务
- const cancelTask = async (id: number) => {
- try {
- await confirm({
- title: t("Msg.SystemPrompt"),
- content: t("UtaskList.item8"),
- confirmText: t("Btn.Confirm"),
- cancelText: t("Btn.Cancel"),
- })
- const res = await activityApi.ActivityMonthlyCancel({ id })
- if (res.code == Code.StatusOK) {
- uni.showToast({ title: t("UtaskList.item9"), icon: "success" })
- searchFunc()
- } else {
- uni.showToast({ title: res.msg, icon: "none" })
- }
- } catch (error) {
- if (error?.msg) uni.showToast({ title: error.msg, icon: "none" })
- }
- }
- // 查看任务进度
- const viewTaskProgress = async (id: number) => {
- loadingStates.value[id] = "progress"
- try {
- const res = await activityApi.UcoinProgress()
- if (res.code == Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: "none" })
- } else {
- uni.showToast({ title: res.msg, icon: "none" })
- }
- } catch (error) {
- uni.showToast({ title: t("Msg.Fail"), icon: "none" })
- } finally {
- loadingStates.value[id] = null
- }
- }
- // 计算卡片数据
- const calculateCardData = () => {
- // 可根据需求实现
- }
- // 返回活动
- const backActivity = () => {
- uni.navigateTo({ url: "/customer/activities" })
- }
- // 获取列表
- const searchFunc = async () => {
- if (flag.value) return
- flag.value = true
- pictLoading.value = true
- let res = await activityApi.ActivitySurplusTaskList()
- if (res.code == Code.StatusOK) {
- tableData.value = res.data
- calculateCardData()
- pictLoading.value = false
- flag.value = false
- } else {
- uni.showToast({ title: res.msg, icon: "none" })
- pictLoading.value = false
- flag.value = false
- }
- }
- // ---------- 生命周期与监听 ----------
- onMounted(() => {
- searchFunc()
- })
- // 原 watch(保留)
- watch(
- () => search.value.type,
- () => {
- searchFunc()
- }
- )
- </script>
- <style lang="scss" scoped>
- @import "@/uni.scss";
- #custom_history {
- width: 100%;
- height: 100%;
- .no-data-container {
- display: flex;
- justify-content: center;
- align-items: center;
- height: px2rpx(300);
- .no-data-content {
- text-align: center;
- color: var(--bs-heading-color);
- i {
- font-size: px2rpx(48);
- margin-bottom: px2rpx(16);
- display: block;
- }
- p {
- font-size: px2rpx(16);
- margin: 0;
- }
- }
- }
- .main-content {
- width: 100%;
- height: calc(100% - 50px);
- // @include bg_white();
- padding: px2rpx(20);
- box-sizing: border-box;
- overflow: hidden;
- overflow-y: auto;
- }
- .state.btn {
- background: #eb3f57;
- color: white;
- padding: px2rpx(3) px2rpx(15);
- border-radius: px2rpx(4);
- }
- .action-buttons {
- display: flex;
- flex-direction: column;
- gap: px2rpx(8);
- align-items: center;
- .el-button {
- min-width: px2rpx(80);
- font-size: px2rpx(12);
- }
- .status-text {
- font-size: px2rpx(14);
- color: var(--bs-heading-color);
- font-weight: 500;
- }
- }
- // 外层卡片样式
- .outer-card {
- background: #ffffff;
- border-radius: px2rpx(16);
- padding: px2rpx(24);
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
- border: 1px solid #f0f0f0;
- margin-bottom: px2rpx(30);
- }
- // 数据卡片样式
- .data-cards {
- display: flex;
- flex-direction: column;
- gap: px2rpx(20);
- .total-data-row {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
- gap: px2rpx(15);
- }
- .sub-data-row {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
- gap: px2rpx(15);
- }
- .data-card {
- background: #ffffff;
- border-radius: px2rpx(12);
- padding: px2rpx(24);
- // box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
- border: 1px solid #f0f0f0;
- transition: all 0.3s ease;
- text-align: center;
- &:hover {
- transform: translateY(-2px);
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
- }
- // 根据状态设置背景色
- &.status-1 {
- background: #fff7e6; // 任务中 - 黄色背景
- border-color: #ffd591;
- }
- &.status-2 {
- background: #f6ffed; // 已完成 - 绿色背景
- border-color: #b7eb8f;
- }
- &.status-3,
- &.status-4 {
- background: #f5f5f5; // 已取消/已结束 - 灰色背景
- border-color: #d9d9d9;
- }
- &.total-card {
- background: #ffffff;
- color: var(--bs-heading-color);
- // border: 1px solid gray;
- .card-value {
- color: var(--bs-heading-color);
- }
- .card-desc {
- color: var(--bs-heading-color);
- }
- // 状态卡片的特殊样式
- &.status-1 {
- background: #fff7e6;
- border-color: #ffd591;
- }
- &.status-2 {
- background: #f6ffed;
- border-color: #b7eb8f;
- }
- &.status-3,
- &.status-4 {
- background: #f5f5f5;
- border-color: #d9d9d9;
- }
- }
- &.sub-card {
- background: #ffffff;
- border-left: px2rpx(4) solid #667eea;
- &:nth-child(2) {
- border-left-color: #52c41a;
- }
- &:nth-child(3) {
- border-left-color: #faad14;
- }
- &:nth-child(4) {
- border-left-color: #ff4d4f;
- }
- }
- .card-content {
- .card-title {
- font-size: px2rpx(16);
- color: var(--bs-heading-color);
- margin-bottom: px2rpx(8);
- font-weight: 500;
- }
- .card-value {
- font-size: px2rpx(18);
- font-weight: 700;
- color: var(--bs-heading-color);
- margin-bottom: px2rpx(4);
- line-height: 1;
- }
- .card-desc {
- font-size: px2rpx(12);
- color: var(--bs-heading-color);
- line-height: 1.4;
- }
- }
- }
- .btn-card {
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- gap: px2rpx(10);
- button {
- width: 100%;
- }
- }
- }
- // 响应式设计
- @media (max-width: 768px) {
- .data-cards {
- .total-data-row,
- .sub-data-row {
- grid-template-columns: 1fr;
- }
- .data-card {
- padding: px2rpx(16);
- .card-content {
- .card-value {
- font-size: px2rpx(24);
- }
- }
- }
- }
- }
- }
- </style>
|