| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711 |
- import { ref } from 'vue'
- import { useI18n } from 'vue-i18n'
- import { activityApi } from '@/service/activity'
- import Config from '@/config/index'
- import type { AccountInfo } from '../types/activity'
- const { Code, Host80 } = Config
- export function useActivityActions(
- activityState: any,
- loginOptions: any,
- tableDataCptFlagCode: any,
- refreshCallback?: () => void
- ) {
- const { t, locale} = useI18n()
- // ==================== 弹窗状态 ====================
- const dialogChinaUnionPay = ref(false)
- const dialogChinaUnionPay1 = ref(false)
- const dialogChinaUnionPayJX = ref(false)
- const dialogDealResult = ref(false)
- const dialogDealResultJx = ref(false)
- const dialogDealResultJxVip = ref(false)
- const dialogDealResultCpt = ref(false)
- const dialogDealResultJxJYB = ref(false)
- const dialogDealResultNoWorries = ref(false)
- const dialogNoWorries = ref(false)
- const dialogNoWorriesApply = ref(false)
- const dialogNewTask = ref(false)
- const dialogNewTaskDraw = ref(false)
- const dialogSurplusActivity = ref(false)
- const dialogSurplusActivity1 = ref(false)
- const dialogInfoTradingAdd = ref(false)
- const openCalculatorFlag = ref(false)
- // ==================== 表单数据 ====================
- const dialogDealResult_form = ref({ login: '' })
- const dialogDealResultJx_form = ref({ login: '' })
- const dialogDealResultJx_formVip = ref({ login: '' })
- const dialogDealResultJx_formJYB = ref({ login: '' })
- const dialogDealResultCpt_form = ref({
- login: '',
- address: '',
- cptId: '',
- mobile: '',
- nickname: '',
- recipient: ''
- })
- const dialogDeal_formNoWorries = ref({ login: '' })
- // Surplus活动相关
- const selectedAccount = ref<AccountInfo | null>(null)
- const valueInfo = ref('')
- const surplusActivityOptions = ref<any[]>([])
- const surplusActivityLoading = ref(false)
- const selectedSurplusActivity = ref('')
- // ==================== 页面跳转 ====================
- const toSingle = (id: string, listID?: string) => {
- const specialIds = [
- '20zj', '23yx', '23jx', '23nz', '23nzTwo', '23jxVip',
- '23xinjia', '23jnhcj', '23nz_zx', '24JYB', 'NoWorries', 'NewYear24'
- ]
- if (specialIds.includes(id)) {
- let query: any = { id: '', type: 1, active: id }
- if (id === '23jx' && activityState.tableData3) {
- query = {
- ...query,
- data1: activityState.tableData3.show ? activityState.tableData3.activityStartTime : activityState.tableData3.showActivityStartTime,
- data2: activityState.tableData3.show ? activityState.tableData3.activityEndTime : activityState.tableData3.showActivityEndTime,
- data3: activityState.tableData3.show ? activityState.tableData3.applicationStartTime : activityState.tableData3.showApplicationStartTime,
- data4: activityState.tableData3.show ? activityState.tableData3.applicationEndTime : activityState.tableData3.showApplicationEndTime
- }
- } else if (id === '23jxVip' && activityState.tableData3Vip) {
- query = {
- ...query,
- data1: activityState.tableData3Vip.show ? activityState.tableData3Vip.activityStartTime : activityState.tableData3Vip.showActivityStartTime,
- data2: activityState.tableData3Vip.show ? activityState.tableData3Vip.activityEndTime : activityState.tableData3Vip.showActivityEndTime,
- data3: activityState.tableData3Vip.show ? activityState.tableData3Vip.applicationStartTime : activityState.tableData3Vip.showApplicationStartTime,
- data4: activityState.tableData3Vip.show ? activityState.tableData3Vip.applicationEndTime : activityState.tableData3Vip.showApplicationEndTime
- }
- } else if (id === '24JYB' && activityState.tableData3JYB) {
- query = {
- ...query,
- data1: activityState.tableData3JYB.show ? activityState.tableData3JYB.activityStartTime : activityState.tableData3JYB.showActivityStartTime,
- data2: activityState.tableData3JYB.show ? activityState.tableData3JYB.activityEndTime : activityState.tableData3JYB.showActivityEndTime,
- data3: activityState.tableData3JYB.show ? activityState.tableData3JYB.applicationStartTime : activityState.tableData3JYB.showApplicationStartTime,
- data4: activityState.tableData3JYB.show ? activityState.tableData3JYB.applicationEndTime : activityState.tableData3JYB.showApplicationEndTime
- }
- } else if (id === '23nz' && activityState.tableData4) {
- query = {
- ...query,
- data3: activityState.tableData4.show ? activityState.tableData4.applicationStartTime : activityState.tableData4.showApplicationStartTime,
- data4: activityState.tableData4.show ? activityState.tableData4.applicationEndTime : activityState.tableData4.showApplicationEndTime
- }
- } else if (id === '23nzTwo' && activityState.tableData4Two) {
- query = {
- ...query,
- data3: activityState.tableData4Two.show ? activityState.tableData4Two.applicationStartTime : activityState.tableData4Two.showApplicationStartTime,
- data4: activityState.tableData4Two.show ? activityState.tableData4Two.applicationEndTime : activityState.tableData4Two.showApplicationEndTime
- }
- }
- uni.navigateTo({
- url: `/pages/activities/content?${new URLSearchParams(query).toString()}`
- })
- } else if (id === 'newList') {
- uni.navigateTo({
- url: `/pages/activities/content?id=${listID}&type=1&active=newList`
- })
- } else {
- uni.navigateTo({
- url: `/pages/activities/content?id=${id}&type=1`
- })
- }
- }
- const toDeposit = () => {
- uni.navigateTo({ url: '/pages/customer/deposit' })
- }
- const toActivity24nianzhong = () => {
- uni.navigateTo({ url: '/pages/customer/deposit' })
- }
- const toActivity24Trading = () => {
- uni.navigateTo({ url: '/pages/customer/new' })
- }
- const toHistoryLuckyDraw = () => {
- uni.navigateTo({ url: '/pages/customer/history/lucky/draw' })
- }
- const toTaskList = () => {
- uni.navigateTo({ url: '/pages/customer/task/list' })
- }
- const goSurplusTaskList = () => {
- uni.navigateTo({ url: '/pages/customer/surplus/list' })
- }
- const goMonthlyTaskList = () => {
- uni.navigateTo({ url: '/pages/customer/monthly/list' })
- }
- const toDocumentary = () => {
- uni.navigateTo({ url: '/pages/documentary/trading/center' })
- }
- const backActivity = () => {
- uni.navigateBack()
- }
- // ==================== PDF打开 ====================
- const openPdf = (pdfConfig: any) => {
- let url = ''
- if (typeof pdfConfig === 'string') {
- url = pdfConfig
- } else if (pdfConfig.dynamic) {
- if (pdfConfig.langMap) {
- url = pdfConfig.langMap[activityState.lang] || pdfConfig.langMap.default
- } else if (pdfConfig.path) {
- url = pdfConfig.path.replace('{lang}', activityState.lang)
- if (pdfConfig.supportedLangs && !pdfConfig.supportedLangs.includes(activityState.lang)) {
- url = pdfConfig.fallback || url
- }
- }
- } else if (pdfConfig.cn) {
- url = pdfConfig[activityState.lang] || pdfConfig.default
- }
- if (url) {
- // #ifdef H5
- window.open(url, '_blank')
- // #endif
- // #ifdef APP-PLUS
- plus.runtime.openURL(url)
- // #endif
- // #ifdef MP-WEIXIN
- uni.downloadFile({
- url: url,
- success: (res) => {
- if (res.statusCode === 200) {
- uni.openDocument({
- filePath: res.tempFilePath,
- success: () => {
- uni.showToast({ title: t('common.success'), icon: 'success' })
- }
- })
- }
- }
- })
- // #endif
- }
- }
- // ==================== 活动操作 ====================
- const toApply23Open = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity23Login({})
- if (res.code === Code.StatusOK) {
- loginOptions.value = res.data
- dialogDealResult.value = true
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('获取账户列表失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- const toApply23 = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity23HundredApply({
- login: dialogDealResult_form.value.login
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogDealResult.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('申请失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- const toApply23Cancel = () => {
- dialogDealResult_form.value = { login: '' }
- dialogDealResult.value = false
- }
- const toTransform = () => {
- dialogChinaUnionPay.value = true
- }
- const toTransformActive = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity23HundredTransform({})
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogChinaUnionPay.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('转换失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- const toRealization = () => {
- dialogChinaUnionPay1.value = true
- }
- const toRealizationActive = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity23HundredRealization({})
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogChinaUnionPay1.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('变现失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- // 23匠鑫活动申请
- const toApply23Jx = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity23JiangxinApply({
- login: dialogDealResultJx_form.value.login
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogDealResultJx.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('申请失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- const toApply23JxCancel = () => {
- dialogDealResultJx_form.value = { login: '' }
- dialogDealResultJx.value = false
- }
- // 23匠鑫VIP活动申请
- const toApply23JxVip = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity23JiangxinApplyVip({
- login: dialogDealResultJx_formVip.value.login
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogDealResultJxVip.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('申请失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- const toApply23JxCancelVip = () => {
- dialogDealResultJx_formVip.value = { login: '' }
- dialogDealResultJxVip.value = false
- }
- // 匠鑫活动变现
- const toRealizationJx = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity23JiangxinRealization({
- id: activityState.tableData3?.id
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('变现失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- // 匠鑫VIP活动变现
- const toRealizationJxVip = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity23JiangxinRealizationVip({
- id: activityState.tableData3Vip?.id
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('变现失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- // 交易大赛申请
- const toApplyCpt = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.ActivityCptInfoAdd({
- cptId: activityState.tableDataCpt?.id,
- login: dialogDealResultCpt_form.value.login,
- nickname: dialogDealResultCpt_form.value.nickname,
- mobile: dialogDealResultCpt_form.value.mobile,
- address: dialogDealResultCpt_form.value.address,
- recipient: dialogDealResultCpt_form.value.recipient
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogDealResultCpt.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('申请失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- const toApplyCptCancel = () => {
- dialogDealResultCpt_form.value = {
- login: '',
- address: '',
- cptId: '',
- mobile: '',
- nickname: '',
- recipient: ''
- }
- dialogDealResultCpt.value = false
- }
- // 24精英杯申请
- const toApply24JYBVip = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity24JYBApplyVip({
- login: dialogDealResultJx_formJYB.value.login
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogDealResultJxJYB.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('申请失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- const toApply24JYBCancelVip = () => {
- dialogDealResultJx_formJYB.value = { login: '' }
- dialogDealResultJxJYB.value = false
- }
- // 24精英杯变现
- const toRealization24JYBVip = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.Activity24JYBRealizationVip({
- id: activityState.tableData3JYB?.id
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('变现失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- // 无忧交易申请
- const toApplyNoWorries = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.ActivityNoWorriesApply({
- login: dialogDeal_formNoWorries.value.login
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogDealResultNoWorries.value = false
- dialogNoWorriesApply.value = true
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('申请失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- const toApplyNoWorriesCancel = () => {
- dialogDeal_formNoWorries.value = { login: '' }
- dialogDealResultNoWorries.value = false
- }
- // 无忧交易变现
- const realizationNoWorries = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.ActivityNoWorriesRealization({
- id: activityState.tableDataNoWorries?.id
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogNoWorries.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('变现失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- // Surplus活动相关
- const getSurplusActivityOptions = async (account: any) => {
- if (!account) return
- surplusActivityLoading.value = true
- try {
- const res = await activityApi.ActivitySurplusDepositAmount({
- login: account.login,
- platform: account.platform
- })
- if (res.code === Code.StatusOK) {
- surplusActivityOptions.value = res.data.map((item: any, index: number) => ({
- id: index,
- value: item.level,
- label: `${t('AmountLabel.item1')}: ${item.amount} | ${t('AmountLabel.item2')}: ${item.needVolume}`,
- giveFlag: item.giveFlag
- }))
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('获取Surplus活动选项失败', error)
- } finally {
- surplusActivityLoading.value = false
- }
- }
- const confirmSurplusActivity = async () => {
- if (!selectedAccount.value || !selectedSurplusActivity.value) return
- surplusActivityLoading.value = true
- try {
- const res = await activityApi.ActivitySurplusAdd({
- login: selectedAccount.value.login,
- platform: selectedAccount.value.platform,
- level: selectedSurplusActivity.value
- })
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogSurplusActivity.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('参加Surplus活动失败', error)
- } finally {
- surplusActivityLoading.value = false
- }
- }
- const confirmSurplusActivity1 = async () => {
- try {
- const res = await activityApi.ActivityMonthlyAdd({})
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: res.msg, icon: 'success' })
- dialogSurplusActivity1.value = false
- if (refreshCallback) refreshCallback()
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('参加月赏礼遇活动失败', error)
- }
- }
- // 现金嘉年华相关
- const closedialogNewTaskDraw = () => {
- dialogNewTaskDraw.value = false
- if (refreshCallback) refreshCallback()
- }
- // 打开外部链接
- const toOpenSingle = (pageAddress: string) => {
- let link = pageAddress
- if (tableDataCptFlagCode.value) {
- if (pageAddress.indexOf('html?') === -1) {
- link = pageAddress + '?code=' + tableDataCptFlagCode.value
- } else if (pageAddress.indexOf('code') === -1) {
- link = pageAddress + '&code=' + tableDataCptFlagCode.value
- }
- }
- // #ifdef H5
- window.open(Host80 + link, '_blank')
- // #endif
- // #ifndef H5
- plus.runtime.openURL(Host80 + link)
- // #endif
- }
- // 返现
- const cashBack = async () => {
- uni.showLoading({ title: t('common.loading') })
- try {
- const res = await activityApi.ActivityPercentageGiveApply({})
- if (res.code === Code.StatusOK) {
- uni.showToast({ title: t('Msg.Application'), icon: 'success' })
- } else {
- uni.showToast({ title: res.msg, icon: 'none' })
- }
- } catch (error) {
- console.error('返现失败', error)
- } finally {
- uni.hideLoading()
- }
- }
- // 收益计算
- const calculateIncome = (balance: number, details: any[]) => {
- let rate = 0
- details.forEach((item) => {
- if (balance > item.min && balance <= item.max) {
- rate = item.rate
- } else if (balance > item.min && balance >= item.max && item.max === 0) {
- rate = item.rate
- }
- })
- return ((balance * rate) / 100 / 365 * 30).toFixed(2)
- }
- return {
- // 弹窗状态
- dialogChinaUnionPay,
- dialogChinaUnionPay1,
- dialogChinaUnionPayJX,
- dialogDealResult,
- dialogDealResultJx,
- dialogDealResultJxVip,
- dialogDealResultCpt,
- dialogDealResultJxJYB,
- dialogDealResultNoWorries,
- dialogNoWorries,
- dialogNoWorriesApply,
- dialogNewTask,
- dialogNewTaskDraw,
- dialogSurplusActivity,
- dialogSurplusActivity1,
- dialogInfoTradingAdd,
- openCalculatorFlag,
- // 表单数据
- dialogDealResult_form,
- dialogDealResultJx_form,
- dialogDealResultJx_formVip,
- dialogDealResultJx_formJYB,
- dialogDealResultCpt_form,
- dialogDeal_formNoWorries,
- selectedAccount,
- valueInfo,
- surplusActivityOptions,
- surplusActivityLoading,
- selectedSurplusActivity,
- // 页面跳转
- toSingle,
- toDeposit,
- toActivity24nianzhong,
- toActivity24Trading,
- toHistoryLuckyDraw,
- toTaskList,
- goSurplusTaskList,
- goMonthlyTaskList,
- toDocumentary,
- backActivity,
- // PDF打开
- openPdf,
- // 活动操作
- toApply23Open,
- toApply23,
- toApply23Cancel,
- toTransform,
- toTransformActive,
- toRealization,
- toRealizationActive,
- toApply23Jx,
- toApply23JxCancel,
- toApply23JxVip,
- toApply23JxCancelVip,
- toRealizationJx,
- toRealizationJxVip,
- toApplyCpt,
- toApplyCptCancel,
- toApply24JYBVip,
- toApply24JYBCancelVip,
- toRealization24JYBVip,
- toApplyNoWorries,
- toApplyNoWorriesCancel,
- realizationNoWorries,
- getSurplusActivityOptions,
- confirmSurplusActivity,
- confirmSurplusActivity1,
- closedialogNewTaskDraw,
- toOpenSingle,
- cashBack,
- calculateIncome
- }
- }
|