|
@@ -1,19 +1,33 @@
|
|
|
<template>
|
|
|
<div id="index">
|
|
|
- <list-frame :title="pageTitle" @query="search" :total="total" :needFilter="false" @add="dialog = true">
|
|
|
+ <list-frame :title="pageTitle" @query="search" :total="total" :needFilter="false" @add="toAdd">
|
|
|
<data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" @delete="toDelete"></data-table>
|
|
|
</list-frame>
|
|
|
<el-dialog title="年度信息" width="30%" :visible.sync="dialog" center :destroy-on-close="true" @close="handleClose">
|
|
|
- <data-form :data="info" :fields="Ffields" :rules="rules" @save="handleSave" :isNew="!info.id" :styles="{ padding: 0 }"> </data-form>
|
|
|
+ <data-form :data="info" :fields="Ffields" :rules="rules" @save="handleSave" :isNew="!info.id" :styles="{ padding: 0 }" labelWidth="60px">
|
|
|
+ <template #custom="{item,form}">
|
|
|
+ <template v-if="item.model == 'festivals'">
|
|
|
+ <data-table :fields="festFields" :data="form[item.model]" :opera="opera" @edit="toFestEdit" @delete="toFestDelete"></data-table>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </data-form>
|
|
|
</el-dialog>
|
|
|
+ <el-drawer :title="form.name" :visible.sync="drawer" direction="rtl" @close="handleFestClose">
|
|
|
+ <data-form :data="form" :fields="festFields" :rules="{}" @save="handleFestSave" :isNew="!info.id" :styles="{ padding: 0 }"> </data-form>
|
|
|
+ </el-drawer>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+var moment = require('moment');
|
|
|
+import _ from 'lodash';
|
|
|
+import Vue from 'vue';
|
|
|
import listFrame from '@frame/layout/admin/list-frame';
|
|
|
import dataTable from '@frame/components/data-table';
|
|
|
import dataForm from '@frame/components/form';
|
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: trainplan } = createNamespacedHelpers('trainplan');
|
|
|
+const { mapActions: other } = createNamespacedHelpers('other');
|
|
|
export default {
|
|
|
name: 'index',
|
|
|
props: {},
|
|
@@ -21,6 +35,7 @@ export default {
|
|
|
data: () => {
|
|
|
return {
|
|
|
dialog: false,
|
|
|
+ drawer: false,
|
|
|
opera: [
|
|
|
{
|
|
|
label: '编辑',
|
|
@@ -35,17 +50,34 @@ export default {
|
|
|
],
|
|
|
fields: [
|
|
|
{ label: '年度', prop: 'year' },
|
|
|
- { label: '状态', prop: 'status', format: i => (i === '0' ? '已使用' : '已禁用') },
|
|
|
+ { label: '标题', prop: 'title' },
|
|
|
+ { label: '状态', prop: 'status', format: i => (i === '0' ? '筹备中' : i === '1' ? '已发布' : '已结束') },
|
|
|
+ ],
|
|
|
+ festFields: [
|
|
|
+ { label: '节假日', prop: 'name', model: 'name', options: { readonly: true } },
|
|
|
+ { label: '开始时间', prop: 'begindate', model: 'begindate', type: 'date' },
|
|
|
+ { label: '结束时间', prop: 'finishdate', model: 'finishdate', type: 'date' },
|
|
|
],
|
|
|
info: {},
|
|
|
- Ffields: [{ label: '年度', model: 'year' }],
|
|
|
+ form: {},
|
|
|
+ Ffields: [
|
|
|
+ { label: '年度', model: 'year' },
|
|
|
+ { label: '标题', model: 'title' },
|
|
|
+ { label: '假期', model: 'festivals', custom: true },
|
|
|
+ ],
|
|
|
rules: {},
|
|
|
list: [],
|
|
|
+ holiday: [],
|
|
|
total: 0,
|
|
|
};
|
|
|
},
|
|
|
- created() {},
|
|
|
+ created() {
|
|
|
+ this.getOtherList();
|
|
|
+ this.search();
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ ...other(['calendar']),
|
|
|
+ ...trainplan(['query', 'create', 'delete', 'update']),
|
|
|
async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
|
const res = await this.query({ skip, limit, ...info });
|
|
|
if (this.$checkRes(res)) {
|
|
@@ -53,6 +85,10 @@ export default {
|
|
|
this.$set(this, `total`, res.total);
|
|
|
}
|
|
|
},
|
|
|
+ toAdd() {
|
|
|
+ this.$set(this.info, `festivals`, JSON.parse(JSON.stringify(this.holiday)));
|
|
|
+ this.dialog = true;
|
|
|
+ },
|
|
|
toEdit({ data }) {
|
|
|
this.$set(this, `info`, data);
|
|
|
this.dialog = true;
|
|
@@ -63,17 +99,62 @@ export default {
|
|
|
this.search();
|
|
|
},
|
|
|
async handleSave({ data, isNew }) {
|
|
|
- console.log(data, isNew);
|
|
|
+ let res;
|
|
|
+ let msg;
|
|
|
if (isNew) {
|
|
|
//create
|
|
|
+ res = await this.create(data);
|
|
|
+ msg = '添加成功';
|
|
|
} else {
|
|
|
//update
|
|
|
+ res = await this.update(data);
|
|
|
+ msg = '修改成功';
|
|
|
+ }
|
|
|
+ if (this.$checkRes(res, msg, res.errmsg || '操作失败')) {
|
|
|
+ this.handleClose();
|
|
|
}
|
|
|
},
|
|
|
handleClose() {
|
|
|
this.dialog = false;
|
|
|
this.info = {};
|
|
|
},
|
|
|
+ handleFestClose() {
|
|
|
+ this.drawer = false;
|
|
|
+ this.form = {};
|
|
|
+ },
|
|
|
+ toFestEdit({ data, index }) {
|
|
|
+ let nd = JSON.parse(JSON.stringify(data));
|
|
|
+ nd.index = index;
|
|
|
+ this.$set(this, 'form', nd);
|
|
|
+ this.drawer = true;
|
|
|
+ },
|
|
|
+ toFestDelete({ data, index }) {
|
|
|
+ this.info.festivals.splice(index, 1);
|
|
|
+ },
|
|
|
+ handleFestSave({ data }) {
|
|
|
+ let index = data.index;
|
|
|
+ let obj = _.omit(data, ['index']);
|
|
|
+ this.$set(this.info.festivals, index, obj);
|
|
|
+ this.drawer = false;
|
|
|
+ },
|
|
|
+ async getOtherList() {
|
|
|
+ let holiday = sessionStorage.getItem('holiday');
|
|
|
+ if (!holiday) {
|
|
|
+ let year = new Date().getFullYear();
|
|
|
+ let key = Vue.config.jhAppKey;
|
|
|
+ let res = await this.calendar({ key, year });
|
|
|
+ if (res) {
|
|
|
+ let plan = res.holiday_list;
|
|
|
+ plan.map(i => {
|
|
|
+ i.begindate = moment(i.startday).format('YYYY-MM-DD');
|
|
|
+ delete i.startday;
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ this.$set(this, `holiday`, plan);
|
|
|
+ }
|
|
|
+ sessionStorage.setItem('holiday', JSON.stringify(res.holiday_list));
|
|
|
+ } else this.$set(this, 'holiday', JSON.parse(holiday));
|
|
|
+ },
|
|
|
},
|
|
|
computed: {
|
|
|
...mapState(['user']),
|