|
|
<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">精网号:</el-text> <el-input class="selectContent" v-model="searchForm.jwcode" placeholder="请输入精网号" clearable /> </div> <div class="selectRow"> <el-text class="text" size="large">商品名称:</el-text> <el-select class="selectContent" v-model="searchForm.goodsName" placeholder="请输入商品名称" clearable> <el-option v-for="item in refundGoodsOptions" :key="item" :label="item" :value="item"></el-option> </el-select> </div> <div class="selectRow"> <el-text class="text" size="large">退款类型:</el-text> <el-select class="selectContent" v-model="searchForm.refundType" placeholder="请选择退款类型" clearable> <el-option label="商品退款" value="商品退款" /> <el-option label="金币退款" value="金币退款" /> </el-select> </div> <div class="selectRow"> <el-text class="text" size="large">所属地区:</el-text> <el-cascader class="selectContent" style="width: 12vw;" v-model="selectedMarketPath" :options="market" placeholder="请选择所属地区" clearable @change="handleMarketChange" /> </div> </div> </el-col> <el-col> <div class="select"> <div class="selectRow" style="width: 36vw;"> <el-text class="text" size="large"> {{ activeName === 'wait' ? '提交时间:' : '审核时间:' }} </el-text> <el-date-picker class="selectContent" v-model="dateRange" type="datetimerange" range-separator="至" start-placeholder="起始时间" end-placeholder="结束时间" style="margin-right:1vw;width:25vw" @change="handleDatePickerChange" :default-time="defaultTime" :disabled-date="disabledDate" /> <div v-if="false"> <el-button @click="getToday()" :type="activeTimeRange === 'today' ? 'primary' : ''">今</el-button> <el-button @click="getYesterday()" :type="activeTimeRange === 'yesterday' ? 'primary' : ''">昨</el-button> <el-button @click="get7Days()" :type="activeTimeRange === '7days' ? 'primary' : ''">近7天</el-button> </div> </div> <div class="selectRow" style="justify-content: flex-start;"> <el-button @click="handleSearch" type="primary">查询</el-button> <el-button @click="resetSearch" type="success">重置</el-button> </div> </div> </el-col> </el-card>
<el-card class="card2"> <div class="custom-button-group"> <el-button v-if="hasrefundWait && hasrefundWaitShow" :type="activeName === 'wait' ? 'primary' : 'default'" @click="handleButtonClick('wait')" class="custom-tab-button"> 待审核 </el-button> <el-button v-if="hasrefundThrough" :type="activeName === 'pass' ? 'primary' : 'default'" @click="handleButtonClick('pass')" class="custom-tab-button"> 已通过 </el-button> <el-button v-if="hasrefundReject" :type="activeName === 'reject' ? 'primary' : 'default'" @click="handleButtonClick('reject')" class="custom-tab-button"> 已驳回 </el-button> </div>
<div class="goldStatistics"> 退款总金币数:{{ format3((stats.permanentGolds + stats.freeGolds + stats.taskGolds).toFixed(2)) }}金币 永久金币:{{ format3(stats.permanentGolds.toFixed(2)) }}金币 免费金币:{{ format3(stats.freeGolds.toFixed(2)) }}金币 任务金币:{{ format3(stats.taskGolds.toFixed(2)) }}金币 </div>
<el-table :data="tableData" style="height:54vh;width:82vw" @sort-change="handleSortChange"> <el-table-column type="index" label="序号" width="60" /> <el-table-column prop="name" label="姓名" width="120" show-overflow-tooltip /> <el-table-column prop="jwcode" label="精网号" width="120" /> <el-table-column prop="market" label="所属地区" width="120" /> <el-table-column prop="orderCode" label="订单号" width="260px" show-overflow-tooltip />
<el-table-column prop="refundType" label="退款类型" width="120" /> <el-table-column prop="refundModel" label="退款方式" width="120"> <template #default="{ row }"> {{ row.refundModel === 0 ? '全部退款' : '部分退款' }} </template> </el-table-column> <el-table-column prop="goodsName" label="退款商品" width="120" show-overflow-tooltip /> <el-table-column prop="sumGold" label="退款金币总数" width="160" sortable="custom"> <template #default="{ row }"> {{ row.sumGold / 100 }} </template> </el-table-column> <el-table-column prop="permanentGold" label="永久金币" width="120" sortable="custom"> <template #default="{ row }"> {{ row.permanentGold / 100 }} </template> </el-table-column> <el-table-column prop="freeGold" label="免费金币" width="120" sortable="custom"> <template #default="{ row }"> {{ (row.freeJune + row.freeDecember) / 100 }} </template> </el-table-column> <el-table-column prop="taskGold" label="任务金币" width="120" sortable="custom"> <template #default="{ row }"> {{ row.taskGold / 100 }} </template> </el-table-column> <el-table-column prop="remark" label="备注" width="150" show-overflow-tooltip /> <el-table-column prop="adminName" label="提交人" width="120" /> <el-table-column v-if="checkTab === 'reject'" prop="rejectReason" label="驳回理由" width="150" show-overflow-tooltip /> <el-table-column v-if="checkTab !== 'pending'" prop="auditName" label="审核人" width="120" /> <el-table-column prop="createTime" label="提交时间" width="180" sortable="custom"> <template #default="{ row }"> {{ checkTab === 'pending' ? moment(row.auditTime).format('YYYY-MM-DD HH:mm:ss') : moment(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}
</template> </el-table-column> <el-table-column v-if="checkTab !== 'pending'" prop="auditTime" label="审核时间" width="180"> <template #default="{ row }"> {{ row.auditTime ? moment(row.auditTime).format('YYYY-MM-DD HH:mm:ss') : '--' }} </template> </el-table-column> <el-table-column v-if="checkTab === 'pending' && (hasrefundWaitThough || hasrefundWaitReject) && hasrefundWaitShow" fixed="right" prop="operation" label="操作" width="150px"> <template #default="scope"> <div class="operation"> <el-popconfirm title="确定要通过此条记录吗?" @confirm="handleApprove(scope.row)"> <template #reference> <el-link :underline="false" class="pass-btn" v-if="hasrefundWaitThough" :disabled="clicked || cancelClicked" type="primary"> 通过 </el-link> </template> <template #actions="{ confirm, cancel }"> <el-button size="small" @click="cancel">取消</el-button> <el-button type="primary" size="small" :disabled="clicked" @click="confirm"> 确认 </el-button> </template> </el-popconfirm> <el-link :underline="false" class="reject-btn" v-if="hasrefundWaitReject" :disabled="clicked || cancelClicked" type="primary" @click="showRejectDialog(scope.row)"> 驳回 </el-link> </div> </template> </el-table-column> </el-table> <el-pagination class="pagination" v-model:current-page="pagination.pageNum" v-model:page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total" @size-change="handlePageSizeChange" @current-change="handleCurrentChange"></el-pagination> </el-card>
<el-dialog v-model="rejectDialogVisible" title="驳回理由" width="500px"> <el-form> <el-form-item label="驳回理由" required> <el-input v-model="rejectReason" type="textarea" :rows="4" placeholder="请输入驳回理由" maxlength="200" show-word-limit /> </el-form-item> </el-form> <template #footer> <span class="dialog-footer"> <el-button @click="rejectDialogVisible = false">取消</el-button> <el-button type="primary" @click="handleReject">确定</el-button> </span> </template> </el-dialog></template>
<script setup>import { onMounted, reactive, ref } from 'vue'import { ElMessage } from 'element-plus'import API from '@/util/http.js'import moment from 'moment'import { useAdminStore } from "@/store/index.js";import { storeToRefs } from "pinia";import dayjs from "dayjs";import { permissionMapping, hasMenuPermission } from "@/utils/menuTreePermission.js"
const adminStore = useAdminStore();const { adminData, menuTree } = storeToRefs(adminStore);const defaultTime = [ new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59),]// 当前激活的时间按钮
const activeTimeRange = ref('')const scopeValue = ref(null) // 当前行
const rejectDialogVisible = ref(false)const rejectReason = ref('')// 状态常量
const STATUS = { PENDING: 0, // 待审核
APPROVED: 1, // 通过
REJECTED: 2 // 驳回
}//无法选择的时间
const disabledDate = (time) => { const limitDate = new Date(2025, 0, 1); return time.getTime() < limitDate.getTime();}// 搜索表单数据
const searchForm = ref({ jwcode: '', refundModel: '', goodsName: '', market: "", startTime: '', endTime: '', auditStatus: '0'})const checkTab = ref('pending') // 能否不用STATUS常量,0是待审批,1是已通过,2是驳回,参数status需要Integer
const dateRange = ref([])const pagination = ref({ pageNum: 1, pageSize: 50, total: 0})const tableData = ref([])const marketOptions = ref([])const refundGoodsOptions = ref([])const adminInfo = ref({})
// 统计合计数
const stats = ref({ totalNum: 0, totalCoins: 0, permanentGolds: 0, freeGolds: 0, taskGolds: 0})const rejectVisible = ref(false)const rejectObj = ref({})const passObj = ref({})// 标签页默认是待审批
const activeName = ref('wait')const sortField = ref('')const sortOrder = ref('')const market = ref("")
//退款操作权限
const hasrefundThrough = ref(false) // 退款审核已通过
const hasrefundReject = ref(false) // 退款审核已驳回
const hasrefundWait = ref(false) // 退款审核待审核
const hasrefundWaitShow = ref(false) // 退款审核待审核查看
const hasrefundWaitThough = ref(false) // 退款审核通过
const hasrefundWaitReject = ref(false) // 退款审核驳回
// 初始化权限状态
const initPermissions = async () => { if (!menuTree.value || !menuTree.value.length) return; // 退款相关权限
hasrefundThrough.value = hasMenuPermission(menuTree.value, permissionMapping.refundThrough); hasrefundReject.value = hasMenuPermission(menuTree.value, permissionMapping.refundReject); hasrefundWait.value = hasMenuPermission(menuTree.value, permissionMapping.refundWait); hasrefundWaitShow.value = hasMenuPermission(menuTree.value, permissionMapping.refundWaitShow); hasrefundWaitThough.value = hasMenuPermission(menuTree.value, permissionMapping.refundWaitThough); hasrefundWaitReject.value = hasMenuPermission(menuTree.value, permissionMapping.refundWaitReject); console.log('退款权限赋值完成');
};// 处理排序事件
const handleSortChange = (column) => { if (column.prop === 'sumGold') { sortField.value = 'sum_gold' } else if (column.prop === 'permanentGold') { sortField.value = 'permanent_gold' } else if (column.prop === 'freeGold') { sortField.value = 'freeGold' } else if (column.prop === 'taskGold') { sortField.value = 'task_gold' } else if (column.prop === 'createTime') { sortField.value = 'create_time' } else if (column.prop === 'auditTime') { sortField.value = 'audit_time' } else { sortField.value = '' } sortOrder.value = column.order === 'ascending' ? 'asc' : 'desc' console.log('排序字段:', sortField.value) console.log('排序方式:', sortOrder.value) get()}// 显示驳回对话框
const showRejectDialog = (row) => { if (!hasrefundWaitReject) { ElMessage.error('暂无权限') return } scopeValue.value = row rejectReason.value = '' rejectDialogVisible.value = true}// 查商品名
const getRefundGoods = async () => { try { const res = await API({ url: '/general/goods' }) refundGoodsOptions.value = res.data || [] } catch (error) { console.error('获取商品列表失败', error) }}
// 搜索方法
const get = async function (val) { if (!hasrefundWaitShow) { ElMessage.error('暂无权限') return } try { if (typeof val === 'number') { pagination.value.pageNum = val } if (dateRange.value && dateRange.value.length === 2) { searchForm.value.startTime = moment(dateRange.value[0]).format('YYYY-MM-DD HH:mm:ss') searchForm.value.endTime = moment(dateRange.value[1]).format('YYYY-MM-DD HH:mm:ss') } else { searchForm.value.startTime = '' searchForm.value.endTime = '' } // if (searchForm.value.market === '总部' || searchForm.value.market === '研发部') {
// searchForm.value.market = '';
// }
const params = { pageNum: pagination.value.pageNum, pageSize: pagination.value.pageSize, refundAudit: { ...searchForm.value, sortField: sortField.value, sortOrder: sortOrder.value } } console.log('看看传给后端的参数:', params) // 校验精网号(数字格式)
if (searchForm.value.jwcode) { // 纯数字
const numberRegex = /^\d{1,9}$/;
// 检查是否不是数字
if (!numberRegex.test(searchForm.value.jwcode)) { ElMessage.error('请检查精网号格式') // 上面提示过了
return } } const res = await API({ url: '/audit/selectRefund', data: params }) tableData.value = res.list || [] pagination.value.total = res.total || 0 console.log('查全部的total', pagination.value.total, res.total) } catch (error) { console.error('获取数据失败', error) }}const clicked = ref(false);// 通过
const handleApprove = async (row) => { if (!hasrefundWaitThough) { ElMessage.error('暂无权限') return } clicked.value = true try { const params = { orderCode: row.orderCode, auditId: adminData.value.id, action: 1,// action的1是通过,2是驳回
rejectReason: '' } await API({ url: '/audit/audit', data: params }) ElMessage.success('审核通过成功') await get() clicked.value = false await getStats() } catch (error) { console.error('审核通过失败', error) ElMessage.error('操作失败') }
}//控制驳回确认按钮禁用状态
const cancelClicked = ref(false)// 处理驳回操作
const handleReject = async () => { if (!hasrefundWaitReject) { ElMessage.error('暂无权限') return } cancelClicked.value = true
if (!rejectReason.value.trim()) { ElMessage.warning('请输入驳回理由') return } try { const params = { orderCode: scopeValue.value.orderCode, auditId: adminData.value.id, action: 2, rejectReason: rejectReason.value } await API({ url: '/audit/audit', data: params }) ElMessage.success('驳回成功') rejectDialogVisible.value = false await get() cancelClicked.value = false await getStats() console.log('看看驳回参数', params) } catch (error) { console.error('驳回失败', error) ElMessage.error('操作失败') }}
const getStats = async () => { if (!hasrefundWaitShow) { return } try { const params = { pageNum: pagination.value.pageNum, pageSize: pagination.value.pageSize, refundAudit: { ...searchForm.value } } if (searchForm.value.jwcode) { // 纯数字
const numberRegex = /^\d{1,9}$/;
// 检查是否不是数字
if (!numberRegex.test(searchForm.value.jwcode)) { // ElMessage.error('精网号必须为数字格式')
// 上面提示过了
return } } const res = await API({ url: '/audit/sumRefundGold', data: params })
stats.value.totalNum = res.totalNum stats.value.permanentGolds = res.permanentGolds / 100 stats.value.freeGolds = res.freeGolds / 100 stats.value.taskGolds = res.taskGolds / 100 console.log('see see stats和搜索对象', stats.value, params) } catch (error) { console.log('请求失败', error) }}// 搜索
const handleSearch = function () { trimJwCode() get() getStats()}// 重置
const resetSearch = function () { const auditStatus = searchForm.value.auditStatus; searchForm.value = { jwcode: '', refundType: '', goodsName: '', market: "", startTime: '', endTime: '', sortField: '', sortOrder: '', auditStatus: auditStatus } dateRange.value = [] activeTimeRange.value = '' // 清除激活状态
selectedMarketPath.value = [] get() getStats()}// 今天
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') dateRange.value = [startTime, endTime] console.log('dateRange', dateRange.value) activeTimeRange.value = 'today' get() getStats()}// 昨天
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') dateRange.value = [startTime, endTime] console.log('dateRange', dateRange.value) activeTimeRange.value = 'yesterday' get() getStats()}// 近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') dateRange.value = [startTime, endTime] console.log('dateRange', dateRange.value) activeTimeRange.value = '7days' get() getStats()}
const handleButtonClick = function (name) { activeName.value = name if (name === 'wait') { if (!hasrefundWait) { ElMessage.error('暂无权限') return } if (hasrefundWaitShow) { adminWait() } } else if (name === 'pass') { if (!hasrefundThrough) { ElMessage.error('暂无权限') return } adminPass() } else if (name === 'reject') { if (!hasrefundReject) { ElMessage.error('暂无权限') return } adminReject() }}// const handleClick = function (tab, event) {
// activeName.value = tab.props.name
// if (tab.props.name === 'wait') {
// console.log(hasrefundWait.value);
// if (!hasrefundWait) {
// ElMessage.error('暂无权限')
// return
// }
// adminWait()
// } else if (tab.props.name === 'pass') {
// if (!hasrefundThrough.value) {
// ElMessage.error('暂无权限')
// return
// }
// adminPass()
// } else if (tab.props.name === 'reject') {
// if (!hasrefundReject) {
// ElMessage.error('暂无权限')
// return
// }
// adminReject()
// }
// }
// 待审核
const adminWait = async function () { checkTab.value = 'pending' searchForm.value.auditStatus = STATUS.PENDING await get() await getStats()}// 已通过
const adminPass = async function () { checkTab.value = 'pass' searchForm.value.auditStatus = STATUS.APPROVED await get() await getStats()}// 已驳回
const adminReject = async function () { checkTab.value = 'reject' searchForm.value.auditStatus = STATUS.REJECTED await get() await getStats()}const selectedMarketPath = ref("")const handleMarketChange = (value) => { if (value && value.length > 0) { searchForm.value.market = value[value.length - 1] } else { searchForm.value.market = '' }}// 获取地区,修改为级联下拉框
const getMarket = async function () { try { 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 trimJwCode = () => { if (searchForm.value.jwcode) { searchForm.value.jwcode = searchForm.value.jwcode.replace(/\s/g, ''); }}// 日期选择器变化时清除按钮激活状态
const handleDatePickerChange = () => { activeTimeRange.value = ''}const format3 = (num) => { // 每三位添加逗号
return num.toLocaleString('en-US')}// 表单验证
const rules = reactive({ reason: [{ required: true, message: '请输入驳回理由', trigger: 'blur' }]})const handlePageSizeChange = function (val) { pagination.value.pageSize = val get()}const handleCurrentChange = function (val) { pagination.value.pageNum = val get()}onMounted(async () => { await initPermissions() if (hasrefundWaitShow.value) { searchForm.value.auditStatus = '0' } else if (hasrefundThrough.value) { searchForm.value.auditStatus = '1' } else if (hasrefundReject) { searchForm.value.auditStatus = '2' } getRefundGoods() await getMarket() await get() await getStats()})</script>
<style scoped lang="scss">.pagination { display: flex; margin-top: 0.5vh;}
.operation { display: flex;}
// 搜索的卡片样式
.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;}
/* 自定义按钮组布局 */.custom-button-group { display: flex; margin-bottom: 16px;}
/* 自定义激活状态样式 - 使用正确的Element Plus类选择器 */:deep(.el-button.custom-tab-button.el-button--primary) { background-color: #2741DE !important; border-color: #2741DE !important; color: #F3FAFE !important;}
/* 鼠标悬停效果 */:deep(.el-button.custom-tab-button:hover:not(.is-disabled)) { opacity: 0.8;}
.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>
|