|
@@ -9,6 +9,9 @@
|
|
|
<script>
|
|
|
import detailFrame from '@frame/layout/admin/detail-frame';
|
|
|
import dataForm from '@frame/components/form';
|
|
|
+import { mapActions, mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: mapClass } = createNamespacedHelpers('dept');
|
|
|
+
|
|
|
export default {
|
|
|
metaInfo: { title: '部门信息' },
|
|
|
name: 'detail',
|
|
@@ -26,14 +29,41 @@ export default {
|
|
|
}),
|
|
|
created() {},
|
|
|
computed: {
|
|
|
+ id() {
|
|
|
+ return this.$route.query.id;
|
|
|
+ },
|
|
|
isNew() {
|
|
|
return this.$route.query.id ? false : true;
|
|
|
},
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ isNew: {
|
|
|
+ immediate: true,
|
|
|
+ handler(val) {
|
|
|
+ if (val) this.loading = false;
|
|
|
+ else this.search();
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ ...mapClass(['fetch', 'create', 'update']),
|
|
|
+ async search() {
|
|
|
+ const res = await this.fetch(this.id);
|
|
|
+ console.log(res);
|
|
|
+ if (this.$checkRes(res)) this.$set(this, `info`, res.data);
|
|
|
+ this.loading = false;
|
|
|
+ },
|
|
|
async handleSave({ isNew, data }) {
|
|
|
- console.log(isNew);
|
|
|
- console.log(data);
|
|
|
+ let res;
|
|
|
+ let msg;
|
|
|
+ if (isNew) {
|
|
|
+ res = this.create(data);
|
|
|
+ msg = '班级添加成功';
|
|
|
+ } else {
|
|
|
+ res = this.update(data);
|
|
|
+ msg = '班级修改成功';
|
|
|
+ }
|
|
|
+ if (this.$checkRes(res, msg)) this.$router.push({ path: '/classes/index' });
|
|
|
},
|
|
|
},
|
|
|
};
|