yn_digital_gadgets_web/src/views/planMange/dailyPlan/index.vue

249 lines
7.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="app-container">
<el-card class="top-radio">
<el-radio-group v-model="tableType">
<el-radio-button label="运行" value="0" />
<el-radio-button label="检修" value="1" />
<el-radio-button label="项目部" value="2" />
</el-radio-group>
<ComButton type="info" plain icon="Download" @click="onDownloadStatistic">
下载统计表
</ComButton>
</el-card>
<!-- 日计划填报管理列表 -->
<ComTable
ref="comTableRef"
:key="tableType"
:show-toolbar="true"
:show-action="true"
:form-columns="formColumns"
:load-data="listDailyPlanAPI"
:table-columns="initTableColumns"
:action-columns="actionColumns"
:defaultQueryParams="{ dayPlanType: tableType }"
>
<template #toolbar>
<ComButton type="primary" icon="Plus" @click="onHandleAdd">新增日计划</ComButton>
<ComButton
plain
type="info"
icon="Download"
@click="onDownloadWorkloadSummary"
v-if="['1', '2'].includes(tableType)"
>
下载工作量统计表
</ComButton>
</template>
</ComTable>
<ComDialog :dialog-config="dialogConfig" @closeDialogOuter="onCloseDialogOuter">
<template #outerContent>
<AddForm ref="addFormRef" />
<el-row class="common-btn-row">
<ComButton plain type="info" @click="onHandleCancel">取消</ComButton>
<ComButton @click="onHandleSave">保存</ComButton>
</el-row>
</template>
</ComDialog>
</div>
</template>
<script setup name="MonthlyPlan">
import { ref, computed, getCurrentInstance } from 'vue'
import { useRouter } from 'vue-router'
import { listDailyPlanAPI, delDailyPlanAPI, addDailyPlanAPI } from '@/api/planMange/dailyPlan.js'
import useDictStore from '@/store/modules/dict'
import { selectDictLabel } from '@/utils/ruoyi'
import dayjs from 'dayjs'
import config from './config'
import ComTable from '@/components/ComTable/index.vue'
import ComButton from '@/components/ComButton/index.vue'
import ComDialog from '@/components/ComDialog/index.vue'
import AddForm from './addForm.vue'
const router = useRouter()
const { proxy } = getCurrentInstance()
const dictStore = useDictStore()
const {
tableColumns: baseTableColumns,
tableColumns_1,
tableColumns_2,
dialogConfig,
buildFormColumns,
} = config
const comTableRef = ref(null)
const addFormRef = ref(null)
const tableType = ref('0')
// 搜索表单配置(当前月计划场景暂不依赖下拉接口,直接使用静态配置)
const formColumns = computed(() => buildFormColumns())
// 创建动态 formatter 函数,每次执行时从 store 获取最新的字典数据
const createDynamicDictFormatter = (dictType, fieldName = null) => {
return (row, column, cellValue) => {
const value = fieldName ? row[fieldName] : cellValue
// 每次执行时都从 store 获取最新的字典数据
const dictData = dictStore.getDict(dictType) || []
return selectDictLabel(dictData, value)
}
}
// 构建表格列配置,添加字典映射的 formatter
const tableColumns = computed(() => {
return baseTableColumns.map((column) => {
if (column.prop === 'riskLevel') {
return {
...column,
// 使用动态 formatter每次执行时都会获取最新的字典数据
formatter: createDynamicDictFormatter('plan_risk_level', 'riskLevel'),
}
}
return column
})
})
const initTableColumns = computed(() => {
if (tableType.value === '0') return [...tableColumns.value, ...tableColumns_1]
if (tableType.value !== '0') return [...tableColumns.value, ...tableColumns_2]
})
// 操作列
const actionColumns = computed(() => [
{
label: '详情',
type: 'primary',
link: true,
handler: (row) => {
router.push({
path: '/plan/dailyPlanEdit/index',
query: {
id: row.planId || row.dayPlanId,
mode: 'detail',
dayPlanType: tableType.value,
inspectionStationName: row.inspectionStationName,
projectName: row.projectName,
planMajorName: row.planMajorName,
dayPlan: row.dayPlan,
},
})
},
},
{
label: '编辑',
type: 'primary',
link: true,
handler: (row) => {
router.push({
path: '/plan/dailyPlanEdit/index',
query: {
id: row.planId || row.dayPlanId,
mode: 'edit',
dayPlanType: tableType.value,
inspectionStationName: row.inspectionStationName,
projectName: row.projectName,
planMajorName: row.planMajorName,
dayPlan: row.dayPlan,
},
})
},
},
{
label: '删除',
type: 'danger',
link: true,
handler: (row) => {
proxy.$modal.confirm('是否确认删除该日计划?').then(async () => {
const result = await delDailyPlanAPI({ dayPlanId: row.dayPlanId })
if (result.code === 200) {
proxy.$modal.msgSuccess('删除成功')
comTableRef.value?.refresh()
}
})
},
},
])
// 新增
const onHandleAdd = () => {
dialogConfig.outerVisible = true
}
// 取消
const onHandleCancel = () => {
dialogConfig.outerVisible = false
}
// 保存
const onHandleSave = async () => {
await addFormRef.value.validate()
const paramsList = addFormRef.value.getSelectedTasks().map((item) => ({
dayPlan: addFormRef.value.getCurrentDate(),
monthlyPlanId: item.monthlyPlanId,
dayPlanType: tableType.value,
riskLevel: item.riskLevel,
}))
const result = await addDailyPlanAPI(paramsList)
if (result.code === 200) {
proxy.$modal.msgSuccess('保存成功')
dialogConfig.outerVisible = false
comTableRef.value?.refresh()
}
}
// 关闭弹框统一处理
const onCloseDialogOuter = (visible) => {
dialogConfig.outerVisible = visible
}
// 编辑调试
const onHandleEdit = () => {
router.push({
path: '/plan/dailyPlanEdit/index',
query: {
mode: 'edit',
dayPlanType: tableType.value,
},
})
}
// 下载统计表
const onDownloadStatistic = () => {
proxy.download(
'/download/dayPlanStatistics',
{
dayPlanType: tableType.value,
startDate: dayjs().startOf('month').format('YYYY-MM-DD'),
endDate: dayjs().endOf('month').format('YYYY-MM-DD'),
},
`日计划统计表.xlsx`,
)
}
// 下载工作量统计表
const onDownloadWorkloadSummary = () => {
proxy.download(
'/monthlyPlan/exportWorkloadSummary',
{
dayPlanType: tableType.value,
},
`${tableType.value === '1' ? '检修' : '项目部'}统计表.xlsx`,
)
}
</script>
<style scoped lang="scss">
.top-radio {
margin-bottom: 10px;
:deep(.el-card__body) {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 20px !important;
}
}
</style>