forked from liweijie/education
532 lines
18 KiB
Vue
532 lines
18 KiB
Vue
<template>
|
||
<div class="app-container joint-training-page">
|
||
<div class="list-title">联教联训管理</div>
|
||
|
||
<!-- ==================== 1. 查询条件区域 ==================== -->
|
||
<el-card shadow="never" class="search-card">
|
||
<el-form :model="searchForm" label-width="40px" class="search-form">
|
||
<el-row :gutter="6">
|
||
<el-col :span="4">
|
||
<el-form-item label="名称">
|
||
<el-input v-model="searchForm.mc" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="2">
|
||
<div class="search-actions">
|
||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||
</div>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form>
|
||
</el-card>
|
||
|
||
<!-- ==================== 2. 操作区域 ==================== -->
|
||
<el-card shadow="never" class="upload-card">
|
||
<div class="upload-row">
|
||
<div class="upload-left">
|
||
<el-button type="primary" @click="handleAdd">新增联教联训</el-button>
|
||
<el-button icon="el-icon-download" @click="handleExport">导出 Excel</el-button>
|
||
<el-button icon="el-icon-download" @click="handleDownloadTemplate">【联教联训数据文件模板】下载</el-button>
|
||
<el-button icon="el-icon-folder-opened" @click="handleChooseFile">选择文件</el-button>
|
||
<span class="file-name" :class="{ 'has-file': selectedFile }">{{ fileName }}</span>
|
||
<input ref="fileInputRef" type="file" accept=".xls,.xlsx" style="display: none" @change="handleFileChange" />
|
||
<el-button type="primary" icon="el-icon-upload2" :loading="uploading" @click="handleUpload">上传数据</el-button>
|
||
</div>
|
||
</div>
|
||
</el-card>
|
||
|
||
<!-- ==================== 3. 数据表格 ==================== -->
|
||
<el-card shadow="never" class="table-card">
|
||
<div class="table-title">联教联训记录列表</div>
|
||
<el-table v-loading="tableLoading" :data="tableData" border stripe style="width: 100%">
|
||
<el-table-column type="index" label="序号" width="55" align="center" />
|
||
<el-table-column prop="bh" label="编号" width="150" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="mc" label="名称" min-width="140" show-overflow-tooltip />
|
||
<el-table-column prop="xz" label="性质" width="80" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="yj" label="依据" width="110" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="ksrq" label="开始日期" width="110" align="center" :formatter="fmtDateTime" />
|
||
<el-table-column prop="jsrq" label="结束日期" width="110" align="center" :formatter="fmtDateTime" />
|
||
<el-table-column prop="ts" label="天数" width="70" align="center" />
|
||
<el-table-column prop="jbksl" label="基本课时量" width="90" align="center" />
|
||
<el-table-column prop="kslx" label="课时类型" width="80" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="xmlx" label="项目类型" width="80" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="sm" label="说明" min-width="120" show-overflow-tooltip />
|
||
<el-table-column prop="bz" label="备注" min-width="120" show-overflow-tooltip />
|
||
<el-table-column label="操作" width="160" align="center" fixed="right">
|
||
<template slot-scope="{ row }">
|
||
<el-button type="text" size="small" @click="handleDetail(row)">详情</el-button>
|
||
<el-button type="text" size="small" @click="handleEdit(row)">修改</el-button>
|
||
<el-button type="text" size="small" class="text-danger" @click="handleDelete(row)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
|
||
<el-pagination
|
||
:current-page="pageNum"
|
||
:page-size="pageSize"
|
||
:total="total"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
layout="total, sizes, prev, pager, next, jumper"
|
||
class="pagination"
|
||
@current-change="handlePageChange"
|
||
@size-change="handleSizeChange"
|
||
/>
|
||
</el-card>
|
||
|
||
<!-- ==================== 4. 新增/修改对话框 ==================== -->
|
||
<el-dialog
|
||
:visible="dialogVisible"
|
||
:title="dialogTitle"
|
||
width="720px"
|
||
:close-on-click-modal="false"
|
||
@update:visible="val => dialogVisible = val"
|
||
>
|
||
<el-form ref="formRef" :model="form" :rules="rules" label-width="110px" class="add-form">
|
||
<el-row :gutter="16">
|
||
<el-col :span="12">
|
||
<el-form-item label="编号">
|
||
<el-input v-model="form.bh" placeholder="留空则自动生成" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="名称" prop="mc">
|
||
<el-input v-model="form.mc" placeholder="请输入名称" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12">
|
||
<el-form-item label="性质">
|
||
<el-input v-model="form.xz" placeholder="请输入性质" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="依据">
|
||
<el-input v-model="form.yj" placeholder="请输入依据" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12">
|
||
<el-form-item label="开始日期">
|
||
<el-date-picker v-model="form.ksrq" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择开始日期" clearable class="w-full" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="结束日期">
|
||
<el-date-picker v-model="form.jsrq" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择结束日期" clearable class="w-full" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12">
|
||
<el-form-item label="天数">
|
||
<el-input-number v-model="form.ts" :min="0" :precision="1" :step="1" class="w-full" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="基本课时量">
|
||
<el-input-number v-model="form.jbksl" :min="0" :precision="1" :step="0.5" class="w-full" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12">
|
||
<el-form-item label="课时类型">
|
||
<el-input v-model="form.kslx" placeholder="请输入课时类型" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="项目类型">
|
||
<el-input v-model="form.xmlx" placeholder="请输入项目类型" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-form-item label="说明">
|
||
<el-input v-model="form.sm" type="textarea" :rows="2" placeholder="请输入说明" />
|
||
</el-form-item>
|
||
<el-form-item label="备注">
|
||
<el-input v-model="form.bz" type="textarea" :rows="2" placeholder="请输入备注" />
|
||
</el-form-item>
|
||
</el-form>
|
||
<div slot="footer">
|
||
<el-button @click="dialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="saving" @click="handleSubmit">确定</el-button>
|
||
</div>
|
||
</el-dialog>
|
||
|
||
<!-- ==================== 5. 详情对话框 ==================== -->
|
||
<el-dialog :visible="detailVisible" title="联教联训详情" width="640px" @update:visible="val => detailVisible = val">
|
||
<el-descriptions :column="2" border>
|
||
<el-descriptions-item label="编号">{{ detailData.bh }}</el-descriptions-item>
|
||
<el-descriptions-item label="名称">{{ detailData.mc }}</el-descriptions-item>
|
||
<el-descriptions-item label="性质">{{ fmtEmpty(detailData.xz) }}</el-descriptions-item>
|
||
<el-descriptions-item label="依据">{{ fmtEmpty(detailData.yj) }}</el-descriptions-item>
|
||
<el-descriptions-item label="开始日期">{{ fmtDateTime(null, null, detailData.ksrq) }}</el-descriptions-item>
|
||
<el-descriptions-item label="结束日期">{{ fmtDateTime(null, null, detailData.jsrq) }}</el-descriptions-item>
|
||
<el-descriptions-item label="天数">{{ fmtValue(detailData.ts) }}</el-descriptions-item>
|
||
<el-descriptions-item label="基本课时量">{{ fmtValue(detailData.jbksl) }}</el-descriptions-item>
|
||
<el-descriptions-item label="课时类型">{{ fmtEmpty(detailData.kslx) }}</el-descriptions-item>
|
||
<el-descriptions-item label="项目类型">{{ fmtEmpty(detailData.xmlx) }}</el-descriptions-item>
|
||
<el-descriptions-item label="说明" :span="2">{{ fmtEmpty(detailData.sm) }}</el-descriptions-item>
|
||
<el-descriptions-item label="备注" :span="2">{{ fmtEmpty(detailData.bz) }}</el-descriptions-item>
|
||
</el-descriptions>
|
||
<div slot="footer">
|
||
<el-button @click="detailVisible = false">关闭</el-button>
|
||
</div>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import { saveAs } from 'file-saver'
|
||
import {
|
||
listJointTraining,
|
||
addJointTraining,
|
||
updateJointTraining,
|
||
deleteJointTraining,
|
||
getJointTraining,
|
||
importJointTraining,
|
||
exportJointTraining
|
||
} from '@/api/classHour/jointTraining'
|
||
|
||
export default {
|
||
name: 'JointTrainingIndex',
|
||
data() {
|
||
return {
|
||
// ==================== 1. 查询条件 ====================
|
||
searchForm: {
|
||
mc: ''
|
||
},
|
||
|
||
// ==================== 2. 文件操作 ====================
|
||
selectedFile: null,
|
||
uploading: false,
|
||
|
||
// ==================== 3. 表格数据 ====================
|
||
tableLoading: false,
|
||
tableData: [],
|
||
pageNum: 1,
|
||
pageSize: 10,
|
||
total: 0,
|
||
|
||
// ==================== 4. 新增/修改表单 ====================
|
||
dialogVisible: false,
|
||
dialogTitle: '新增联教联训',
|
||
saving: false,
|
||
form: this.createEmptyForm(),
|
||
rules: {
|
||
mc: [{ required: true, message: '请输入名称', trigger: 'blur' }]
|
||
},
|
||
|
||
// ==================== 5. 详情 ====================
|
||
detailVisible: false,
|
||
detailData: {}
|
||
}
|
||
},
|
||
computed: {
|
||
fileName() {
|
||
return (this.selectedFile && this.selectedFile.name) || '未选择任何文件'
|
||
}
|
||
},
|
||
mounted() {
|
||
this.fetchList()
|
||
},
|
||
methods: {
|
||
createEmptyForm() {
|
||
return {
|
||
bh: '',
|
||
mc: '',
|
||
xz: '',
|
||
yj: '',
|
||
ksrq: '',
|
||
jsrq: '',
|
||
ts: null,
|
||
jbksl: null,
|
||
kslx: '',
|
||
xmlx: '',
|
||
sm: '',
|
||
bz: ''
|
||
}
|
||
},
|
||
|
||
/** 把后端 LocalDateTime(含 T/毫秒)规范为表单可回显的格式 */
|
||
normalizeDateTime(val) {
|
||
if (!val) return ''
|
||
return String(val).replace('T', ' ').replace(/\.\d+$/, '').slice(0, 19)
|
||
},
|
||
|
||
// ==================== 查询 ====================
|
||
fetchList() {
|
||
this.tableLoading = true
|
||
const params = { pageNum: this.pageNum, pageSize: this.pageSize }
|
||
if (this.searchForm.mc && this.searchForm.mc.trim()) params.mc = this.searchForm.mc.trim()
|
||
listJointTraining(params).then(res => {
|
||
const data = (res && res.data) || {}
|
||
this.tableData = data.records || []
|
||
this.total = data.total || 0
|
||
this.tableLoading = false
|
||
}).catch(() => {
|
||
this.tableData = []
|
||
this.total = 0
|
||
this.tableLoading = false
|
||
})
|
||
},
|
||
|
||
handleQuery() {
|
||
this.pageNum = 1
|
||
this.fetchList()
|
||
},
|
||
|
||
handlePageChange(page) {
|
||
this.pageNum = page
|
||
this.fetchList()
|
||
},
|
||
|
||
handleSizeChange(size) {
|
||
this.pageSize = size
|
||
this.pageNum = 1
|
||
this.fetchList()
|
||
},
|
||
|
||
/** 日期时间显示(去掉 T、截断到分钟) */
|
||
fmtDateTime(row, column, cellValue) {
|
||
if (cellValue === null || cellValue === undefined || cellValue === '') return '-'
|
||
return String(cellValue).replace('T', ' ').slice(0, 16)
|
||
},
|
||
|
||
/** 空值显示为 '-' */
|
||
fmtEmpty(val) {
|
||
return val === null || val === undefined || val === '' ? '-' : val
|
||
},
|
||
|
||
/** 数值空值显示为 '-'(保留 0) */
|
||
fmtValue(val) {
|
||
return val === null || val === undefined ? '-' : val
|
||
},
|
||
|
||
// ==================== 新增 / 修改 ====================
|
||
handleAdd() {
|
||
this.form = this.createEmptyForm()
|
||
this.dialogTitle = '新增联教联训'
|
||
this.dialogVisible = true
|
||
},
|
||
|
||
handleEdit(row) {
|
||
getJointTraining(row.bh).then(res => {
|
||
const d = (res && res.data) || {}
|
||
this.form = {
|
||
bh: d.bh || '',
|
||
mc: d.mc || '',
|
||
xz: d.xz || '',
|
||
yj: d.yj || '',
|
||
ksrq: this.normalizeDateTime(d.ksrq),
|
||
jsrq: this.normalizeDateTime(d.jsrq),
|
||
ts: d.ts === null || d.ts === undefined ? null : d.ts,
|
||
jbksl: d.jbksl === null || d.jbksl === undefined ? null : d.jbksl,
|
||
kslx: d.kslx || '',
|
||
xmlx: d.xmlx || '',
|
||
sm: d.sm || '',
|
||
bz: d.bz || ''
|
||
}
|
||
this.dialogTitle = '修改联教联训'
|
||
this.dialogVisible = true
|
||
}).catch(() => {})
|
||
},
|
||
|
||
handleSubmit() {
|
||
this.$refs.formRef.validate(valid => {
|
||
if (!valid) {
|
||
this.$message.warning('请完善必填项后再提交')
|
||
return
|
||
}
|
||
const payload = this.buildPayload()
|
||
this.saving = true
|
||
const req = payload.bh ? updateJointTraining(payload) : addJointTraining(payload)
|
||
req.then(() => {
|
||
this.$message.success(this.dialogTitle === '修改联教联训' ? '修改成功' : '新增成功')
|
||
this.dialogVisible = false
|
||
this.fetchList()
|
||
}).catch(() => {}).finally(() => {
|
||
this.saving = false
|
||
})
|
||
})
|
||
},
|
||
|
||
/** 构建请求体,仅含实体非空字段(创建/修改时间为后端自动维护,不传) */
|
||
buildPayload() {
|
||
const f = this.form
|
||
const payload = {}
|
||
if (f.bh && f.bh.trim()) payload.bh = f.bh.trim()
|
||
if (f.mc && f.mc.trim()) payload.mc = f.mc.trim()
|
||
if (f.xz && f.xz.trim()) payload.xz = f.xz.trim()
|
||
if (f.yj && f.yj.trim()) payload.yj = f.yj.trim()
|
||
if (f.ksrq) payload.ksrq = f.ksrq
|
||
if (f.jsrq) payload.jsrq = f.jsrq
|
||
if (f.ts !== null && f.ts !== undefined) payload.ts = f.ts
|
||
if (f.jbksl !== null && f.jbksl !== undefined) payload.jbksl = f.jbksl
|
||
if (f.kslx && f.kslx.trim()) payload.kslx = f.kslx.trim()
|
||
if (f.xmlx && f.xmlx.trim()) payload.xmlx = f.xmlx.trim()
|
||
if (f.sm && f.sm.trim()) payload.sm = f.sm.trim()
|
||
if (f.bz && f.bz.trim()) payload.bz = f.bz.trim()
|
||
return payload
|
||
},
|
||
|
||
// ==================== 删除 ====================
|
||
handleDelete(row) {
|
||
this.$confirm(`确定要删除「${row.mc || row.bh || '该记录'}」吗?`, '系统提示', {
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
type: 'warning'
|
||
}).then(() => deleteJointTraining(row.bh)).then(() => {
|
||
this.$message.success('删除成功')
|
||
this.fetchList()
|
||
}).catch(() => {})
|
||
},
|
||
|
||
// ==================== 详情 ====================
|
||
handleDetail(row) {
|
||
getJointTraining(row.bh).then(res => {
|
||
this.detailData = (res && res.data) || {}
|
||
this.detailVisible = true
|
||
}).catch(() => {})
|
||
},
|
||
|
||
// ==================== 导出 ====================
|
||
handleExport() {
|
||
exportJointTraining().then(blob => {
|
||
saveAs(blob, '联教联训管理.xlsx')
|
||
this.$message.success('导出成功')
|
||
}).catch(() => {})
|
||
},
|
||
|
||
// ==================== 文件选择与导入 ====================
|
||
handleChooseFile() {
|
||
this.$refs.fileInputRef && this.$refs.fileInputRef.click()
|
||
},
|
||
|
||
handleFileChange(e) {
|
||
const input = e.target
|
||
this.selectedFile = (input.files && input.files[0]) || null
|
||
},
|
||
|
||
handleUpload() {
|
||
if (!this.selectedFile) {
|
||
this.$message.warning('请先选择文件')
|
||
return
|
||
}
|
||
this.uploading = true
|
||
importJointTraining(this.selectedFile).then(res => {
|
||
const count = res && res.data
|
||
if (count !== null && count !== undefined) {
|
||
this.$message.success(`导入成功,共 ${count} 条记录`)
|
||
} else {
|
||
this.$message.success((res && res.msg) || '导入成功')
|
||
}
|
||
this.selectedFile = null
|
||
this.$refs.fileInputRef && (this.$refs.fileInputRef.value = '')
|
||
this.pageNum = 1
|
||
this.fetchList()
|
||
}).catch(() => {}).finally(() => {
|
||
this.uploading = false
|
||
})
|
||
},
|
||
|
||
handleDownloadTemplate() {
|
||
// 后端暂未提供模板下载接口,仅作提示
|
||
this.$message.info('后端暂未提供该接口')
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.app-container {
|
||
padding: 20px;
|
||
}
|
||
|
||
.joint-training-page {
|
||
.list-title {
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
// ==================== 1. 查询条件区域 ====================
|
||
.search-card {
|
||
margin-bottom: 16px;
|
||
|
||
.search-form {
|
||
.w-full {
|
||
width: 100%;
|
||
}
|
||
|
||
.search-actions {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
align-items: center;
|
||
height: 40px;
|
||
}
|
||
}
|
||
}
|
||
|
||
// ==================== 2. 操作区域 ====================
|
||
.upload-card {
|
||
margin-bottom: 16px;
|
||
|
||
.upload-row {
|
||
display: flex;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
gap: 12px;
|
||
|
||
.upload-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
flex-wrap: wrap;
|
||
|
||
.file-name {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
|
||
&.has-file {
|
||
color: #303133;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// ==================== 3. 数据表格 ====================
|
||
.table-card {
|
||
margin-bottom: 16px;
|
||
|
||
.table-title {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.pagination {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
margin-top: 12px;
|
||
}
|
||
|
||
.text-danger {
|
||
color: #f56c6c;
|
||
}
|
||
}
|
||
|
||
// ==================== 4. 新增/修改表单 ====================
|
||
.add-form {
|
||
max-height: 62vh;
|
||
overflow-y: auto;
|
||
padding-right: 4px;
|
||
}
|
||
}
|
||
</style>
|