|
@@ -0,0 +1,145 @@
|
|
|
+<template>
|
|
|
+ <div id="afterClassDetail">
|
|
|
+ <detail-frame :title="mainTitle" returns="/teaching/afterClass">
|
|
|
+ <data-form :data="info" :fields="fields" :rules="rules" @save="handleSave" :isNew="isNew">
|
|
|
+ <template #options="{item}">
|
|
|
+ <template v-if="item.model === 'subid'">
|
|
|
+ <el-option v-for="(i, index) in subjectList" :key="index" :label="i.name" :value="i.id"></el-option>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ <template #custom="{item}">
|
|
|
+ <template v-if="item.model == 'date'">
|
|
|
+ <el-date-picker v-model="dateArray" type="date" placeholder="请选择" format="yyyy-MM-dd" value-format="yyyy-MM-dd" @change="changeDate">
|
|
|
+ </el-date-picker>
|
|
|
+ <el-col :span="24">
|
|
|
+ 答疑时间:<span v-for="item in dateList" :key="item"
|
|
|
+ >{{ item }}<el-button type="text" size="mini" @click="deleteDate(item)">删除</el-button>;</span
|
|
|
+ >
|
|
|
+ </el-col>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </data-form>
|
|
|
+ </detail-frame>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import detailFrame from '@frame/layout/admin/detail-frame';
|
|
|
+import dataForm from '@frame/components/form';
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: subject } = createNamespacedHelpers('subject');
|
|
|
+const { mapActions: answerapply } = createNamespacedHelpers('answerapply');
|
|
|
+export default {
|
|
|
+ metaInfo: { title: '课后答疑' },
|
|
|
+ name: 'afterClassDetail',
|
|
|
+ props: {},
|
|
|
+ components: {
|
|
|
+ detailFrame,
|
|
|
+ dataForm,
|
|
|
+ },
|
|
|
+ data: function() {
|
|
|
+ return {
|
|
|
+ info: {},
|
|
|
+ fields: [
|
|
|
+ { label: '科目', required: true, model: 'subid', type: 'select' },
|
|
|
+ { label: '时间', required: false, model: 'date', custom: true },
|
|
|
+ ],
|
|
|
+ rules: {
|
|
|
+ subid: [{ required: true, message: '请选择科目名称' }],
|
|
|
+ },
|
|
|
+ // 科目列表
|
|
|
+ subjectList: [],
|
|
|
+ // 选择时间
|
|
|
+ dateArray: '',
|
|
|
+ // 时间列表
|
|
|
+ dateList: [],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getOtherList();
|
|
|
+ if (this.id) {
|
|
|
+ this.search();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...subject({ getSubjectList: 'query' }),
|
|
|
+ ...answerapply(['fetch', 'create', 'update']),
|
|
|
+ // 查詢詳情
|
|
|
+ async search() {
|
|
|
+ let res = await this.fetch(this.id);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `dateList`, res.data.date);
|
|
|
+ this.$set(this, `info`, res.data);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 查询科目
|
|
|
+ async getOtherList() {
|
|
|
+ let res = await this.getSubjectList();
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `subjectList`, res.data);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 添加
|
|
|
+ async handleSave({ isNew, data }) {
|
|
|
+ let res;
|
|
|
+ let msg;
|
|
|
+ if (isNew) {
|
|
|
+ data.teacherid = this.user.userid;
|
|
|
+ data.teacher = this.user.name;
|
|
|
+ data.date = this.dateList;
|
|
|
+ console.log(data);
|
|
|
+ res = await this.create(data);
|
|
|
+ msg = `${this.keyWord}添加成功`;
|
|
|
+ } else {
|
|
|
+ res = await this.update(data);
|
|
|
+ msg = `${this.keyWord}修改成功`;
|
|
|
+ }
|
|
|
+ if (this.$checkRes(res, msg)) this.$router.push({ path: '/teaching/afterClass' });
|
|
|
+ },
|
|
|
+ // 选择时间
|
|
|
+ changeDate(value) {
|
|
|
+ if (value == null || value == '') {
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ this.dateList.push(value);
|
|
|
+ }
|
|
|
+ this.dateArray = '';
|
|
|
+ },
|
|
|
+ // 删除时间
|
|
|
+ deleteDate(index) {
|
|
|
+ this.dateList.splice(index, 1);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
+ id() {
|
|
|
+ return this.$route.query.id;
|
|
|
+ },
|
|
|
+ isNew() {
|
|
|
+ return this.$route.query.id ? false : true;
|
|
|
+ },
|
|
|
+ mainTitle() {
|
|
|
+ let meta = this.$route.meta;
|
|
|
+ let main = meta.title || '';
|
|
|
+ let sub = meta.sub || '';
|
|
|
+ return `${main}${sub}`;
|
|
|
+ },
|
|
|
+ keyWord() {
|
|
|
+ let meta = this.$route.meta;
|
|
|
+ let main = meta.title || '';
|
|
|
+ return main;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ isNew: {
|
|
|
+ immediate: true,
|
|
|
+ handler(val) {
|
|
|
+ if (val) this.loading = false;
|
|
|
+ else this.search();
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped></style>
|