<template>
  <div id="homework">
    <el-row>
      <el-col :span="24" class="style">
        <el-col :span="24" class="top">
          <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
        </el-col>
        <el-col :span="24" class="main">
          <el-col :span="24" class="leaveBtn"> </el-col>
          <el-col :span="24" class="leaveList">
            <shangchuan :form="form" @onConfirm="onsave"></shangchuan>
          </el-col>
          <el-col :span="24" class="foot">
            <footInfo></footInfo>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import NavBar from '@/layout/common/topInfo.vue';
import shangchuan from '@/layout/user/shangchuan.vue';
import footInfo from '@/layout/common/footInfo.vue';
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: mapUploadtask } = createNamespacedHelpers('uploadtask');
export default {
  name: 'homework',
  props: {},
  components: {
    NavBar, //头部导航
    shangchuan,
    footInfo,
  },
  data: () => ({
    form: {
      // picrul: [{ url: 'fksdfhksdhfsk' }],
    },
    show: false,
    navShow: true,
    title: '',
    isleftarrow: '',
  }),
  mounted() {
    this.title = this.$route.meta.title;
    this.isleftarrow = this.$route.meta.isleftarrow;
  },
  watch: {
    $route(to, from) {
      this.title = to.meta.title;
      this.isleftarrow = to.meta.isleftarrow;
    },
  },
  created() {},
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
    lessonid() {
      return this.$route.query.lessonid;
    },

    name() {
      return this.$route.query.name;
    },
  },
  methods: {
    ...mapUploadtask({ list: 'query', add: 'create', fet: 'fetch', updates: 'update' }),
    //提交上传
    async onsave(form) {
      this.form.termid = this.user.termid;
      this.form.batchid = this.user.batchid;
      this.form.classid = this.user.classid;
      this.form.studentid = this.user.userid;
      this.form.lessonid = this.lessonid;
      this.form.lessonname = this.name;
      let data = this.form;
      console.log();
      if (data.picrul) {
        let res = await this.add(data);
        this.$checkRes(res, '提交成功', res.errmsg);
      } else {
        this.$message({
          showClose: true,
          message: '请上传图片',
          type: 'error',
        });
      }
      //
    },
  },
};
</script>

<style lang="less" scoped>
.style {
  width: 100%;
  min-height: 667px;
  position: relative;
  background-color: #f9fafc;
}
.top {
  height: 46px;
  overflow: hidden;
}
.main {
  min-height: 570px;
}
.main .leaveBtn {
  text-align: center;
  padding: 15px 0;
}
</style>
