| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709 |
- <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("Label.State") }}</view>
- <view class="card-value" :style="getStatusStyle(item.status)">
- {{ getStatusText(item.status) }}
- </view>
- </view>
- </view>
- <view class="data-card total-card" v-if="item.status === 2">
- <view class="card-content">
- <view class="card-title">
- {{ t("MonthlyActivities.item4") }}
- </view>
- <view class="card-value" :style="getGiveStatusStyle(item.giveStatus)">
- {{ getGiveStatusText(item.giveStatus) }}
- </view>
- </view>
- </view>
- </view>
- <!-- 第二行:分数据 -->
- <view class="sub-data-row">
- <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-if="item.status === 2">
- <view class="card-content">
- <view class="card-value">{{ item.applyTime }}</view>
- <view class="card-desc">{{ t("MonthlyActivities.item6") }}</view>
- </view>
- </view>
- <view class="data-card" v-if="item.status === 2">
- <view class="card-content">
- <view class="card-value">{{ item.grantTime }}</view>
- <view class="card-desc">{{ t("MonthlyActivities.item7") }}</view>
- </view>
- </view>
- <view class="data-card" v-if="item.logisticsOrder">
- <view class="card-content">
- <view class="card-value">{{ item.logisticsOrder }}</view>
- <view class="card-desc">{{ t("MonthlyActivities.item9") }}</view>
- </view>
- </view>
- <view class="data-card btn-card" v-show="shouldShowCard(item, item)">
- <!-- 取消按钮 - status为1时显示 -->
- <button v-if="item.status === 1" type="danger" size="small" @click="cancelTask(item.id)"
- :loading="loadingStates[item.id] === 'cancel'">
- {{ t("Btn.Cancel") }}
- </button>
- <!-- 礼物申请按钮 - status为2且giveStatus为1时显示 -->
- <button v-if="item.status === 2 && item.giveStatus === 1 && lang1" type="primary"
- size="small" @click="applyGift(item.id)"
- :loading="loadingStates[item.id] === 'applyGift'">
- {{ t("Btn.Application") }}
- </button>
- </view>
- </view>
- <!-- 提示信息 -->
- <view class="tip-info" style="padding: 10px 0; color: #909399; font-size: 14px">
- {{ t("MonthlyActivities.item10") }}
- </view>
- </view>
- </view>
- </view>
- <!-- 礼物申请对话框 -->
- <GiftApplicationPopup v-model:visible="dialogGiftApplication" :title="t('Btn.Application')"
- :giftList="giftList" :giftForm="giftForm" @confirm="submitGiftApply" />
- </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 GiftApplicationPopup from "./components/GiftApplicationPopup.vue"
- 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")
- // 礼物申请对话框相关
- const dialogGiftApplication = ref(false)
- const giftList = ref<any[]>([])
- const giftForm = ref({
- id: null as number | null,
- giveCode: "",
- giveName: "",
- giveAddress: "",
- givePhone: "",
- giveAcceptName: "",
- })
- const giftSubmitting = ref(false)
- // 原 watch 中依赖的 search(保留)
- const search = ref({ type: "" })
- // ---------- 计算属性 ----------
- const expireTime = computed(() => {
- return Session.Get("user", true)
- })
- const lang = computed(() => {
- return (Session.Get("lang") == "en" && document.body.clientWidth < 1330)
- })
- // 注意:document 在 uni-app 中不可用,此处保留原逻辑但需注意运行环境
- // 若需兼容,可改用 uni.getSystemInfoSync().windowWidth
- const lang1 = computed(() => {
- const user = Session.Get("user", true)
- return user?.customInfo?.country == "CN"
- })
- // ---------- 方法 ----------
- 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 getStatusText = (status: number) => {
- if (status == 1) {
- return t("State.InTask")
- } else if (status == 2) {
- return t("UtaskList.item6")
- } else if (status == 3) {
- return t("State.Cancelled")
- } else if (status == 4) {
- return t("State.Ended")
- }
- return ""
- }
- const getStatusStyle = (status: number) => {
- if (status == 1) {
- return "color: #ffd591;"
- } else if (status == 2) {
- return "color: #52c41a;"
- } else if (status == 3) {
- return "color: #999999;"
- } else if (status == 4) {
- return "color: #999999;"
- }
- return "color: #333;"
- }
- const getGiveStatusText = (giveStatus: number) => {
- if (giveStatus == 1) {
- return t("State.NotApply")
- } else if (giveStatus == 2) {
- return t("State.Applied")
- } else if (giveStatus == 3) {
- return t("State.Granted")
- }
- return ""
- }
- const getGiveStatusStyle = (giveStatus: number) => {
- if (giveStatus == 1) {
- return "color: #999999;"
- } else if (giveStatus == 2) {
- return "color: #1890ff;"
- } else if (giveStatus == 3) {
- return "color: #52c41a;"
- }
- return "color: #333;"
- }
- const canPerformAction = (task: any) => {
- return task.status === 1 || (task.status === 2 && task.withdrawStatus === 1)
- }
- const shouldShowCard = (el: any) => {
- const hasCancelButton = el.status === 1
- const hasGiftApplyButton = el.status === 2 && el.giveStatus === 1 && lang1.value
- return hasCancelButton || hasGiftApplyButton
- }
- // 恢复信用(原 completeTask)
- const completeTask = async (id: number) => {
- return new Promise(async (resolve) => {
- const resConfirm = await uni.showModal({
- title: t("Msg.SystemPrompt"),
- content: t("surplusList.item9"),
- confirmText: t("Btn.Confirm"),
- cancelText: t("Btn.Cancel"),
- })
- if (!resConfirm.confirm) return resolve(null)
- loadingStates.value[id] = "complete"
- try {
- const res = await activityApi.ActivitySurplusRecoverCredit({ 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 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) {
- 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 applyGift = async (id: number) => {
- // 重置表单
- giftForm.value = {
- id: id,
- giveCode: "",
- giveName: "",
- giveAddress: "",
- givePhone: "",
- giveAcceptName: "",
- }
- giftList.value = []
- // 获取礼品列表
- try {
- const res = await activityApi.ActivityMonthlyGiveList({ id })
- if (res.code == Code.StatusOK) {
- giftList.value = res.data || []
- dialogGiftApplication.value = true
- } else {
- uni.showToast({ title: res.msg, icon: "none" })
- }
- } catch (error) {
- uni.showToast({ title: t("Msg.Fail"), icon: "none" })
- }
- }
- // 处理礼品选择变化
- const handleGiftChange = (giveCode: string) => {
- const selectedGift = giftList.value.find(gift => gift.giveCode === giveCode)
- if (selectedGift) {
- giftForm.value.giveName = selectedGift.giveName
- }
- }
- // 提交礼物申请
- const submitGiftApply = async (form) => {
- // 表单验证(假设模板中有 ref="giftForm" 的 uni-forms 组件)
- // 这里需要适配实际验证方式,简化起见调用一个验证函数,若验证失败则返回
- // 由于 uni-app 中没有直接提供 validate,需根据实际组件实现,此处保留原逻辑结构
- // 实际使用时请配合 uni-forms 或自定义验证
- const valid = true // 占位,实际需调用 this.$refs.giftForm.validate()
- if (!valid) return
- const resConfirm = await uni.showModal({
- title: t("Msg.SystemPrompt"),
- content: t("MonthlyActivities.item10"),
- confirmText: t("Btn.Confirm"),
- cancelText: t("Btn.Cancel"),
- })
- if (!resConfirm.confirm) return
- giftSubmitting.value = true
- try {
- const res = await activityApi.ActivityMonthlyGiveApply({
- id: giftForm.value.id,
- giveCode: form.giveCode,
- giveName: form.giveName,
- giveAddress: form.giveAddress.trim(),
- givePhone: form.givePhone.trim(),
- })
- if (res.code == Code.StatusOK) {
- // uni.showToast({ title: t("Msg.Success"), icon: "success" })
- dialogGiftApplication.value = false
- searchFunc()
- } else {
- uni.showToast({ title: res.msg, icon: "none" })
- }
- } catch (error) {
- uni.showToast({ title: t("Msg.Fail"), icon: "none" })
- } finally {
- giftSubmitting.value = false
- }
- }
- // 查看任务进度
- 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.navigateBack()
- }
- // 获取列表
- const searchFunc = async () => {
- if (flag.value) return
- flag.value = true
- pictLoading.value = true
- let res = await activityApi.ActivityMonthlyTaskList()
- if (res.code == Code.StatusOK) {
- tableData.value = res.data
- calculateCardData()
- // uni.showToast({ title: t("Msg.SearchSuccess"), icon: "success" })
- 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()
- }
- )
- // 若需要 uni-app 页面生命周期可额外添加 onShow 等
- // onShow(() => {})
- </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: #999;
- 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: #666;
- 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: #333;
- // border: 1px solid gray;
- .card-value {
- color: #333;
- }
- .card-desc {
- color: #999;
- }
- // 状态卡片的特殊样式
- &.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: #666;
- margin-bottom: px2rpx(8);
- font-weight: 500;
- }
- .card-value {
- font-size: px2rpx(18);
- font-weight: 700;
- color: #333;
- margin-bottom: px2rpx(4);
- line-height: 1;
- }
- .card-desc {
- font-size: px2rpx(12);
- color: #999;
- 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>
|