|
|
<script setup>import { onMounted, ref, watch } from 'vue'import { ElMessage } from 'element-plus'import moment from 'moment'import API from '@/util/http.js'import { reverseMarketMapping } from '@/utils/marketMap.js';import dayjs from "dayjs";import { storeToRefs } from 'pinia'import { useAdminStore } from '@/store/index.js'const adminStore = useAdminStore()const { flag } = storeToRefs(adminStore)// 国际化
import { useI18n } from 'vue-i18n';const { t } = useI18n();
//新增员工数数据复选框,默认不勾选
// const showEmployeeData = ref(false)
// 监听全局flag状态变化
watch(flag, (newFlag, oldFlag) => { if(newFlag !== oldFlag) { get() }})
const trimJwCode = () => { if (rechargeUser.value.jwcode) { rechargeUser.value.jwcode = rechargeUser.value.jwcode.replace(/\s/g, ''); }}//这是获取用户信息的接口
const adminData = ref({})const getAdminData = async function () { try { const result = await API({ url: '/admin/userinfo', data: {} }) adminData.value = result rechargeUser.value.adminId = adminData.value.id console.log('请求成功', result) console.log('用户信息', adminData.value) } catch (error) { console.log('请求失败', error) }}const defaultTime = [ new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59),]// 变量
// 充值明细表格
const tableData = ref([])// 标记当前激活的时间范围按钮
const activeTimeRange = ref('')// 日期选择器变化时清除按钮激活状态
const handleDatePickerChange = () => { activeTimeRange.value = ''}
// 搜索===========================================
// 搜索recharge
const rechargeUser = ref({ adminId: adminData.value.id, market: "",})
/*//处理地区选择变化const handleMarketChange = (value) => { if (Array.isArray(value) && value.length > 0) { const ids = new Set();
value.forEach(path => { const lastName = path[path.length - 1]; const id = reverseMarketMapping[lastName]; if (id) ids.add(Number(id)); });
// 添加额外处理:如果一个父节点下所有子节点都被选中,则把父节点也加入
const getAllLeafNames = (nodes) => { const leafNames = [];
const traverse = (node, parentName = null) => { if (!node.children || node.children.length === 0) { leafNames.push({ name: node.label, parent: parentName }); } else { node.children.forEach(child => traverse(child, node.label)); } };
nodes.forEach(node => traverse(node)); return leafNames; };
const leafNameMap = getAllLeafNames(market.value); // 所有叶子节点和对应父级名称
// 构建一个 { parentName: [childName1, childName2, ...] } 的结构
const parentToChildren = {}; leafNameMap.forEach(({ name, parent }) => { if (!parentToChildren[parent]) parentToChildren[parent] = []; parentToChildren[parent].push(name); });
// 构建当前被选中的叶子节点
const selectedLeafNames = value.map(path => path[path.length - 1]);
// 如果 parent 下所有子节点都选中了,就把 parent 加进来
Object.entries(parentToChildren).forEach(([parent, children]) => { const allChildrenSelected = children.every(child => selectedLeafNames.includes(child)); if (allChildrenSelected && reverseMarketMapping[parent]) { ids.add(Number(reverseMarketMapping[parent])); } });
// 修改:将数组转换为单个字符串(取第一个ID)
const idArray = Array.from(ids); rechargeUser.value.market= idArray.length > 0 ? idArray[0].toString() : ""; } else { rechargeUser.value.market = ""; }
console.log('最终映射后的 market IDs:', rechargeUser.value.market);};*/// 存储地区选择变化
const selectedMarketPath = ref("")const handleMarketChange = (value) => { if (value && value.length > 0) { const lastValue = value[value.length - 1] rechargeUser.value.market = reverseMarketMapping[lastValue] } else { rechargeUser.value.market = '' }}
/*// 处理地区选择变化(单选场景)const handleMarketChange = (value) => { // 重置为默认空值
rechargeUser.value.market = "";
// 检查是否有有效的选择值
if (Array.isArray(value) && value.length > 0) { // 对于单选,value数组中通常只有一个路径
const selectedPath = value[0]; if (Array.isArray(selectedPath) && selectedPath.length > 0) { // 获取选中项的最后一级名称
const lastName = selectedPath[selectedPath.length - 1]; // 查找对应的ID
const id = reverseMarketMapping[lastName];
// 如果找到有效ID,转换为字符串格式
if (id) { rechargeUser.value.market = String(id); } } } console.log('最终选中的 market ID:', rechargeUser.value.market);};*/
// 搜索对象
const getObj = ref({ pageNum: 1, pageSize: 50})//分页总条目
const total = ref(100)// 搜索对象时间
const getTime = ref([])// 搜索活动列表
const activity = ref([])// 所有信息
const allData = ref([])// 搜索地区列表
const market = ref("")//时间格式化
const formatTime = (val) => val ? moment(val).format('YYYY-MM-DD HH:mm:ss') : ''// 初始化 money 和 permanentGold 和 freeGold
const money = ref(0)const permanentGold = ref(0)const freeGold = ref(0)
// 定义响应式变量存储金币合计数
const permanentGolds = ref(0)const freeGolds = ref(0)
//无法选择的时间
const disabledDate = (time) => { const limitDate = new Date(2025, 0, 1); return time.getTime() < limitDate.getTime();}// 支付方式选项
const payModel = [ { value: '微信', label: '微信' }, { value: '支付宝', label: '支付宝' }, { value: '银联', label: '银联' }, { value: '信用卡', label: '信用卡' }, { value: '借记卡', label: '借记卡' }, { value: '现金充值', label: '现金充值' }]// 删除==========================================================
// 删除对象
const delObj = ref({})
// 获取活动名称
const getActivity = async function () { try { // 发送POST请求
const result = await API({ url: '/general/activity', data: {} })
// 将响应结果存储到响应式数据中
console.log('请求成功', result)
// 检查返回的数据是否为数组
if (Array.isArray(result.data)) { // 将字符串数组转换为 { value, label } 格式
activity.value = result.data.map(item => ({ value: item, label: item })); } else { console.error('活动数据格式错误', result) ElMessage.error($t('elmessage.activityFormatError')) }
console.log('activity', activity.value) } catch (error) { console.log('请求失败', error) // 在这里可以处理错误逻辑,比如显示错误提示等
}}const marketsTree = ref("")// 获取地区,修改为级联下拉框
const getArea = async function () { try { // 发送POST请求
const result = await API({
url: '/market/selectMarket', }); // 将响应结果存储到响应式数据中
console.log('请求成功', result)
// 递归转换树形结构为级联选择器需要的格式(跳过第一级节点)
const transformTree = (nodes) => { // 直接处理第一级节点的子节点
const allChildren = nodes.flatMap(node => node.children || []);
return allChildren.map(child => { const grandchildren = child.children && child.children.length ? transformTree([child]) // 递归处理子节点
: null;
return { value: child.name, label: child.name, children: grandchildren }; }); }; // 存储地区信息
market.value = transformTree(result.data) console.log('转换后的地区树==============', market.value) } catch (error) { console.log('请求失败', error) }}
//定义充值方式的加载状态
const isLoadingPlatform = ref(false)// 充值平台
const platform = ref([])//获取充值方式的函数
const getPlatform = async () => { isLoadingPlatform.value = true; try { const result = await API({ url: '/general/platform', method: 'post', data: {}// 这里添加参数
}) // 假设后端返回的是字符串数组,转换为 { value, label } 格式
if (Array.isArray(result.data)) { platform.value = result.data.map(item => ({ value: item, label: item })); } else { console.error('充值方式格式错误', result) ElMessage.error($t('elmessage.rechargeFormatError')) } } catch (error) { console.error('获取充值方式失败:', error); ElMessage.error($t('elmessage.getRechargeError')) } finally { isLoadingPlatform.value = false }}
// 搜索===========================================================================
// 搜索方法
const get = async function (val) { try { // 搜索参数页码赋值
if (typeof val === 'number') { getObj.value.pageNum = val } // 搜索参数时间赋值
if (getTime.value != null) { if (getTime.value.startTime != '' && getTime.value.endTime != '') { rechargeUser.value.startTime = formatTime(getTime.value[0]) rechargeUser.value.endTime = formatTime(getTime.value[1]) } } else { rechargeUser.value.startTime = '' rechargeUser.value.endTime = '' } // 搜索参数赋值
rechargeUser.value.sortField = sortField.value rechargeUser.value.sortOrder = sortOrder.value console.log('搜索参数', getObj.value) // 发送POST请求
// if (rechargeUser.value.market === '9' || rechargeUser.value.market === '9999') {
// rechargeUser.value.market = '';
// }
if (rechargeUser.value.jwcode) { // 纯数字
const numberRegex = /^\d{1,9}$/;
// 检查是否不是数字
if (!numberRegex.test(rechargeUser.value.jwcode)) { ElMessage.error($t('elmessage.checkJwcodeFormat')) // 上面提示过了
return } } const result = await API({ url: '/recharge/selectBy', data: { ...getObj.value, rechargeUser: { ...rechargeUser.value, flag: flag.value }//新增flag参数
} }) // 复制一份 rechargeUser.value 并移除排序字段和排序方式
const detailWithoutSort = ref({ ...rechargeUser.value, sortField: undefined, sortOrder: undefined, flag: flag.value // 新增 flag 参数
}) const resultTotalGold = await API({ url: '/recharge/statsGold', data: { ...detailWithoutSort.value } })
if (resultTotalGold.code === 200 && resultTotalGold.data) { const data = resultTotalGold.data console.log('获取到的金币数据:', data)
permanentGolds.value = (Number(data.permanentGolds) || 0) freeGolds.value = (Number(data.freeGolds) || 0)
}
// 将响应结果存储到响应式数据中
console.log('请求成功', result) // 存储表格数据
tableData.value = result.data.list // 处理表格中的充值金额、永久金币和免费金币数据,除以 100
tableData.value = tableData.value.map(item => ({ ...item, // 处理永久金币
permanentGold: (Number(item.permanentGold) || 0), // 处理免费金币
freeGold: (Number(item.freeGold) || 0), // 处理充值金额
money: (Number(item.money) || 0) })) console.log('tableData', tableData.value) // 存储分页总数
total.value = result.data.total console.log('total', total.value) } catch (error) { console.log('请求失败', error) // 在这里可以处理错误逻辑,比如显示错误提示等
}}// 搜索
const search = function () { trimJwCode() getObj.value.pageNum = 1 get()}// 重置
const reset = function () { delete rechargeUser.value.jwcode delete rechargeUser.value.activity delete rechargeUser.value.payPlatform rechargeUser.value.market = "" selectedMarketPath.value = "" // 重置地区选择路径
delete rechargeUser.value.startTime delete rechargeUser.value.endTime delete sortField.value delete sortOrder.value getTime.value = {} activeTimeRange.value = '' // 清除激活状态
// 重置页码
getObj.value.pageNum = 1
get()}// 今天
const getToday = function () { const today = dayjs() const startTime = today.startOf('day').format('YYYY-MM-DD HH:mm:ss') const endTime = today.endOf('day').format('YYYY-MM-DD HH:mm:ss') getTime.value = [startTime, endTime] console.log('getTime', getTime.value) activeTimeRange.value = 'today' // 标记当前激活状态
get()}const handlePageSizeChange = function (val) { getObj.value.pageSize = val get()}const handleCurrentChange = function (val) { getObj.value.pageNum = val get()}// 昨天
const getYesterday = function () { const today = dayjs() const startTime = today.subtract(1, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss') const endTime = today.subtract(1, 'day').endOf('day').format('YYYY-MM-DD HH:mm:ss') getTime.value = [startTime, endTime] console.log('getTime', getTime.value) activeTimeRange.value = 'yesterday' // 标记当前激活状态
get()}
// 近7天
const get7Days = function () { const today = dayjs() const startTime = today.subtract(6, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss') const endTime = today.endOf('day').format('YYYY-MM-DD HH:mm:ss') getTime.value = [startTime, endTime] console.log('getTime', getTime.value) activeTimeRange.value = '7days' // 标记当前激活状态
get()}
const format3 = (num) => { // 每三位添加逗号
return num.toLocaleString('en-US')}// 挂载
onMounted(async function () { await get() await getActivity() await getAdminData() await getArea() await getPlatform()})// 新增排序字段和排序方式
const sortField = ref()const sortOrder = ref()// 处理排序事件
const handleSortChange = (column) => {
console.log('排序字段:', column.prop) console.log('排序方式:', column.order) if (column.prop === 'money') { sortField.value = 'money' } else if (column.prop === 'freeGold') { sortField.value = 'freeGold' } else if (column.prop === 'auditTime') { sortField.value = 'auditTime' } else if (column.prop === 'createTime') { sortField.value = 'createTime' } else if (column.prop === 'permanentGold') { sortField.value = 'permanentGold' } sortOrder.value = column.order === 'ascending' ? 'ASC' : 'DESC' console.log('传递给后端的排序字段:', sortField.value) console.log('传递给后端的排序方式:', sortOrder.value) get()}
const exportExcel = async function () { const params = { rechargeUser: { ...rechargeUser.value, flag: flag.value }, page: getObj.value.pageNum, size: total.value } try { const res = await API({ url: '/export/exportRecharge', data: params }) if (res.code === 200) { ElMessage.success($t('elmessage.exportSuccess')) } else { ElMessage.error(res.message || $t('elmessage.exportFailed')) } } catch (error) { console.log('请求失败', error) ElMessage.error($t('elmessage.exportFailed')) }}
const exportListVisible = ref(false)
// 打开导出列表弹窗
const openExportList = () => { getExportList() exportListVisible.value = true}
// 导出列表数据
const exportList = ref([])// 导出列表加载状态
const exportListLoading = ref(false)// 获取导出列表
const getExportList = async () => { exportListLoading.value = true try { const result = await API({ url: '/export/export' }) if (result.code === 200) { const filteredData = result.data.filter(item => { return item.type === 2; //2表示金币充值列表
}); exportList.value = filteredData } else { ElMessage.error(result.msg || $t('elmessage.getExportListError')) } } catch (error) { console.error('获取导出列表出错:', error) ElMessage.error($t('elmessage.getExportListError')) } finally { exportListLoading.value = false }}// 下载导出文件
const downloadExportFile = (item) => { if (item.state === 2) { const link = document.createElement('a') link.href = item.url link.download = item.fileName link.click() } else { ElMessage.warning($t('elmessage.exportingInProgress')) }}//根据状态返回对应的标签类型
const getTagType = (state) => { switch (state) { case 0: return 'info'; case 1: return 'primary'; case 2: return 'success'; case 3: return 'danger'; default: return 'info'; }}//根据状态返回对应的标签文案
const getTagText = (state) => { switch (state) { case 0: return $t('elmessage.pendingExecution'); case 1: return $t('elmessage.executing'); case 2: return $t('elmessage.executed'); case 3: return $t('elmessage.errorExecution'); default: return $t('elmessage.unknownStatus'); }}
</script>
<template> <el-card class="card1" style="margin-bottom: 0.5vh"> <el-col style="margin-bottom: 1vh"> <div class="select"> <div class="selectRow"> <el-text class="text" size="large">{{ $t('common.jwcode') }}:</el-text> <el-input class="selectContent" v-model="rechargeUser.jwcode" :placeholder="$t('common.jwcodePlaceholder')" clearable /> </div> <div class="selectRow"> <el-text class="text" size="large">{{ $t('common.activityName') }}:</el-text> <el-select class="selectContent" v-model="rechargeUser.activity" :placeholder="$t('common.activityNamePlaceholder')" clearable> <el-option v-for="item in activity" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </div> <div class="selectRow" style="width: 15vw;"> <el-text class="text" size="large">{{ $t('common.market') }}:</el-text> <el-cascader class="selectContent" v-model="selectedMarketPath" :options="market" :placeholder="$t('common.marketPlaceholder')" clearable @change="handleMarketChange" /> </div> <div class="selectRow" style="width: 15vw;"> <el-text class="text" size="large">{{ $t('common.rechargePlatform') }}:</el-text> <el-select class="selectContent" v-model="rechargeUser.payPlatform" :placeholder="$t('common.rechargePlatformPlaceholder')" clearable> <el-option v-for="item in platform" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </div> <!-- <el-checkbox v-model="showEmployeeData" @change="search()">员工数据</el-checkbox> --> </div> </el-col> <el-col> <div class="select"> <div class="selectRow" style="width: 36vw;"> <el-text class="text" size="large">{{ $t('common.rechargeTime') }}:</el-text> <el-date-picker class="selectContent" v-model="getTime" type="datetimerange" :range-separator="$t('common.to')" :start-placeholder="$t('common.startTime')" :end-placeholder="$t('common.endTime')" style="margin-right:1vw;width:25vw" @change="handleDatePickerChange" :default-time="defaultTime" :disabled-date="disabledDate" /> <div v-if="false"> <el-button @click="getToday()" style="margin-left: 1vw" :type="activeTimeRange === 'today' ? 'primary' : ''"> 今 </el-button> <el-button @click="getYesterday()" style="margin-left: 1vw" :type="activeTimeRange === 'yesterday' ? 'primary' : ''"> 昨 </el-button> <el-button @click="get7Days()" style="margin-left: 1vw" :type="activeTimeRange === '7days' ? 'primary' : ''"> 近7天 </el-button> </div> </div> <div class="selectRow" style="justify-content: flex-start;"> <el-button type="primary" @click="search()">{{ $t('common.search') }}</el-button> <el-button type="primary" @click="exportExcel()">{{ $t('common.exportExcel') }}</el-button> <el-button type="primary" @click="openExportList">{{ $t('common.viewExportList') }}</el-button> <el-button type="success" @click="reset()">{{ $t('common.reset') }}</el-button> </div> </div>
</el-col> </el-card>
<el-card class="card2"> <div class="goldStatistics"> {{ $t('common.rechargeSGD') }}:{{ format3(permanentGolds) }} {{ $t('common.SGD') }} {{ $t('common.totalGoldCoin') }}:{{ format3(permanentGolds + freeGolds) }} {{ $t('common.goldCoin') }} {{ $t('common.permanentGold') }}:{{ format3(permanentGolds) }} {{ $t('common.goldCoin') }} {{ $t('common.freeGold') }}:{{ format3(freeGolds) }} {{ $t('common.goldCoin') }} </div> <!-- 设置表格容器的高度和滚动样式 --> <div style="height: 66vh;"> <el-table :data="tableData" height="66vh" @sort-change="handleSortChange"> <el-table-column type="index" :label="$t('common_list.id')" width="80px" fixed="left"> <template #default="scope"> <span>{{ scope.$index + 1 + (getObj.pageNum - 1) * getObj.pageSize }}</span> </template> </el-table-column> <el-table-column fixed="left" prop="name" :label="$t('common_list.name')" width="150px" /> <el-table-column fixed="left" prop="jwcode" :label="$t('common_list.jwcode')" width="110px" /> <el-table-column prop="market" :label="$t('common_list.market')" width="100px" /> <el-table-column prop="activity" :label="$t('common_list.activity')" width="110px" show-overflow-tooltip /> <el-table-column prop="rateName" :label="$t('common_list.rateName')" width="110px" /> <el-table-column prop="money" sortable="custom" :label="$t('common_list.rechargeAmount')" width="110px" /> <el-table-column prop="permanentGold" :label="$t('common_list.permanentGold')" sortable="custom" width="110px" /> <el-table-column prop="freeGold" :label="$t('common_list.freeGold')" sortable="custom" width="110px" /> <el-table-column prop="payPlatform" :label="$t('common_list.rechargePlatform')" width="110px" /> <el-table-column prop="payModel" :label="$t('common_list.payModel')" width="100px" /> <el-table-column prop="remark" :label="$t('common_list.remark')" width="150px" show-overflow-tooltip /> <el-table-column prop="isRefund" :label="$t('common_list.orderStatus')" width="200px" show-overflow-tooltip> <template #default="scope"> <span v-if="scope.row.isRefund == 0">{{ $t('recharge.normal') }}</span> <span v-else-if="scope.row.isRefund == 1">{{ $t('recharge.refunded') }}</span> <span v-else>{{ $t('recharge.unknown') }}</span> </template> </el-table-column> <el-table-column prop="adminName" :label="$t('common_list.submitter')" width="100px" /> <el-table-column prop="auditTime" sortable :label="$t('common_list.rechargeTime')" width="200px"> <template #default="scope"> {{ moment(scope.row.auditTime).format('YYYY-MM-DD HH:mm:ss') }} </template> </el-table-column> </el-table> </div>
<!-- 分页 --> <div style="margin-top: 1vh"> <el-pagination background :current-page="getObj.pageNum" :page-size="getObj.pageSize" :page-sizes="[5, 10, 20, 50, 100]" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handlePageSizeChange" @current-change="handleCurrentChange"></el-pagination> </div> </el-card>
<!-- 导出弹窗 --> <el-dialog v-model="exportListVisible" :title="$t('common_export.exportList')" width="80%"> <el-table :data="exportList" style="width: 100% ;height: 60vh;" :loading="exportListLoading"> <el-table-column prop="fileName" :label="$t('common_export.fileName')" /> <el-table-column prop="state" :label="$t('common_export.status')"> <template #default="scope"> <el-tag :type="getTagType(scope.row.state)" :effect="scope.row.state === 3 ? 'light' : 'plain'"> {{ getTagText(scope.row.state) }} </el-tag> </template> </el-table-column> <el-table-column prop="createTime" :label="$t('common_export.createTime')"> <template #default="scope"> {{ moment(scope.row.createTime).format('YYYY-MM-DD HH:mm:ss') }} </template> </el-table-column> <el-table-column :label="$t('common_export.operation')"> <template #default="scope"> <el-button type="primary" size="small" @click="downloadExportFile(scope.row)" :disabled="scope.row.state !== 2"> {{ $t('common_export.download') }} </el-button> </template> </el-table-column> </el-table> <template #footer> <div class="dialog-footer"> <el-button text @click="exportListVisible = false">{{ $t('common_export.close') }}</el-button> </div> </template> </el-dialog></template><style scoped lang="scss">// 搜索的卡片样式
.card1 { background: #F3FAFE;}
// 表单的卡片样式
.card2 { background: #E7F4FD;}
// 新币总数等等
.goldStatistics { margin-left: 1vw; margin-bottom: 1vh; color: #000000; font-family: "PingFang SC"; font-size: 16px; font-style: normal; font-weight: 700; line-height: 20px;}
// 表头背景等
:deep(.el-table__header-wrapper),:deep(.el-table__body-wrapper),:deep(.el-table__cell),/* 表格 */:deep(.el-table__body td) { background-color: #F3FAFE !important;}
/* 表头 */:deep(.el-table__header th) { background-color: #F3FAFE !important;}
/* 鼠标悬停 */:deep(.el-table__row:hover > .el-table__cell) { background-color: #E5EBFE !important;}
/** 上面搜索的布局 **/.select { display: flex;
.selectRow { width: 17vw; display: flex; align-items: center; justify-content: center; padding: 0 0.5vw;
.text { width: 5vw; font-size: 15px; }
.selectContent { flex: 1; } }}</style>
|