<template>
  <el-dialog v-if="dialogVisible" :visible.sync="dialogVisible" :v-loading="loading" title="申辩记录">
    <el-table :data="list" border>
      <el-table-column prop="CREATTIME" label="申辩时间"/>
      <el-table-column prop="INSPECTED_EXPLAIN" label="申辩描述"/>
      <el-table-column prop="ISPASS" label="申辩状态">
        <template slot-scope="{row}">
          {{ row.ISPASS === '0'?'待审核': (row.ISPASS === '1'?'申辩成功':row.ISPASS === '2'?'申辩驳回':'历史数据' ) }}
        </template>
      </el-table-column>
      <el-table-column prop="INSPECTED_SITEUSER_SIGN_IMG" label="签字图片">
        <template slot-scope="{row}">
          <el-image
            :src="config.fileUrl + row.INSPECTED_SITEUSER_SIGN_IMG"
            :preview-src-list="new Array(config.fileUrl + row.INSPECTED_SITEUSER_SIGN_IMG)"
            :z-index="9999"
            style="width: 100px; height: 100px"/>
        </template>
      </el-table-column>
      <el-table-column prop="INSPECTED_EXPLAIN_FILENAME" label="申辩附件名称"/>
      <el-table-column prop="INSPECTED_EXPLAIN_FILEPATH" label="申辩附件">
        <template slot-scope="{row}">
          <el-button :disabled="!row.INSPECTED_EXPLAIN_FILENAME" type="primary" @click="downloadFile(row.INSPECTION_EXPLAIN_ID)">下载</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="INSPECTION_ORIGINATOR_SIGN_IMG" label="检查人签字">
        <template slot-scope="{row}">
          <el-image
            v-if="row.ISPASS === '2'"
            :src="config.fileUrl + row.INSPECTION_ORIGINATOR_SIGN_IMG"
            :preview-src-list="new Array(config.fileUrl + row.INSPECTION_ORIGINATOR_SIGN_IMG)"
            :z-index="9999"
            style="width: 100px; height: 100px"/>
        </template>
      </el-table-column>
      <el-table-column prop="INSPECTED_EXPLAIN_REFUSE" label="检查人意见">
        <template slot-scope="{row}">
          {{ row.ISPASS === '2' ? row.INSPECTED_EXPLAIN_REFUSE : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="INSPECTION_ORIGINATOR_SIGN_TIME" label="审批时间">
        <template slot-scope="{row}">
          {{ row.ISPASS === '2' ? row.INSPECTION_ORIGINATOR_SIGN_TIME : row.ISPASS === '1' ? row.OPERATTIME : '' }}
        </template>
      </el-table-column>
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import WriteSign from '@/components/WriteSign'
import waves from '@/directive/waves' // waves directive
export default {
  components: { Pagination, WriteSign },
  directives: { waves },
  data() {
    return {
      dialogVisible: false,
      loading: false,
      config: config,
      list: [],
      listQuery: {
        page: 1,
        limit: 20
      }
    }
  },
  methods: {
    init(id) {
      this.dialogVisible = true
      this.loading = true
      requestFN(
        '/safetyenvironmental/getExplain?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          INSPECTION_ID: id
        }
      ).then((data) => {
        this.loading = false
        this.list = data.list
      }).catch((e) => {
        this.$message.error(e)
        this.listLoading = false
      })
    },
    downloadFile(id) {
      this.$confirm('确定要下载此文件吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = false
        window.location.href = config.httpurl + 'safetyenvironmental/downloadExplain?INSPECTION_EXPLAIN_ID=' + id
      }).catch(() => {
        this.listLoading = false
      })
      this.listLoading = false
    }
  }
}

</script>
