<template>
  <div id="file">
    <el-row type="flex">
      <el-col :span="21">{{ data.title }}----视频列表</el-col>
      <el-col :span="2">
        <el-button type="primary" @click="$router.push('/adminCenter/online')" size="mini">返回</el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <e-upload url="/files/cysci/online_video/upload" v-model="data.video" type="text"></e-upload>
      </el-col>
      <el-col :span="24" style="text-align: center">
        <el-button type="primary" @click="toSave">保存</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: online } = createNamespacedHelpers('online');
export default {
  name: 'onlineFile',
  props: {},
  components: {},
  data: function () {
    return {
      data: {
        video: [],
      },
    };
  },
  created() {
    if (this.id) this.search();
  },
  methods: {
    ...online(['fetch', 'create', 'update']),
    async search() {
      const res = await this.fetch(this.id);
      if (this.$checkRes(res)) {
        this.$set(this, `data`, res.data);
      }
    },
    async toSave() {
      let dup = _.cloneDeep(this.data);
      let res;
      if (_.get(dup, 'id')) {
        res = await this.update(dup);
      } else {
        res = await this.create(dup);
      }
      if (this.$checkRes(res, '保存成功', '保存失败')) {
        if (!this.$dev_mode) this.$router.push('/adminCenter/news');
      }
    },
  },
  computed: {
    ...mapState(['user', 'menuParams']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
    id() {
      return this.$route.query.id;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped></style>
