<style lang="scss" scoped>
.preview {
  .aname{
    text-align: center;
    margin-bottom: 20px;
    color: #333;
    font-size: 16px;
  }
  .ainfo{
    display: flex;
    margin-bottom: 10px;
    p{
      width: 60%;
      margin-left: 15px;
      line-height: 26px;
    }
  }
  b{
    color: #333;
  }
  div{
    line-height: 26px;
    margin-bottom: 10px;
    overflow: auto;
  }

}
.content .title {
  height: 32px;
  font-size: 14px;
  font-weight: bold;
  color: #333333;
  border-bottom: 1px solid #d8d8d8;
  margin-bottom: 25px;
}
.el-form {
  font-size: 14px;
  font-weight: 400;
  color: #666666;
  .el-select,
  .el-range-editor--small.el-input__inner {
    width: 100%;
  }
}
/deep/.el-tabs__header {
  margin: 0;
  .el-tabs__active-bar {
    height: 0px;
  }
  .el-tabs__item {
    width: 160px;
    height: 40px;
    text-align: center;
    border-radius: 8px 8px 0px 0px;
    color: #333333;
    background: #ececec;
    margin-right: 10px;
  }
  .el-tabs__item.is-active {
    background: #3895fe;

    color: #ffffff;
  }
}
.el-button {
  width: 120px;
  height: 36px;
}
// 上传

/deep/.avatar-uploader .el-upload {
  width: 148px;
  height: 148px;
  line-height: 148px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  .avatar {
    width: 100%;
    height: 100%;
  }
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 68px;
  height: 68px;
  line-height: 68px;
  text-align: center;
}
.avatar {
  width: 68px;
  height: 68px;
  display: block;
}
/deep/.speaker_avatar .el-upload {
  width: 80px;
  height: 80px;
  line-height: 80px;
}
.hotel_imgs {
  /deep/.el-upload--picture-card {
    width: 79px;
    height: 79px;
    line-height: 79px;
  }
}

</style>
<template>
  <section>
    <p><span>作业管理></span>查看作业</p>
    <div class="content" v-loading='loading' element-loading-background="rgba(0, 0, 0, 0)">
      <el-form ref="form" :model="form" label-width="80px">
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="作业名称">
              <el-input v-model="form.filename" placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <a :href="form.dlink" target="_blank"><el-button type="primary">下載</el-button></a>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="狀態">
              <el-select v-model="form.status" placeholder="">
                <el-option label="未批改" :value="0"></el-option>
                <el-option label="已批改" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="4" :offset="20">
            <el-button type="primary" @click="save">保存</el-button>
            <el-button type="normal" @click='$router.go(-1)'>返回</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </section>
</template>
<script>

export default {
  components: {
  },
  data() {
    return {
      loading:false,
      form:{}
    };
  },
  methods: {
    getData(){
      let id = this.$route.query.id;
      if (id) {
        this.loading = true;
        this.$api.getHomeWorkInfo({ id: id }).then((res) => {
          this.form = res.data.data;
          this.$api.getWorkInfo({fsid:res.data.data.fs_id}).then((res)=>{
            this.form.dlink = res.data.data.dlink;
            this.loading = false;
          })
        });
      }
    },
    save(status) {
      let id = this.$route.query.id;
      let parm = this.form;
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (id) {
            parm.id = id;
            parm.status = String(parm.status)
            this.$api.updateHomeWork(parm).then((res) => {
              if (res.data.code == 0) {
                this.$message({
                  type: "success",
                  message: status==1?"保存成功!":"发布成功!",
                });
                this.$router.go(-1)
                
              } else {
                this.$message.error(status==1?"保存失败!":"发布失败!");
              }
            });
          }
        } else {
            this.$message.error("有必填项没有填!");
        }
      });
    },
  },
  created() {
    this.getData()
  },
};
</script>
