<template>
  <div class="app-container" v-loading="loading">
    <el-tabs stretch v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="加计年度企业基本信息" name="1">
        <year-edit :type="type" :info.sync="form"></year-edit>
      </el-tab-pane>
      <el-tab-pane label="企业研发项目情况表" name="2" :disabled="entDisabled">
        <ent-edit :type="type" :info.sync="form"></ent-edit>
      </el-tab-pane>
      <el-tab-pane label="上传文件" name="3" :disabled="encDisabled">
        <enclosure-edit :type="type"></enclosure-edit>
      </el-tab-pane>
    </el-tabs>
    <div class="oper" v-if="oper == 'audit'">
      <el-button @click="handleAudit('4')" type="primary">审核通过</el-button>
      <el-button @click="handleAudit('1')" type="danger">审核驳回</el-button>
    </div>
  </div>
</template>

<script>
import YearEdit from "./components/year-edit.vue"
import EntEdit from "./components/ent-edit.vue"
import EnclosureEdit from "./components/enclosure-edit.vue"
import { devProjectApi } from "@/api/enterprise/project/project"
import {submitDeclareApi} from "@/api/enterprise/declare/declare"
export default {
  name: "projectEdit",
  computed: {
    userType() {
      return this.$store.state.user.userType
    },
  },
  components: {
    YearEdit,
    EntEdit,
    EnclosureEdit
  },
  data() {
    return {
      oper: this.$route.query.oper || "",
      activeName: "1",
      loading: false,
      id: undefined,
      entDisabled: false,
      encDisabled: false,
      type: "",
      form: {},
      source: ""
    };
  },
  created() {
    this.id = this.$route.query.id || undefined;
    this.type = this.$route.query.type || ""
    this.source = this.$route.query.source || ""
    this.activeName = this.$route.query.activeName || "1"
    if(this.id) {
      this.getData()
    }
    if(this.type == 'year' || this.source == 'add') {
      this.entDisabled = true
      this.encDisabled = true
    }else {
      this.entDisabled = false
      this.encDisabled = false
    }
  },
  methods: {
    getEntData() {

    },
    handleClick(tab,event) {

    },
    async getData() {
      devProjectApi(this.id).then(res => {
        this.form = res.data || {}
      })
    },
    handleAudit(type) {
      let _self = this
      this.$confirm('是否确认提交审核该数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return submitDeclareApi(_self.id,type);
        }).then(() => {
          _self.$message({
            message: '提交成功',
            type: 'success'
          });
          _self.$router.go(-1)
        })
    },
  }
};
</script>
