<template>
  <div id="detail">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="top">
          <el-button type="primary" size="mini" @click="back">返回</el-button>
        </el-col>
        <el-col :span="24" class="down">
          <el-col :span="24" class="setp">
            <el-steps :active="active" align-center>
              <el-step title="吉林省科技成果评价证书"> </el-step>
              <el-step title="（一）成果评价基础信息"> </el-step>
              <el-step title="（二）研究（开发，转化，实施，建设）内筒和技术（创新点）"></el-step>
              <el-step title="（三）成果取得的技术，经济指标（目标）"></el-step>
              <el-step title="（四）成果参加人员"></el-step>
              <el-step title="（五）现场测试（监测，测产）意见"></el-step>
              <el-step title="（六）评价意见"></el-step>
              <el-step title="（七）评价专家组名单"></el-step>
            </el-steps>
          </el-col>
          <el-col :span="24" class="form">
            <one :form="form" @next="next('2')" v-if="active == '1'"></one>
            <two :form="form" @up="up('1')" @next="next('3')" v-else-if="active == '2'"></two>
            <thr :form="form" @up="up('2')" @next="next('4')" v-else-if="active == '3'"></thr>
            <four :form="form" @up="up('3')" @next="next('5')" v-else-if="active == '4'"></four>
            <five :form="form" @up="up('4')" @next="next('6')" v-else-if="active == '5'"></five>
            <six :form="form" @up="up('5')" @next="next('7')" v-else-if="active == '6'"></six>
            <seven :form="form" @up="up('6')" @next="next('8')" v-else-if="active == '7'"></seven>
            <eight :form="form" @up="up('7')" @onSubmit="onSubmit" v-else-if="active == '8'"></eight>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import one from './parts/one.vue';
import two from './parts/two.vue';
import thr from './parts/thr.vue';
import four from './parts/four.vue';
import five from './parts/five.vue';
import six from './parts/six.vue';
import seven from './parts/seven.vue';
import eight from './parts/eight.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: achieveApply } = createNamespacedHelpers('achieveApply');
export default {
  name: 'detail',
  props: {},
  components: { one, two, thr, four, five, six, seven, eight },
  data: function() {
    return {
      // 成果详情
      active: 1,
      form: {
        // 基本信息
        basic: {},
        // 内容简介
        brief: {},
        // 参加人员
        research: [],
        // 会审照片
        file: {},
      },
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...achieveApply(['fetch', 'update']),
    async search() {
      if (this.id) {
        let res = await this.fetch(this.id);
        if (this.$checkRes(res)) {
          this.$set(this, 'form', res.data);
        }
      }
    },
    back() {
      this.$router.push({ path: '/adminCate' });
    },
    // 提交
    async onSubmit({ data }) {
      console.log(data);
      let res = await this.update(data);
      if (this.$checkRes(res)) {
        this.$message({
          message: '信息归档成功',
          type: 'success',
        });
        this.back();
      }
    },
    // 上一步
    up(type) {
      this.active = parseInt(type);
    },
    // 下一步
    next(type) {
      this.active = parseInt(type);
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {},
};
</script>

<style lang="less" scoped>
.main {
  .top {
    text-align: right;
    margin: 0 0 15px 0;
  }
  .down {
    .setp {
      margin: 0 0 10px 0;
      /deep/.el-step__title {
        font-size: 14px;
        line-height: 20px;
        padding: 15px 0 0 0;
      }
    }
  }
}
</style>
