|
@@ -0,0 +1,183 @@
|
|
|
+<template>
|
|
|
+ <div id="detail">
|
|
|
+ <detail-frame :title="mainTitle" returns="/trainVidoe/index">
|
|
|
+ <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 #radios="{item}">
|
|
|
+ <template v-if="item.model === 'touser'">
|
|
|
+ <el-radio label="0">所有人</el-radio>
|
|
|
+ <el-radio label="1">教师</el-radio>
|
|
|
+ <el-radio label="2">学生</el-radio>
|
|
|
+ <el-radio label="3">班主任</el-radio>
|
|
|
+ </template>
|
|
|
+ <template v-if="item.model === 'status'">
|
|
|
+ <el-radio label="0">待审核</el-radio>
|
|
|
+ <el-radio label="1">审核通过</el-radio>
|
|
|
+ <el-radio label="2">审核拒绝</el-radio>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ <template #custom="{item}">
|
|
|
+ <template v-if="item.model == 'url'">
|
|
|
+ <upload-file
|
|
|
+ :url="`/files/trainVidoe/upload`"
|
|
|
+ desc="只能上传不超过2MB文件"
|
|
|
+ :limit="100"
|
|
|
+ @upload="uploadSuccess"
|
|
|
+ @changeName="changeName"
|
|
|
+ @toRemove="toRemove"
|
|
|
+ type="url"
|
|
|
+ :data="info.url"
|
|
|
+ ></upload-file>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </data-form>
|
|
|
+ </detail-frame>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import _ from 'lodash';
|
|
|
+import uploadFile from '@/components/upload-file.vue';
|
|
|
+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: trainvideo } = createNamespacedHelpers('trainvideo');
|
|
|
+export default {
|
|
|
+ metaInfo: { title: '课程培训' },
|
|
|
+ name: 'detail',
|
|
|
+ props: {},
|
|
|
+ components: {
|
|
|
+ detailFrame,
|
|
|
+ dataForm,
|
|
|
+ uploadFile,
|
|
|
+ },
|
|
|
+ data: function() {
|
|
|
+ return {
|
|
|
+ info: {},
|
|
|
+ fields: [
|
|
|
+ { label: '科目', required: true, model: 'subid', type: 'select' },
|
|
|
+ { label: '视频地址', model: 'url', custom: true },
|
|
|
+ { label: '面向对象', model: 'touser', type: 'radio' },
|
|
|
+ ],
|
|
|
+ rules: {
|
|
|
+ subid: [{ required: true, message: '请选择科目名称' }],
|
|
|
+ reason: [{ required: true, message: '请输入申请说明' }],
|
|
|
+ },
|
|
|
+ // 科目列表
|
|
|
+ subjectList: [],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ if (this.id) {
|
|
|
+ this.fields.push({ label: '状态', required: true, model: 'status', type: 'radio' });
|
|
|
+ }
|
|
|
+ this.getOtherList();
|
|
|
+ if (this.id) {
|
|
|
+ this.search();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...subject({ getSubjectList: 'query' }),
|
|
|
+ ...trainvideo(['fetch', 'create', 'update']),
|
|
|
+ // 查詢詳情
|
|
|
+ async search() {
|
|
|
+ let res = await this.fetch(this.id);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ 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;
|
|
|
+ let subject = this.subjectList.find(f => f.id == data.subid);
|
|
|
+ if (subject) {
|
|
|
+ data.subname = subject.name;
|
|
|
+ }
|
|
|
+ data.status = '1';
|
|
|
+ if (isNew) {
|
|
|
+ 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: '/trainVidoe/index' });
|
|
|
+ },
|
|
|
+ uploadSuccess({ type, data }) {
|
|
|
+ if (type !== 'url') {
|
|
|
+ let arr = _.get(this.info, type);
|
|
|
+ if (arr !== undefined) {
|
|
|
+ this.info[type].push({ name: data.name, uri: data.uri });
|
|
|
+ } else {
|
|
|
+ let newArr = [{ name: data.name, uri: data.uri }];
|
|
|
+ this.$set(this.info, `${type}`, newArr);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$set(this.info, `${type}`, data.uri);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ toRemove({ type, data }) {
|
|
|
+ if (type !== 'url') {
|
|
|
+ let arr = _.get(this.info, type);
|
|
|
+ let newArr = arr.filter(item => item.uri !== data.url);
|
|
|
+ this.$set(this.info, `${type}`, newArr);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ changeName({ type, data }) {
|
|
|
+ console.log(type, data);
|
|
|
+ let newObject = { name: data.name, uri: data.url };
|
|
|
+ let list = _.get(this.info, type);
|
|
|
+ if (list.length > 0) {
|
|
|
+ let index = _.findIndex(list, item => {
|
|
|
+ return item.uri === data.url;
|
|
|
+ });
|
|
|
+ this.$set(list, `${index}`, newObject);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 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>
|