354 lines
11 KiB
Vue
354 lines
11 KiB
Vue
<template>
|
||
<div class="app-container teach-office">
|
||
<!-- 查询条件区域 -->
|
||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="88px" v-show="showSearch">
|
||
<el-form-item label="教研室代号" prop="jysdh">
|
||
<el-input
|
||
v-model="queryParams.jysdh"
|
||
placeholder="请输入教研室代号"
|
||
clearable
|
||
style="width: 160px"
|
||
@keyup.enter.native="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="教研室名称" prop="jysmc">
|
||
<el-input
|
||
v-model="queryParams.jysmc"
|
||
placeholder="请输入教研室名称"
|
||
clearable
|
||
style="width: 180px"
|
||
@keyup.enter.native="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="部系" prop="bx">
|
||
<el-input
|
||
v-model="queryParams.bx"
|
||
placeholder="请输入部系"
|
||
clearable
|
||
style="width: 160px"
|
||
@keyup.enter.native="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="停用" prop="ty">
|
||
<el-radio-group v-model="queryParams.ty">
|
||
<el-radio :label="1">是</el-radio>
|
||
<el-radio :label="0">否</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
|
||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<!-- 操作按钮区域 -->
|
||
<el-row :gutter="10" class="mb8">
|
||
<el-col :span="1.5">
|
||
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
|
||
</el-col>
|
||
<el-col :span="1.5">
|
||
<el-button type="info" plain icon="el-icon-upload2" size="mini" @click="openImport">导入</el-button>
|
||
</el-col>
|
||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||
</el-row>
|
||
|
||
<!-- 数据列表区域 -->
|
||
<el-table v-loading="loading" :data="officeList" border :height="tableHeight">
|
||
<el-table-column type="index" label="序号" width="55" align="center" />
|
||
<el-table-column label="教研室代号" align="center" prop="jysdh" min-width="110" />
|
||
<el-table-column label="教研室名称" align="center" prop="jysmc" min-width="160" :show-overflow-tooltip="true" />
|
||
<el-table-column label="简称" align="center" prop="jc" min-width="90" />
|
||
<el-table-column label="部系" align="center" prop="bx" min-width="100" />
|
||
<el-table-column label="机关性质" align="center" min-width="90">
|
||
<template slot-scope="scope">
|
||
<el-tag :type="scope.row.jgxz ? 'primary' : 'info'" size="mini">{{ scope.row.jgxz ? '是' : '否' }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="停用" align="center" min-width="80">
|
||
<template slot-scope="scope">
|
||
<el-tag :type="scope.row.ty ? 'danger' : 'success'" size="mini">{{ scope.row.ty ? '是' : '否' }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="备注" align="center" prop="bz" min-width="120" :show-overflow-tooltip="true" />
|
||
<el-table-column label="操作" align="center" min-width="140" class-name="small-padding fixed-width">
|
||
<template slot-scope="scope">
|
||
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
|
||
<el-button
|
||
size="mini"
|
||
type="text"
|
||
icon="el-icon-circle-close"
|
||
style="color: #f56c6c"
|
||
:disabled="scope.row.ty === 1"
|
||
@click="handleDisable(scope.row)"
|
||
>停用</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
|
||
<pagination
|
||
v-show="total > 0"
|
||
:total="total"
|
||
:page.sync="queryParams.pageNum"
|
||
:limit.sync="queryParams.pageSize"
|
||
@pagination="getList"
|
||
/>
|
||
|
||
<!-- 新增/编辑对话框 -->
|
||
<el-dialog :title="title" :visible.sync="open" width="560px" append-to-body>
|
||
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||
<el-form-item label="教研室代号" prop="jysdh">
|
||
<el-input v-model="form.jysdh" placeholder="请输入教研室代号" :disabled="!isAdd" maxlength="20" />
|
||
</el-form-item>
|
||
<el-form-item label="教研室名称" prop="jysmc">
|
||
<el-input v-model="form.jysmc" placeholder="请输入教研室名称" maxlength="50" />
|
||
</el-form-item>
|
||
<el-form-item label="简称" prop="jc">
|
||
<el-input v-model="form.jc" placeholder="请输入简称" maxlength="20" />
|
||
</el-form-item>
|
||
<el-form-item label="部系" prop="bx">
|
||
<el-input v-model="form.bx" placeholder="请输入部系" maxlength="30" />
|
||
</el-form-item>
|
||
<el-form-item label="序号" prop="xh">
|
||
<el-input v-model="form.xh" placeholder="请输入序号" maxlength="10" />
|
||
</el-form-item>
|
||
<el-form-item label="备注" prop="bz">
|
||
<el-input v-model="form.bz" type="textarea" placeholder="请输入备注" :rows="3" maxlength="200" show-word-limit />
|
||
</el-form-item>
|
||
</el-form>
|
||
<div slot="footer" class="dialog-footer">
|
||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||
<el-button @click="cancel">取 消</el-button>
|
||
</div>
|
||
</el-dialog>
|
||
|
||
<!-- 导入对话框 -->
|
||
<el-dialog title="教研室数据导入" :visible.sync="importOpen" width="420px" append-to-body>
|
||
<el-upload
|
||
ref="uploadRef"
|
||
:action="importUrl"
|
||
:headers="uploadHeaders"
|
||
:on-success="handleImportSuccess"
|
||
:on-error="handleImportError"
|
||
:limit="1"
|
||
:before-upload="beforeImport"
|
||
accept=".xls, .xlsx"
|
||
drag
|
||
>
|
||
<i class="el-icon-upload"></i>
|
||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
||
<div class="el-upload__tip text-center" slot="tip">
|
||
<span>仅允许导入 xls、xlsx 格式文件。</span>
|
||
</div>
|
||
</el-upload>
|
||
<div slot="footer" class="dialog-footer">
|
||
<el-button type="primary" @click="submitImport">确 定</el-button>
|
||
<el-button @click="importOpen = false">取 消</el-button>
|
||
</div>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import { listOffice, addOffice, updateOffice, disableOffice } from "@/api/teachOffice/office"
|
||
import { getToken } from '@/utils/auth'
|
||
|
||
export default {
|
||
name: "Office",
|
||
data() {
|
||
return {
|
||
// 遮罩层
|
||
loading: true,
|
||
// 显示搜索条件
|
||
showSearch: true,
|
||
// 表格高度
|
||
tableHeight: window.innerHeight - 280,
|
||
// 总条数
|
||
total: 0,
|
||
// 教研室列表数据
|
||
officeList: [],
|
||
// 弹出层标题
|
||
title: "",
|
||
// 是否显示新增/编辑弹出层
|
||
open: false,
|
||
// 是否新增(false 为编辑)
|
||
isAdd: true,
|
||
// 是否显示导入弹出层
|
||
importOpen: false,
|
||
// 查询参数
|
||
queryParams: {
|
||
pageNum: 1,
|
||
pageSize: 20,
|
||
jysdh: undefined,
|
||
jysmc: undefined,
|
||
bx: undefined,
|
||
ty: undefined
|
||
},
|
||
// 表单参数
|
||
form: {},
|
||
// 表单校验
|
||
rules: {
|
||
jysdh: [
|
||
{ required: true, message: "教研室代号不能为空", trigger: "blur" }
|
||
],
|
||
jysmc: [
|
||
{ required: true, message: "教研室名称不能为空", trigger: "blur" }
|
||
]
|
||
}
|
||
}
|
||
},
|
||
computed: {
|
||
importUrl() {
|
||
return process.env.VUE_APP_BASE_API + '/jys/office/import'
|
||
},
|
||
uploadHeaders() {
|
||
return { Authorization: 'Bearer ' + getToken() }
|
||
}
|
||
},
|
||
created() {
|
||
this.getList()
|
||
},
|
||
methods: {
|
||
/** 查询教研室列表 */
|
||
getList() {
|
||
this.loading = true
|
||
listOffice(this.queryParams).then(response => {
|
||
// 后端返回 MyBatis-Plus 分页结构:data.records / data.total
|
||
const data = response.data || {}
|
||
this.officeList = data.records || []
|
||
this.total = data.total || 0
|
||
this.loading = false
|
||
}).catch(() => {
|
||
this.officeList = []
|
||
this.total = 0
|
||
this.loading = false
|
||
})
|
||
},
|
||
/** 查询按钮 */
|
||
handleQuery() {
|
||
this.queryParams.pageNum = 1
|
||
this.getList()
|
||
},
|
||
/** 重置按钮 */
|
||
resetQuery() {
|
||
this.resetForm("queryForm")
|
||
this.handleQuery()
|
||
},
|
||
/** 新增按钮 */
|
||
handleAdd() {
|
||
this.reset()
|
||
this.isAdd = true
|
||
this.open = true
|
||
this.title = "新增教研室"
|
||
},
|
||
/** 编辑按钮 */
|
||
handleUpdate(row) {
|
||
this.reset()
|
||
this.isAdd = false
|
||
// 编辑:jysdh 必传
|
||
this.form = {
|
||
jysdh: row.jysdh,
|
||
jysmc: row.jysmc,
|
||
jc: row.jc,
|
||
bx: row.bx,
|
||
xh: row.xh,
|
||
bz: row.bz
|
||
}
|
||
this.open = true
|
||
this.title = "编辑教研室"
|
||
},
|
||
/** 停用按钮 */
|
||
handleDisable(row) {
|
||
const jysdh = row.jysdh
|
||
this.$modal.confirm('确认停用教研室【' + row.jysmc + '】吗?').then(() => {
|
||
return disableOffice(jysdh)
|
||
}).then(() => {
|
||
this.getList()
|
||
this.$modal.msgSuccess("停用成功")
|
||
}).catch(() => {})
|
||
},
|
||
/** 提交表单 */
|
||
submitForm() {
|
||
this.$refs["form"].validate(valid => {
|
||
if (valid) {
|
||
if (this.isAdd) {
|
||
addOffice(this.form).then(response => {
|
||
this.$modal.msgSuccess("新增成功")
|
||
this.open = false
|
||
this.getList()
|
||
}).catch(() => {})
|
||
} else {
|
||
updateOffice(this.form).then(response => {
|
||
this.$modal.msgSuccess("修改成功")
|
||
this.open = false
|
||
this.getList()
|
||
}).catch(() => {})
|
||
}
|
||
}
|
||
})
|
||
},
|
||
/** 重置表单 */
|
||
reset() {
|
||
this.form = {
|
||
jysdh: undefined,
|
||
jysmc: undefined,
|
||
jc: undefined,
|
||
bx: undefined,
|
||
xh: undefined,
|
||
bz: undefined
|
||
}
|
||
this.resetForm("form")
|
||
},
|
||
/** 取消按钮 */
|
||
cancel() {
|
||
this.open = false
|
||
this.reset()
|
||
},
|
||
/** 打开导入对话框 */
|
||
openImport() {
|
||
this.importOpen = true
|
||
this.$nextTick(() => {
|
||
if (this.$refs.uploadRef) {
|
||
this.$refs.uploadRef.clearFiles()
|
||
}
|
||
})
|
||
},
|
||
/** 导入前校验文件格式 */
|
||
beforeImport(file) {
|
||
const name = file.name.toLowerCase()
|
||
if (!name.endsWith('.xls') && !name.endsWith('.xlsx')) {
|
||
this.$modal.msgError('仅支持 xls、xlsx 格式文件')
|
||
return false
|
||
}
|
||
return true
|
||
},
|
||
/** 提交导入 */
|
||
submitImport() {
|
||
const files = this.$refs.uploadRef.uploadFiles
|
||
if (!files || files.length === 0) {
|
||
this.$modal.msgError('请选择要导入的文件')
|
||
return
|
||
}
|
||
this.$refs.uploadRef.submit()
|
||
},
|
||
/** 导入成功 */
|
||
handleImportSuccess(response) {
|
||
this.importOpen = false
|
||
this.$alert("<div style='overflow:auto;overflow-x:hidden;max-height:70vh;padding:10px 20px 0;'>" + response.msg + '</div>', '导入结果', { dangerouslyUseHTMLString: true })
|
||
this.getList()
|
||
},
|
||
/** 导入失败 */
|
||
handleImportError() {
|
||
this.$modal.msgError('导入失败,请稍后重试')
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.teach-office {
|
||
.mb8 {
|
||
margin-bottom: 8px;
|
||
}
|
||
}
|
||
</style>
|