You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
734 lines
19 KiB
734 lines
19 KiB
<template>
|
|
<div>
|
|
<el-card shadow="never" style="margin-top: 20px">
|
|
<template #header>
|
|
<slot name="header">
|
|
<vxe-toolbar :print="isHasAuth('print')" custom ref="toolbar">
|
|
<template #toolSuffix>
|
|
<vxe-button
|
|
style="margin-right: 10px"
|
|
v-if="isHasAuth('export')"
|
|
icon="vxe-icon-download"
|
|
circle
|
|
@click="exportMethod"
|
|
></vxe-button>
|
|
</template>
|
|
<template #buttons>
|
|
<el-button
|
|
v-if="isHasAuth('create')"
|
|
icon="el-icon-plus"
|
|
type="primary"
|
|
size="small"
|
|
@click="isShowAdd = true"
|
|
>新增</el-button
|
|
>
|
|
<template v-if="isHasAuth('search')">
|
|
<el-cascader
|
|
v-model="select['filter[0][value]']"
|
|
placeholder="归属表.."
|
|
size="small"
|
|
clearable
|
|
:options="groupAspiration"
|
|
:props="{
|
|
emitPath: false,
|
|
lazy: true,
|
|
lazyLoad: (node, resolve) => {
|
|
const { level, value } = node;
|
|
if (level === 1) {
|
|
resolve(groupAspiration.find(i => i.value === value).children)
|
|
}
|
|
else if (level === 2) {
|
|
getBatches(value.split('-')[1]).then((res) => {
|
|
resolve(
|
|
res.map((i) => ({
|
|
...i,
|
|
value: i.id,
|
|
label: i.name,
|
|
leaf: true,
|
|
}))
|
|
);
|
|
});
|
|
}
|
|
},
|
|
}"
|
|
></el-cascader>
|
|
<el-button
|
|
icon="el-icon-search"
|
|
type="primary"
|
|
plain
|
|
size="small"
|
|
@click="getList(true)"
|
|
>搜索</el-button
|
|
>
|
|
</template>
|
|
</template>
|
|
</vxe-toolbar>
|
|
</slot>
|
|
</template>
|
|
|
|
<vxe-table
|
|
ref="table"
|
|
stripe
|
|
style="margin-top: 10px"
|
|
:loading="loading"
|
|
:height="tableHeight"
|
|
keep-source
|
|
show-overflow
|
|
:menu-config="{
|
|
className: 'my-menus',
|
|
body: {
|
|
options: [
|
|
[
|
|
{
|
|
code: 'copy',
|
|
name: '复制',
|
|
prefixConfig: { icon: 'vxe-icon-copy' },
|
|
suffixConfig: { content: 'Ctrl+C' },
|
|
},
|
|
{
|
|
code: 'remove',
|
|
name: '删除',
|
|
prefixConfig: {
|
|
icon: 'vxe-icon-delete-fill',
|
|
className: 'color-red',
|
|
},
|
|
},
|
|
],
|
|
],
|
|
},
|
|
}"
|
|
@menu-click="contextMenuClickEvent"
|
|
:row-config="{ isCurrent: true, isHover: true }"
|
|
:column-config="{ resizable: true }"
|
|
:export-config="{}"
|
|
:edit-rules="validRules"
|
|
:edit-config="{
|
|
trigger: 'manual',
|
|
mode: 'row',
|
|
showStatus: true,
|
|
isHover: true,
|
|
autoClear: false,
|
|
}"
|
|
:align="allAlign"
|
|
:data="tableData"
|
|
>
|
|
<vxe-column type="checkbox" width="50" align="center" />
|
|
<vxe-column type="seq" width="58" align="center" />
|
|
|
|
<vxe-column title="归属表" min-width="160" header-align="center">
|
|
<template #default="{ row }">
|
|
<span
|
|
>{{
|
|
row.batch
|
|
? row.batch.aspiration
|
|
? row.batch.aspiration.name
|
|
: "/"
|
|
: "/"
|
|
}}
|
|
- {{ row.batch ? row.batch.name : "/" }}</span
|
|
>
|
|
</template>
|
|
</vxe-column>
|
|
<vxe-column
|
|
header-align="center"
|
|
field="name"
|
|
width="160"
|
|
title="名称"
|
|
:edit-render="{ name: 'input', attrs: { type: 'text' } }"
|
|
/>
|
|
|
|
<vxe-column
|
|
align="center"
|
|
field="batch.name"
|
|
width="180"
|
|
title="归属批次"
|
|
:edit-render="{}"
|
|
>
|
|
<template #edit="{ row }">
|
|
<el-cascader
|
|
v-model="row['batch_id']"
|
|
size="small"
|
|
style="width: 100%"
|
|
:options="aspiration"
|
|
:props="{
|
|
value: 'id',
|
|
label: 'name',
|
|
lazy: true,
|
|
emitPath: false,
|
|
lazyLoad: (node, resolve) => {
|
|
const { level, value } = node;
|
|
getBatches(value).then((res) => {
|
|
resolve(
|
|
res.map((i) => ({
|
|
...i,
|
|
leaf: true,
|
|
}))
|
|
);
|
|
});
|
|
},
|
|
}"
|
|
></el-cascader>
|
|
</template>
|
|
</vxe-column>
|
|
|
|
<vxe-column
|
|
align="center"
|
|
field="school"
|
|
width="240"
|
|
title="绑定学校"
|
|
:edit-render="{}"
|
|
>
|
|
<template #default="{ row }">
|
|
{{ row.school_details ? row.school_details.map((i) => i.name) : "" }}
|
|
</template>
|
|
<template #edit="{ row }">
|
|
<el-input
|
|
:value="
|
|
row.school_details ? row.school_details.map((i) => i.name).toString() : ''
|
|
"
|
|
size="small"
|
|
placeholder="点击选择学校"
|
|
@focus="
|
|
(selectedRow = row),
|
|
$refs['SchoolPicker'].setDefaultValue(row.school_details || []),
|
|
(isShowSchoolPicker = true)
|
|
"
|
|
></el-input>
|
|
</template>
|
|
</vxe-column>
|
|
|
|
<vxe-column
|
|
header-align="center"
|
|
align="right"
|
|
field="sort"
|
|
width="160"
|
|
title="排序"
|
|
:edit-render="{ name: 'input', attrs: { type: 'number' } }"
|
|
/>
|
|
|
|
<vxe-column
|
|
align="center"
|
|
field="show_school_obey"
|
|
width="180"
|
|
title="是否显示学校服从"
|
|
:edit-render="{
|
|
name: 'VxeSelect',
|
|
options: [
|
|
{ value: 1, label: '是' },
|
|
{ value: 0, label: '否' },
|
|
],
|
|
props: { multiple: false },
|
|
optionProps: { value: 'value', label: 'label' },
|
|
}"
|
|
/>
|
|
|
|
<vxe-column
|
|
align="center"
|
|
field="show_specialty_obey"
|
|
width="180"
|
|
title="是否显示专业服从"
|
|
:edit-render="{
|
|
name: 'VxeSelect',
|
|
options: [
|
|
{ value: 1, label: '是' },
|
|
{ value: 0, label: '否' },
|
|
],
|
|
props: { multiple: false },
|
|
optionProps: { value: 'value', label: 'label' },
|
|
}"
|
|
/>
|
|
|
|
<vxe-column
|
|
field="operate"
|
|
header-align="center"
|
|
title="操作"
|
|
min-width="220"
|
|
fixed="right"
|
|
>
|
|
<template #default="{ row }">
|
|
<template v-if="isActiveStatus(row)">
|
|
<el-button size="small" type="primary" @click="saveRowEvent(row)"
|
|
>保存</el-button
|
|
>
|
|
<el-button
|
|
size="small"
|
|
type="primary"
|
|
plain
|
|
@click="cancelRowEvent(row)"
|
|
>取消</el-button
|
|
>
|
|
</template>
|
|
<template v-else>
|
|
<el-button
|
|
v-if="isHasAuth('detail')"
|
|
size="small"
|
|
type="primary"
|
|
plain
|
|
@click="detail(row)"
|
|
>查看</el-button
|
|
>
|
|
<el-button
|
|
v-if="isHasAuth('edit')"
|
|
size="small"
|
|
type="warning"
|
|
@click="editRowEvent(row)"
|
|
>编辑</el-button
|
|
>
|
|
<el-button
|
|
v-if="isHasAuth('delete')"
|
|
size="small"
|
|
type="danger"
|
|
@click="destroyRowEvent(row)"
|
|
>删除</el-button
|
|
>
|
|
</template>
|
|
</template>
|
|
</vxe-column>
|
|
</vxe-table>
|
|
|
|
<el-pagination
|
|
style="margin-top: 10px; display: flex; justify-content: flex-end"
|
|
:current-page.sync="select.page"
|
|
:page-sizes="[20, 30, 40, 50]"
|
|
:page-size.sync="select.page_size"
|
|
layout="total, sizes, prev, pager, next, jumper"
|
|
:total="total"
|
|
@size-change="
|
|
(e) => {
|
|
select.page_size = e;
|
|
select.page = 1;
|
|
getList();
|
|
}
|
|
"
|
|
@current-change="
|
|
(e) => {
|
|
select.page = e;
|
|
getList();
|
|
}
|
|
"
|
|
/>
|
|
</el-card>
|
|
|
|
<AddBatchSub
|
|
ref="AddBatchSub"
|
|
:is-show.sync="isShowAdd"
|
|
@refresh="getList"
|
|
/>
|
|
<ShowBatchSub
|
|
ref="ShowBatchSub"
|
|
:is-show.sync="isShowDetail"
|
|
/>
|
|
<SchoolPicker
|
|
ref="SchoolPicker"
|
|
:is-show.sync="isShowSchoolPicker"
|
|
@confirm="(e) => (selectedRow.school_details = e)"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import VxeUI from "vxe-pc-ui";
|
|
|
|
import { authMixin } from "@/mixin/authMixin";
|
|
import { uploadSize } from "@/settings";
|
|
import {deepCopy, paramsSerializer} from "@/utils";
|
|
import { download } from "@/utils/downloadRequest";
|
|
import { destroy, index, save } from "@/api/batch-sub/batch-sub";
|
|
import AddBatchSub from "./components/AddBatchSub.vue";
|
|
import ShowBatchSub from "./components/ShowBatchSub.vue";
|
|
import SchoolPicker from "./components/SchoolPicker.vue";
|
|
import axios from "axios";
|
|
import { getToken } from "@/utils/auth";
|
|
|
|
import { index as batchIndex } from "@/api/batch/batch";
|
|
import { index as schoolIndex } from "@/api/school/school";
|
|
import { index as aspirationIndex } from "@/api/aspiration/aspiration";
|
|
|
|
export default {
|
|
name: "BatchSub",
|
|
mixins: [authMixin],
|
|
components: {
|
|
AddBatchSub,
|
|
ShowBatchSub,
|
|
SchoolPicker,
|
|
},
|
|
data() {
|
|
return {
|
|
uploadSize,
|
|
examineKey: 0,
|
|
isShowAdd: false,
|
|
isShowDetail: false,
|
|
isShowSchoolPicker: false,
|
|
selectedRow: {},
|
|
|
|
loading: false,
|
|
tableHeight: 400,
|
|
select: {
|
|
page: 1,
|
|
page_size: 20,
|
|
keyword: "",
|
|
show_relation: ["batch.aspiration"],
|
|
"filter[0][key]": 'batch_id',
|
|
"filter[0][op]": 'eq',
|
|
"filter[0][value]": ''
|
|
},
|
|
total: 0,
|
|
allAlign: null,
|
|
tableData: [],
|
|
form: {
|
|
id: "",
|
|
name: "",
|
|
batch_id: "",
|
|
sort: "",
|
|
show_school_obey: "",
|
|
show_specialty_obey: "",
|
|
school: [],
|
|
},
|
|
validRules: {
|
|
name: [
|
|
{
|
|
required: true,
|
|
message: "名称" + "必填",
|
|
},
|
|
],
|
|
|
|
batch_id: [
|
|
{
|
|
required: true,
|
|
message: "归属批次" + "必填",
|
|
},
|
|
],
|
|
},
|
|
|
|
// batch: [],
|
|
aspiration: [],
|
|
// school: [],
|
|
};
|
|
},
|
|
computed: {
|
|
groupAspiration() {
|
|
const yearMap = {};
|
|
|
|
// 遍历数据,按年份分组
|
|
this.aspiration.forEach((item) => {
|
|
if (!yearMap[item.year]) {
|
|
yearMap[item.year] = {
|
|
value: `0-${item.year}`,
|
|
label: `${item.year}年`,
|
|
children: [],
|
|
};
|
|
}
|
|
yearMap[item.year].children.push({
|
|
value: `1-${item.id}`,
|
|
label: item.name,
|
|
leaf: false,
|
|
children: [],
|
|
// 可以根据需要添加其他字段
|
|
});
|
|
});
|
|
|
|
// 转换为数组格式
|
|
return Object.values(yearMap);
|
|
},
|
|
isActiveStatus() {
|
|
return function (row) {
|
|
if (this.$refs["table"]) {
|
|
return this.$refs["table"].isEditByRow(row);
|
|
}
|
|
};
|
|
},
|
|
isHasAuth() {
|
|
return function (auth) {
|
|
return this.auths_auth_mixin.indexOf(auth) !== -1;
|
|
};
|
|
},
|
|
},
|
|
created() {
|
|
this.getAspiration();
|
|
// this.getBatch();
|
|
// this.getSchool();
|
|
|
|
this.getList();
|
|
},
|
|
mounted() {
|
|
this.bindToolbar();
|
|
this.calcTableHeight();
|
|
},
|
|
methods: {
|
|
exportMethod() {
|
|
this.$confirm("请选择导出方式", "提示", {
|
|
confirmButtonText: "全量导出",
|
|
cancelButtonText: "部分导出",
|
|
distinguishCancelAndClose: true,
|
|
})
|
|
.then((_) => {
|
|
const tableColumns = this.$refs['table'].getFullColumns()
|
|
let export_fields = {}
|
|
Object.keys(this.form).forEach(key => {
|
|
export_fields[key] = tableColumns.find(col => col.field === key)?.title || key
|
|
})
|
|
download("/api/admin/school/index", "get", {
|
|
...this.select,
|
|
page: 1,
|
|
page_size: 9999,
|
|
is_export: 1,
|
|
export_fields
|
|
}, `${this.$route.meta.title}_${this.$moment().valueOf()}.xlsx`,paramsSerializer);
|
|
})
|
|
.catch((action) => {
|
|
if (action === "cancel" && this.$refs["table"]) {
|
|
this.$refs["table"].openExport();
|
|
}
|
|
});
|
|
},
|
|
calcTableHeight() {
|
|
let clientHeight = document.documentElement.clientHeight;
|
|
let cardTitle = document
|
|
.querySelector(".el-card__header")
|
|
?.getBoundingClientRect()?.height;
|
|
let search = document
|
|
.querySelector(".vxe-toolbar")
|
|
?.getBoundingClientRect()?.height;
|
|
let paginationHeight =
|
|
(document.querySelector(".el-pagination")?.getBoundingClientRect()
|
|
?.height ?? 0) + 10; //分页的高度
|
|
let topHeight = 50; //页面 头部
|
|
let padding = 80;
|
|
let margin = 20;
|
|
this.tableHeight =
|
|
clientHeight -
|
|
cardTitle -
|
|
search -
|
|
paginationHeight -
|
|
topHeight -
|
|
padding -
|
|
margin;
|
|
},
|
|
contextMenuClickEvent({ menu, row, column }) {
|
|
switch (menu.code) {
|
|
case "copy":
|
|
// 示例
|
|
if (row && column) {
|
|
if (VxeUI.clipboard.copy(row[column.field])) {
|
|
this.$message.success("已复制到剪贴板!");
|
|
}
|
|
}
|
|
break;
|
|
case "remove":
|
|
if (row && column) {
|
|
this.destroyRowEvent(row);
|
|
}
|
|
default:
|
|
}
|
|
},
|
|
async getBatches(aspirationId) {
|
|
try {
|
|
const res = await batchIndex({
|
|
page: 1,
|
|
page_size: 999,
|
|
"filter[0][key]": "aspiration_id",
|
|
"filter[0][op]": "eq",
|
|
"filter[0][value]": aspirationId,
|
|
});
|
|
return res.data;
|
|
} catch (err) {
|
|
console.error(err);
|
|
return [];
|
|
}
|
|
},
|
|
async detail(row) {
|
|
await this.$refs["ShowBatchSub"].getDetail(row.id);
|
|
this.isShowDetail = true;
|
|
},
|
|
|
|
// async getSchool() {
|
|
// try {
|
|
// const res = await schoolIndex(
|
|
// {
|
|
// page: 1,
|
|
// page_size: 999,
|
|
// },
|
|
// false
|
|
// );
|
|
// this.school = res.data;
|
|
// } catch (err) {
|
|
// console.error(err);
|
|
// }
|
|
// },
|
|
async getAspiration() {
|
|
try {
|
|
const res = await aspirationIndex(
|
|
{
|
|
page: 1,
|
|
page_size: 999,
|
|
},
|
|
false
|
|
);
|
|
this.aspiration = res.data;
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
},
|
|
|
|
async getBatch() {
|
|
try {
|
|
const res = await batchIndex(
|
|
{
|
|
page: 1,
|
|
page_size: 999,
|
|
},
|
|
false
|
|
);
|
|
this.batch = res.data;
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
},
|
|
|
|
uploadMethod(file) {
|
|
const formData = new FormData();
|
|
formData.append("file", file);
|
|
window.$_uploading = true;
|
|
return axios
|
|
.post(process.env.VUE_APP_UPLOAD_API, formData, {
|
|
headers: {
|
|
Authorization: `Bearer ${getToken()}`,
|
|
},
|
|
})
|
|
.then((response) => {
|
|
window.$_uploading = false;
|
|
if (response.status === 200 && !response.data.code) {
|
|
return {
|
|
response: response.data,
|
|
name: response.data.original_name,
|
|
url: response.data.url,
|
|
};
|
|
} else {
|
|
this.$message.error("上传失败");
|
|
}
|
|
})
|
|
.catch((_) => {
|
|
window.$_uploading = false;
|
|
});
|
|
},
|
|
bindToolbar() {
|
|
this.$nextTick(() => {
|
|
if (this.$refs["table"] && this.$refs["toolbar"]) {
|
|
this.$refs["table"].connect(this.$refs["toolbar"]);
|
|
}
|
|
});
|
|
},
|
|
|
|
editRowEvent(row) {
|
|
if (this.$refs["table"]) {
|
|
this.$refs["table"].setEditRow(row);
|
|
}
|
|
},
|
|
cancelRowEvent(row) {
|
|
if (this.$refs["table"]) {
|
|
this.$refs["table"].clearEdit().then(() => {
|
|
// 还原行数据
|
|
this.$refs["table"].revertData(row);
|
|
});
|
|
}
|
|
},
|
|
|
|
async getList(isRefresh) {
|
|
if (isRefresh) {
|
|
this.select.page = 1;
|
|
}
|
|
this.loading = true;
|
|
try {
|
|
const res = await index(this.select, false);
|
|
this.tableData = res.data;
|
|
this.total = res.total;
|
|
this.loading = false;
|
|
} catch (err) {
|
|
console.error(err);
|
|
this.loading = false;
|
|
}
|
|
},
|
|
|
|
async saveRowEvent(row) {
|
|
if (window.$_uploading) {
|
|
this.$message.warning("文件正在上传中");
|
|
return;
|
|
}
|
|
try {
|
|
const errMap = await this.$refs["table"].validate();
|
|
if (errMap) {
|
|
throw new Error(errMap);
|
|
}
|
|
await this.$confirm("确认保存?", "提示", {
|
|
confirmButtonText: "确认",
|
|
cancelButtonText: "取消",
|
|
});
|
|
await this.$refs["table"].clearEdit();
|
|
let form = deepCopy(this.form);
|
|
for (const key in form) {
|
|
form[key] = row[key];
|
|
}
|
|
|
|
let arr = []
|
|
if(this.selectedRow.school_details && this.selectedRow.school_details.length>0){
|
|
this.selectedRow.school_details.map(item=>{
|
|
arr.push(item.id)
|
|
})
|
|
form.school = arr
|
|
}
|
|
|
|
console.log("form",form)
|
|
// return
|
|
this.loading = true;
|
|
|
|
await save(form, false);
|
|
await this.getList();
|
|
this.loading = false;
|
|
} catch (err) {
|
|
this.loading = false;
|
|
console.log("err",err)
|
|
}
|
|
},
|
|
async destroyRowEvent(row) {
|
|
try {
|
|
await this.$confirm("确认删除?", "提示", {
|
|
confirmButtonText: "确认",
|
|
cancelButtonText: "取消",
|
|
});
|
|
this.loading = true;
|
|
if (row.id) {
|
|
await destroy(
|
|
{
|
|
id: row.id,
|
|
},
|
|
false
|
|
);
|
|
await this.getList();
|
|
} else {
|
|
console.log(row);
|
|
this.tableData.splice(
|
|
this.tableData.findIndex((i) => i._X_ROW_KEY === row._X_ROW_KEY),
|
|
1
|
|
);
|
|
}
|
|
this.loading = false;
|
|
} catch (err) {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
::v-deep .vxe-buttons--wrapper > * + * {
|
|
margin-left: 10px;
|
|
}
|
|
::v-deep .el-card__header {
|
|
padding: 6px 20px;
|
|
}
|
|
::v-deep .el-tag + .el-tag {
|
|
margin-left: 4px;
|
|
}
|
|
</style>
|