|
@@ -1,44 +1,37 @@
|
|
|
<template>
|
|
|
- <div id="index">
|
|
|
- <list-frame :title="mainTitle" @query="search" :total="total" :needFilter="false" @add="$router.push({ path: '/duty/detail' })">
|
|
|
- <data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" @delete="toDelete"></data-table>
|
|
|
- </list-frame>
|
|
|
+ <div id="detail">
|
|
|
+ <detail-frame :title="mainTitle" returns="/dept/index" v-loading="loading">
|
|
|
+ <data-form v-if="!loading" :data="info" :fields="fields" :rules="rules" @save="handleSave" :isNew="isNew"> </data-form>
|
|
|
+ </detail-frame>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import listFrame from '@frame/layout/admin/list-frame';
|
|
|
-import dataTable from '@frame/components/data-table';
|
|
|
-import { createNamespacedHelpers } from 'vuex';
|
|
|
-const { mapActions } = createNamespacedHelpers('duty');
|
|
|
+import detailFrame from '@frame/layout/admin/detail-frame';
|
|
|
+import dataForm from '@frame/components/form';
|
|
|
+import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: mapDuty } = createNamespacedHelpers('duty');
|
|
|
+
|
|
|
export default {
|
|
|
- metaInfo: { title: '职责管理' },
|
|
|
- name: 'index',
|
|
|
+ metaInfo: { title: '职责详情' },
|
|
|
+ name: 'detail',
|
|
|
props: {},
|
|
|
components: {
|
|
|
- listFrame,
|
|
|
- dataTable,
|
|
|
+ detailFrame,
|
|
|
+ dataForm,
|
|
|
},
|
|
|
data: () => ({
|
|
|
- opera: [
|
|
|
- {
|
|
|
- label: '编辑',
|
|
|
- icon: 'el-icon-edit',
|
|
|
- method: 'edit',
|
|
|
- },
|
|
|
- {
|
|
|
- label: '删除',
|
|
|
- icon: 'el-icon-delete',
|
|
|
- method: 'delete',
|
|
|
- confirm: true,
|
|
|
- },
|
|
|
- ],
|
|
|
+ info: {},
|
|
|
fields: [
|
|
|
- { label: '班长职责', prop: 'bzduty' },
|
|
|
- { label: '学委职责', prop: 'xwduty' },
|
|
|
+ { label: '班长职责', required: true, model: 'bzduty', type: 'editor' },
|
|
|
+ { label: '学委职责', required: true, model: 'xwduty', type: 'editor' },
|
|
|
],
|
|
|
- list: [],
|
|
|
- total: 0,
|
|
|
+ rules: {
|
|
|
+ bzduty: [{ required: true, message: '请输入班长职责' }],
|
|
|
+ xwduty: [{ required: true, message: '请输入学委职责' }],
|
|
|
+ },
|
|
|
+ loading: true,
|
|
|
+ isNew: true,
|
|
|
}),
|
|
|
created() {
|
|
|
this.search();
|
|
@@ -57,23 +50,29 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
|
- ...mapActions(['query', 'delete']),
|
|
|
- async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
|
- const res = await this.query({ skip, limit, ...info });
|
|
|
+ ...mapDuty(['query', 'create', 'update']),
|
|
|
+ async search() {
|
|
|
+ const res = await this.query({ skip: 0, limit: 1 });
|
|
|
if (this.$checkRes(res)) {
|
|
|
- this.$set(this, `list`, res.data);
|
|
|
- this.$set(this, `total`, res.total);
|
|
|
+ if (res.data.length > 0) {
|
|
|
+ this.isNew = false;
|
|
|
+ let data = res.data[0];
|
|
|
+ this.$set(this, `info`, data);
|
|
|
+ }
|
|
|
}
|
|
|
+ this.loading = false;
|
|
|
},
|
|
|
-
|
|
|
- toEdit({ data }) {
|
|
|
- this.$router.push({ path: '/duty/detail', query: { id: data.id } });
|
|
|
- },
|
|
|
-
|
|
|
- async toDelete({ data }) {
|
|
|
- const res = await this.delete(data.id);
|
|
|
- this.$checkRes(res, '删除成功', '删除失败');
|
|
|
- this.search();
|
|
|
+ async handleSave({ isNew, data }) {
|
|
|
+ let res;
|
|
|
+ let msg;
|
|
|
+ if (isNew) {
|
|
|
+ res = await this.create(data);
|
|
|
+ msg = `${this.keyWord}添加成功`;
|
|
|
+ } else {
|
|
|
+ res = await this.update(data);
|
|
|
+ msg = `${this.keyWord}修改成功`;
|
|
|
+ }
|
|
|
+ this.$checkRes(res, msg);
|
|
|
},
|
|
|
},
|
|
|
};
|