fix: 功能优化,活动记录费用优化。
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
<el-table-column label="活动时长" align="center" prop="exerciseTimeStr" width="150"> </el-table-column>
|
||||
<el-table-column label="成员" align="center" prop="partner" />
|
||||
<el-table-column label="总费用(元)" width="120" align="center" prop="totalCost" />
|
||||
<el-table-column label="操作" width="140" align="center" class-name="small-padding fixed-width">
|
||||
<el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
|
||||
<template v-slot="scope">
|
||||
<div class="ctrl-btn d-flex">
|
||||
<el-tooltip v-for="item in operateList" :key="item.id" class="item" effect="dark" :content="item.title" placement="top">
|
||||
@@ -126,16 +126,54 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 费用汇总对话框 -->
|
||||
<el-dialog title="费用汇总" v-model="summaryDialogVisible" width="1200px" append-to-body>
|
||||
<div v-loading="summaryLoading">
|
||||
<el-table :data="expenseList" @selection-change="handleExpenseSelectionChange" max-height="500">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="账户名称" align="center" width="180" prop="accountName" />
|
||||
<el-table-column label="交易时间" align="center" width="160" prop="createTime" />
|
||||
<el-table-column label="交易金额" align="center" width="100" prop="amount" />
|
||||
<el-table-column label="交易类别" align="center" width="140" prop="dealCategory">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="deal_category" :value="scope.row.dealCategory" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="交易子类别" align="center" width="140" prop="childCategoryName" />
|
||||
<el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip />
|
||||
</el-table>
|
||||
<div style="margin-top: 16px; text-align: right; color: #606266; font-size: 14px">
|
||||
已选 <span style="color: #409eff; font-weight: bold">{{ selectedExpenses.length }}</span> 条, 合计金额:<span
|
||||
style="color: #f56c6c; font-weight: bold; font-size: 16px"
|
||||
>{{ calculateTotalAmount() }}</span
|
||||
>
|
||||
元
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="confirmSummary" :disabled="selectedExpenses.length === 0">确认汇总</el-button>
|
||||
<el-button @click="summaryDialogVisible = false">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="Activity">
|
||||
import { listActivity, getActivity, delActivity, addActivity, updateActivity } from '@/api/health/activity'
|
||||
import { listAccountDealRecord } from '@/api/invest/accountDealRecord'
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import dayjs from 'dayjs'
|
||||
import { require } from '@/utils/require'
|
||||
const { proxy } = getCurrentInstance()
|
||||
const { activity_type, activity_exercise } = proxy.useDict('activity_type', 'activity_exercise')
|
||||
const { activity_type, activity_exercise, deal_category, daily_expenses } = proxy.useDict(
|
||||
'activity_type',
|
||||
'activity_exercise',
|
||||
'deal_category',
|
||||
'daily_expenses'
|
||||
)
|
||||
|
||||
const activityList = ref([])
|
||||
const open = ref(false)
|
||||
@@ -146,9 +184,16 @@ const single = ref(true)
|
||||
const multiple = ref(true)
|
||||
const total = ref(0)
|
||||
const title = ref('')
|
||||
const summaryDialogVisible = ref(false)
|
||||
const summaryLoading = ref(false)
|
||||
const expenseList = ref([])
|
||||
const selectedExpenses = ref([])
|
||||
const currentActivityId = ref(null)
|
||||
const summaryTotal = ref(0)
|
||||
const operateList = ref([
|
||||
{ id: 'view', icon: 'View', title: '查看', hasPermi: ['health:activity:query'] },
|
||||
{ id: 'edit', icon: 'Edit', title: '修改', hasPermi: ['health:activity:edit'] },
|
||||
{ id: 'summary', icon: 'Money', title: '费用汇总', hasPermi: ['health:activity:edit'] },
|
||||
{ id: 'delete', icon: 'Delete', title: '删除', hasPermi: ['health:activity:remove'] }
|
||||
])
|
||||
const data = reactive({
|
||||
@@ -182,6 +227,9 @@ const handleOperate = (operate, row) => {
|
||||
case 'edit':
|
||||
handleUpdate(row)
|
||||
break
|
||||
case 'summary':
|
||||
handleCostSummary(row)
|
||||
break
|
||||
case 'delete':
|
||||
handleDelete(row)
|
||||
break
|
||||
@@ -345,5 +393,84 @@ function handleExport() {
|
||||
)
|
||||
}
|
||||
|
||||
// 费用汇总按钮操作
|
||||
function handleCostSummary(row) {
|
||||
currentActivityId.value = row.id
|
||||
summaryDialogVisible.value = true
|
||||
summaryLoading.value = true
|
||||
|
||||
// 构建查询参数
|
||||
const queryExpenseParams = {
|
||||
pageNum: 1,
|
||||
pageSize: 1000,
|
||||
dealCategory: '1', // 日常支出
|
||||
startTime: row.startTime ? dayjs(row.startTime).format('YYYY-MM-DD') : '',
|
||||
endTime: row.endTime ? dayjs(row.endTime).format('YYYY-MM-DD') : dayjs().format('YYYY-MM-DD')
|
||||
}
|
||||
|
||||
// 查询日常支出列表
|
||||
listAccountDealRecord(queryExpenseParams)
|
||||
.then((response) => {
|
||||
expenseList.value = response.rows || []
|
||||
summaryLoading.value = false
|
||||
})
|
||||
.catch(() => {
|
||||
summaryLoading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
// 多选框选中数据(费用汇总)
|
||||
function handleExpenseSelectionChange(selection) {
|
||||
selectedExpenses.value = selection
|
||||
}
|
||||
|
||||
// 计算选中费用总额
|
||||
function calculateTotalAmount() {
|
||||
return selectedExpenses.value
|
||||
.reduce((sum, item) => {
|
||||
return sum + (parseFloat(item.amount) || 0)
|
||||
}, 0)
|
||||
.toFixed(2)
|
||||
}
|
||||
|
||||
// 确认汇总
|
||||
function confirmSummary() {
|
||||
if (selectedExpenses.value.length === 0) {
|
||||
proxy.$modal.msgWarning('请至少选择一条费用记录')
|
||||
return
|
||||
}
|
||||
|
||||
// 获取活动详情
|
||||
getActivity(currentActivityId.value).then((response) => {
|
||||
const activity = response.data
|
||||
|
||||
// 计算总金额
|
||||
const totalAmount = parseFloat(calculateTotalAmount())
|
||||
const currentTotal = parseFloat(activity.totalCost) || 0
|
||||
|
||||
// 构建费用明细
|
||||
const details = selectedExpenses.value
|
||||
.map((item) => {
|
||||
const category = item.childCategoryName || ''
|
||||
return `${category} ${item.amount}元${item.remark ? '(' + item.remark + ')' : ''}`
|
||||
})
|
||||
.join(';')
|
||||
|
||||
// 更新活动费用
|
||||
const updateData = {
|
||||
...activity,
|
||||
totalCost: (currentTotal + totalAmount).toFixed(2),
|
||||
costDetail: activity.costDetail ? `${activity.costDetail};${details}` : details
|
||||
}
|
||||
|
||||
updateActivity(updateData).then(() => {
|
||||
proxy.$modal.msgSuccess('费用汇总成功')
|
||||
summaryDialogVisible.value = false
|
||||
selectedExpenses.value = []
|
||||
getList()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
getList()
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user