<template>
  <div>
    <!--2.中心主任审批-->
    <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>
            </tbody>
          </table>
        </div>
        <Form inline>
          <Form-item label="质量负责人签字" prop="qualityManagerAudit" style="width: 100%;">
            <Input v-model="qualityManagerAudit" name="qualityManagerAudit" type="text" />
          </Form-item>
          <h6 style="font-weight: 600">
            建议的纠正措施计划
          </h6>
          <Form-item style="width: 97.6%;background: white">
            <editor ref="editorModal" @on-result-change="_editorData" />
          </Form-item>
        </Form>
      </Alert>
    </div>
    <!--<div>
      <frameUnconformMeasure ref="measureModal" />
    </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" :key="item.id" class="file-upload-list">
          <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: 80px">
      <Button type="error" @click="_approve(false)">
        驳回
      </Button>
      <Button type="success" @click="_approve(true)">
        同意
      </Button>
      <Button @click="_record()">
        操作记录
      </Button>
    </div>
    <!--操作记录-->
    <unconformRegisterRecord ref="recordModal" />
  </div>
</template>
<script>
import { frameUnconformRegister } from '../../../api'
import global from '../../../api/config'
import editor from '../../../components/base/editor'
import unconformRegisterRecord from './measureManage/unconformRegisterRecord'
// import frameUnconformMeasure from './measureManage/frameUnconformMeasure'

export default {
  components: {
    // frameUnconformMeasure,
    unconformRegisterRecord,
    editor
  },
  data() {
    return {
      id: {},
      verifyPlan: '',
      qualityManagerAudit: '',
      getObj: {},
      filePath: '',
      visible: false
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this._getData()
    // this.$refs.measureModal._open()
  },
  methods: {
    _editorData(data) {
      this.verifyPlan = data.content
    },
    _record() {
      this.$refs.recordModal._open(this.id)
    },
    _getData: async function() {
      this.getObj = await frameUnconformRegister.getById(this.id)
    },
    _approve(allow) {
      this.$Modal.confirm({
        title: '提示',
        content: allow ? '确定通过？' : '确定驳回？',
        onOk: () => {
          const data = {}
          data.id = $('#flowFrame', parent.document).attr('data-tid')
          data.status = allow ? 3 : 7 //
          data.reason = this.verifyPlan
          data.audit = this.qualityManagerAudit
          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>
