<template>
  <div>
    <template>
      <el-card class="box-card">
        <div slot="header">
          <span style="font-weight: bold">检验流程</span>
        </div>
        <el-steps :active="7" align-center>
          <el-step title="申请检验" />
          <el-step title="安排检验" />
          <el-step title="等待检验" />
          <el-step title="进行检验" />
          <el-step title="检验结束" />
          <el-step title="生成报告" />
          <el-step title="等待打印" />
        </el-steps>
      </el-card>
    </template>
    <el-card class="box-card">
      <div slot="header">
        <span style="font-weight: bold">{{ this.$store.getters.name }} - {{ this.$store.getters.shiyongdanwei }}</span>
      </div>
      <el-table :data="list" height="550" border style="width: 100%">
        <el-table-column align="center" type="selection" />
        <el-table-column align="center" type="index" label="序号" width="67" />
        <el-table-column align="center" prop="baogaobianhao" label="报告编号" width="180" />
        <el-table-column :formatter="formatterCategory" align="center" prop="jianyanleibie" label="检验类别" width="180" />
        <el-table-column align="center" prop="zhucedaima" label="注册代码" width="200" />
        <el-table-column align="center" prop="chanpinbianhao" label="产品编号" width="200" />
        <el-table-column align="center" prop="shiyongdengjibianhao" label="使用登记编号" width="200" />
        <el-table-column align="center" prop="quhuamingcheng" label="区划名称" width="120" />
        <el-table-column align="center" prop="shouliriqi" label="报检日期" width="100" />
        <el-table-column align="center" prop="jianyanriqi" label="检验日期" width="100" />
        <el-table-column :formatter="formatterStatus" align="center" prop="status" label="检验状态" width="100" />
        <el-table-column align="center" prop="access" label="操作" width="268">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-printer" @click="print(scope.row, 'JYBG')">
              打印报告
            </el-button>
            <el-button type="primary" title="" size="mini" icon="el-icon-printer" @click="print(scope.row, 'HGZ')">
              打印合格证
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { pullSenior } from '@/api/search'
import { formatterCategory } from '@/utils/category'
import { pullSeniorPath } from '@/api/download'

export default {
  name: 'Senior',
  data() {
    return {
      list: []
    }
  },
  created() {
    this.pull()
  },
  methods: {
    pull() {
      pullSenior(this.$store.getters.userId).then(data => {
        this.list = data.list
      })
    },
    print(report, type) {
      if (report.link === 'reportState' && report.status > 3) {
        pullSeniorPath({
          id: report.id,
          type: type
        }).then(data => {
          window.open(data.data)
        })
      } else {
        this.$notify.error({
          title: '错误',
          message: '报告流程在检验结束时才可以进行打印！',
          duration: 1000 * 60
        })
      }
    },
    formatterCategory(row) {
      return formatterCategory(row.jianyanleibie)
    },
    formatterStatus(row) {
      switch (row.link) {
        case 'bjstate':
          return '申请检验'
        case 'fpState':
          return '安排检验'
        case 'renwuState':
          return '等待检验'
        case 'ysjlState':
          return '进行检验'
        case 'reportState':
          if (row.status > 3) {
            return '等待打印'
          } else {
            return '进行检验'
          }
      }
    }
  }
}
</script>

<style scoped>
</style>
