培训计划调整

This commit is contained in:
Yjhon 2022-03-12 10:26:53 +08:00
parent 8f4387f5cc
commit f189ea1453
4 changed files with 206 additions and 27 deletions

View File

@ -0,0 +1,13 @@
import request from '@/utils/request'
const trainPlanAPI = {
add: '/trainPlan/add',
}
export function trainPlanAdd(params) {
return request({
url: trainPlanAPI.add,
method: 'post',
data: params
})
}

View File

@ -32,7 +32,9 @@
</a-row>
</a-form>
<!-- onChange: onSelectChange, -->
<s-table ref="table" :columns="columns" :data="loadData" :rowKey="(record) => record.id" :rowSelection="{ selectedRowKeys: selectedRowKeys, selectedRows: selectedRows,onChange: onSelectChange, onSelect: tableOnSelect ,onSelectAll: tableAllSelected }">
<s-table ref="table" :columns="columns" :data="loadData" :rowKey="(record) => record.id"
:rowSelection="{ selectedRowKeys: selectedRowKeys, selectedRows: selectedRows,onChange: onSelectChange,
onSelect: tableOnSelect ,onSelectAll: tableAllSelected }">
<span slot="serial" slot-scope="text, record, index">
{{ index + 1 }}
</span>

View File

@ -1,29 +1,177 @@
<template>
<a-card :bordered="false" title="培训计划">
<a-form-model ref="form" :rules="rules" :model="form" :layout="'horizontal'">
<a-form-model-item label="培训计划名称" prop="name">
<a-input v-model="form.name" />
</a-form-model-item>
<a-form-model-item label="培训计划年度" prop="year">
<a-select v-model="form.year" placeholder="--请选择--" defaultValue=''>
<a-select-option v-for="entity in years" :key="Number(entity)"> {{ entity }}年度 </a-select-option>
</a-select>
</a-form-model-item>
<a-button type="primary" size="default" icon="plus" @click="showDrawer" style="margin-right: 8px;">选择项目</a-button>
<a-table v-if="selectedRows.length > 0" rowKey="id" :columns="columns" :data-source="selectedRows" :pagination="false"></a-table>
<a-form-model-item label="备注">
<a-input v-model="form.remark" type="textarea" />
</a-form-model-item>
<a-col :span="24" style="text-align: center;">
<a-button type="primary" size="default" @click="handleSave" style="margin-right: 8px;">保存</a-button>
<a-button type="danger" size="default" @click="showConfirm">关闭</a-button>
</a-col>
</a-form-model>
<a-drawer title="选择项目" placement="right" :width="800" :closable="false" :visible="visible" :after-visible-change="afterVisibleChange" @close="onClose">
<s-table ref="table" size="default" rowKey="id" :columns="columns" :rowSelection="{ selectedRowKeys: selectedRowKeys, selectedRows: selectedRows,onChange: onSelectChange, onSelect: tableOnSelect ,onSelectAll: tableAllSelected }" :data="loadData" :pageNum="Number(this.$route.query.projectPageNum) || 1">
</s-table>
</a-drawer>
</a-card>
</template>
<script>
// jsjsjson
// import from ''
import { STable } from '@/components'
import { getProjectList } from '@/api/project/project'
import { trainPlanAdd } from '@/api/trainplan';
export default {
// import使
components: {},
components: { STable },
props: {},
data() {
//
return {};
return {
queryParam: {
pageNum: 1,
pageSize: 20
},
total: 10,
visible: false,
years: [],
form: {
name: '',
year: Number,
projectIds: [],
status: 1, //
},
rowSelection: {},
selectedRows: [],
selectedRowKeys: [],
rules: {
name: [{ required: true, message: '请输入培训计划名称', trigger: 'blur' }],
year: [{ required: true, message: '请选择培训计划年度', trigger: 'change' }],
},
columns: [
{ title: '项目名称', dataIndex: 'projectName', key: 'projectName' },
{ title: '创建人', dataIndex: 'createBy', key: 'createBy' },
{ title: '创建时间', dataIndex: 'createDate', key: 'createDate' }
],
loadData: (parameter) => {
return getProjectList(Object.assign(parameter, this.queryParam)).then((res) => {
return res
})
},
};
},
// data
computed: {},
// data
watch: {},
//
methods: {},
methods: {
// TODO
handleSave() {
this.form.projectIds = this.selectedRowKeys;
this.$refs.form.validate(validate => {
if (validate) {
if (this.form.projectIds.length > 0) {
console.log('form', this.form)
trainPlanAdd(Object.assign({}, this.form)).then((res) => {
if (res.code == 200) {
this.$router.push({
path: '/trainPlan/list/'+this.$route.query.t,
query: {
t: this.queryParam.type, //
trainPlanPageNum: this.$route.query.trainPlanPageNum, //
},
})
} else{
this.$message.error('保存失败!')
}
})
} else {
this.$message.warning('项目不能为空,请选择项目后重新提交!')
}
}
})
},
/** 提示框 START */
showConfirm() {
this.$confirm({
title: '提示',
content: h => <span style="color:red;font-size:15px;">关闭后当前未保存的数据将丢失! 确认关闭吗?</span>,
onOk() { console.log('OK'); },
onCancel() { console.log('Cancel'); },
class: 'test',
});
},
/** 提示框 END */
/** TABLE START */
/** 表格行选中后触发 */
onSelectChange(selectedRowKeys, selectedRows) {
console.log('selectedRowKeys changed: ', selectedRowKeys)
console.log('选择的表格数据 : ', selectedRows)
this.selectedRowKeys = selectedRowKeys
this.selectedRows = selectedRows
},
/** table取消勾选 */
tableOnSelect(record, selected, selectedRows, nativeEvent) {
if (!selected) { //
let keys = this.selectedRowKeys.filter(item => item != record.id);
let rows = this.selectedRows.filter(item => item.id != record.id);
this.selectedRows = rows;
this.selectedRowKeys = keys;
}
},
/** table取消全选 */
tableAllSelected(selected, selectedRows, changeRows) {
if (!selected) { //
let exKeys = changeRows.map(value => { return value.id })
let keys = this.selectedRowKeys.filter(item => { return !exKeys.includes(item) });
let rows = this.selectedRows.filter(item => { return !exKeys.includes(item.id) });
this.selectedRows = rows;
this.selectedRowKeys = keys;
}
},
/** TABLE END */
/** 抽屉使用的方法 ---start */
afterVisibleChange(val) {
console.log('visible', val);
},
showDrawer() {
this.visible = true;
},
onClose() {
this.visible = false;
},
/** 抽屉使用的方法 ---end */
/** 初始化年度 */
initYears() {
for (let i = 0; i < 5; i++) {
this.years.push(new Date().getFullYear() - 2 + i);
}
}
},
// - 访this
created() { },
created() { this.initYears() },
// - 访DOM
mounted() { },
// -

View File

@ -47,7 +47,7 @@ export default {
data() {
//
return {
title: '',
title: '培训计划列表',
queryParam: {
name: '',
year: '',
@ -94,12 +94,25 @@ export default {
// data
watch: {
$route(to, from) { //to from
console.log("监控到变化")
this.changeType(to.path)
this.$refs.table.refresh(true)
},
},
//
methods: {
//
handledCreate(record) {
console.log(this.queryParam)
this.$router.push({
path: '/project/trainPlan/TrainPlanForm',
query: {
t: this.queryParam.type, //
trainPlanId: record.id, //id
trainPlanPageNum: this.$refs.table.localPagination.current, //
},
})
},
//
changeType(path) {
console.log('变更路由:', path)
@ -113,8 +126,11 @@ export default {
this.queryParam.type = str
str == 'year' ? this.title = '年度培训计划列表' : this.title = '单位培训计划列表'
},
},
// - 访this
created() { this.changeType(this.$route.path) },
created() {
this.changeType(this.$route.path)
},
// - 访DOM
mounted() { },
// -
@ -132,7 +148,7 @@ export default {
// keep-alive
activated() { }
}
}
</script>
<style scoped>
</style>