<template>
  <div>
    <!--1.技术主管审批-->
    <div>
      <!-- 执行顺序 -->
      <Alert class="equip_alert">
        <div>
          <table class="tableClass table1Class">
            <tbody>
              <tr>
                <th>受审核部门</th>
                <td>{{ getObj.orgName }}</td>
                <th>部门负责人</th>
                <td>{{ getObj.orgManagerName }}</td>
              </tr>
              <tr>
                <th>登记人</th>
                <td>{{ getObj.registerName }}</td>
                <th>登记时间</th>
                <td>{{ this.$dateformat(getObj.registerTime, "yyyy-mm-dd HH:MM") }}</td>
              </tr>
              <tr>
                <th>不符合条款</th>
                <td colspan="3">
                  {{ getObj.unconformItemText }}
                </td>
              </tr>
              <tr>
                <th>备注</th>
                <td colspan="3">
                  {{ getObj.remark }}
                </td>
              </tr>
            </tbody>
          </table>
          <table class="tableClass table1Class">
            <tbody>
              <tr>
                <th>部门负责人签字</th>
                <td>{{ getObj.orgManagerAudit }}</td>
                <th>部门负责人签字时间</th>
                <td>{{ this.$dateformat(getObj.orgManagerTime, "yyyy-mm-dd HH:MM") }}</td>
              </tr>
              <tr>
                <th>不符合项原因分析</th>
                <td colspan="3">
                  {{ getObj.unconformReason }}
                </td>
              </tr>
              <tr>
                <th>质量负责人签字</th>
                <td>{{ getObj.qualityManagerAudit }}</td>
                <th>质量负责人签字时间</th>
                <td>{{ this.$dateformat(getObj.qualityManagerTime, "yyyy-mm-dd HH:MM") }}</td>
              </tr>
              <tr>
                <th>建议的纠正措施计划</th>
                <td colspan="3">
                  {{ getObj.verifyPlan }}
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </Alert>
    </div>
    <Form v-if="getObj.lmsFrameFileList&&getObj.lmsFrameFileList.length!==0" :label-width="90" inline>
      <Form-item label="附件报告单:" style="width: 98.6%;margin-top:10px">
        <div v-for="item in getObj.lmsFrameFileList" class="file-upload-list" :key="item.id">
          <div>
            <div class="file-upload-list-cover">
              <Icon type="ios-eye-outline" @click.native="_handleView(item)"/>
              <Icon type="ios-cloud-download-outline" @click.native="_downloadFile(item)" />
            </div>
          </div>
          {{ item.orginName }}
        </div>
      </Form-item>
    </Form>
    <Modal title="查看图片" v-model="visible" footer-hide>
      <img :src="filePath" v-if="visible" style="width: 100%">
    </Modal>
    <!--操作-->
    <div slot="footer" align="center" style="margin-top: 150px">
      <Button type="error" @click="_approve()">
        确定
      </Button>
    </div>
  </div>
</template>
<script>
import { frameUnconformRegister } from '../../../api'
import global from '../../../api/config'

export default {
  data() {
    return {
      id: {},
      getObj: {},
      filePath: '',
      visible: false
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this._getData()
  },
  methods: {
    _getData: async function() {
      this.getObj = await frameUnconformRegister.getById(this.id)
    },
    _approve() {
      this.$Modal.confirm({
        title: '提示',
        content: '确认？',
        onOk: () => {
          const data = {}
          data.id = $('#flowFrame', parent.document).attr('data-tid')
          data.status = 'false' // 确认通知申请人
          this._approveOk(data)
        }
      })
    },
    _approveOk: async function(data) {
      const result = await frameUnconformRegister.approve(data)
      if (result) {
        this.$Message.success('审批成功！')
        setTimeout(() => {
          parent.location.replace(global.webURL + '/sys/workflow/flow_task')
        }, 200)
      }
    },
    _handleView(data) {
      this.filePath = data.filePath
      if (
        this.filePath.indexOf('jpg') > -1 ||
        this.filePath.indexOf('png') > -1 ||
        this.filePath.indexOf('jpeg') > -1
      ) {
        this.visible = true
      } else {
        this.$message.warning('非图片文件无法查看，请下载查看')
        this.visible = false
      }
    },
    _downloadFile(file) {
      // 下载文件
      this.$Modal.confirm({
        title: '提示',
        content: '确定要下载？',
        onOk: () => {
          const url =
            global.baseURL +
            '/res/v1/frame_unconform_register/downLoadFile?id=' +
            file.id
          window.open(url)
        }
      })
    }
  }
}
</script>
