<template>
  <div id="preview">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="top">
          <el-button type="primary" size="mini" @click="download">PDF下载</el-button>
          <el-button type="primary" size="mini" @click="back">返回</el-button>
        </el-col>
        <el-col :span="24" class="down">
          <div id="demo">
            <el-col :span="24" class="common one">
              <el-col :span="24" class="title"> {{ form.basic.achieve_name }}({{ type == '1' ? '专家评分鉴定意见' : '专家会审鉴定意见' }}) </el-col>
              <listpdf :list="list"></listpdf>
            </el-col>
          </div>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import listpdf from './parts/listpdf.vue';
import htmlToPdf from '@/unit/htmlToPdf.js';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: achieveApply } = createNamespacedHelpers('achieveApply');
const { mapActions: achieveApplyExpert } = createNamespacedHelpers('achieveApplyExpert');
export default {
  name: 'preview',
  props: {},
  components: { listpdf },
  data: function() {
    return {
      form: {
        // 基本信息
        basic: {},
        // 信息简介
        brief: {},
        // 参加人员
        research: [],
        // 图片
        file: {},
      },
      list: [],
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...achieveApply(['fetch', 'update']),
    ...achieveApplyExpert(['query']),
    async search({ skip, limit = 10, ...info } = {}) {
      if (this.id) {
        let res = await this.fetch(this.id);
        if (this.$checkRes(res)) {
          this.$set(this, 'form', res.data);
        }
        res = await this.query({ ...info, apply_id: this.id, expert: true, type: this.type });
        if (this.$checkRes(res)) {
          this.$set(this, `list`, res.data);
        }
      }
    },
    // PDF下载
    download() {
      htmlToPdf.downloadPDF(document.querySelector('#demo'), '专家意见');
    },
    // 返回
    back() {
      if (this.type == '1') {
        this.$router.push({ path: '/adminScore/detail', query: { id: this.id } });
      } else if (this.type == '2') {
        this.$router.push({ path: '/adminMeet/expert', query: { id: this.id } });
      }
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
    type() {
      return this.$route.query.type;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .top {
    text-align: center;
    margin: 0 0 15px 0;
  }
  .down {
    padding: 0 20%;
    #demo {
      width: 100%;
      height: 1389px;
      border: 1px solid #ff0000;
      .one {
        height: 1389px;
        padding: 20px;
        .title {
          text-align: center;
          margin: 0 0 10px 0;
          font-size: 18px;
          font-family: monospace;
          font-weight: bold;
        }
      }
    }
  }
}
.common {
  width: 100%;
  height: 1389px;
  border-bottom: 1px solid #666666;
  padding: 40px 20px;
}
</style>
