<template>
  <div>
    <el-dialog
      :visible.sync="showModal"
      title="流程详情"
      fullscreen
      top="0"
    >
      <div>
        <!-- 执行顺序 -->
        <Alert class="equip_alert">
          <div>
            <table class="tableClass table1Class">
              <tbody>
                <tr>
                  <th colspan="4" style="text-align: center;font-size: 15px">
                    仪器维修申请单
                  </th>
                </tr>
                <tr>
                  <th>申请编号</th>
                  <td>{{ getObj.num }}</td>
                  <th>申请人</th>
                  <td>{{ getObj.applyName }}</td>
                </tr>
                <tr>
                  <th>申请时间</th>
                  <td>{{ this.$dateformat(getObj.applyTime, 'yyyy-mm-dd HH:MM') }}</td>
                  <th>申请原因</th>
                  <td>{{ getObj.applyReason }}</td>
                </tr>
                <tr>
                  <th>备注</th>
                  <td colspan="3">
                    {{ getObj.remark }}
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </Alert>
      </div>
      <div style="margin-top: 10px">
        <element-table
          ref="pageTable"
          :page-columns="pageColumns"
          :get-page="getPage"
          :table-height="360"
          hide-page
          @on-result-change="_tableResultChange"
        >
          <el-table-column
            v-for="item in pageColumns"
            :key="item.key"
            show-overflow-tooltip
            :prop="item.key"
            :label="item.title"
            :min-width="item.width"
            :fixed="item.fixed?item.fixed:undefined"
          >
            <template slot-scope="scope">
              <div v-if="item.datetime">
                {{ scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd HH:MM'):'' }}
              </div>
              <div v-else>
                {{ scope.row[item.key] }}
              </div>
            </template>
          </el-table-column>
        </element-table>
      </div>
      <Form id="file-form-detail" :label-width="90" inline style="margin-top: 10px;">
        <Form-item label="附件上传">
          <div v-for="item in lmsEquipFiles" :key="item" 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>
    </el-dialog>
  </div>
</template>
<script>
import global from '../../../../api/config'
import { equipRepair, equipRepairDetail } from '../../../../api'

export default {
  data() {
    return {
      pageColumns: [
        { title: '仪器编号', key: 'labNum', width: 160 },
        { title: '仪器名称', key: 'name', width: 160 },
        { title: '故障原因', key: 'breakdown', width: 160 },
        { title: '故障时间', key: 'failureTime', width: 180, datetime: true },
        { title: '计划维修人员', key: 'repairerNames', width: 160 },
        {
          title: '计划维修开始时间',
          key: 'repairStartTimePlan',
          width: 180,
          datetime: true
        },
        {
          title: '计划维修结束时间',
          key: 'repairEndTimePlan',
          width: 180,
          datetime: true
        },
        { title: '备注', key: 'remark', width: 160 },
        { title: '规格型号', key: 'spec', width: 160 },
        { title: '制造厂商', width: 200, key: 'productPlace' }
      ],
      getPage: {
        records: []
      },
      showModal: false,
      id: '',
      getObj: {},
      dataObj: {
        repairId: ''
      },
      filePath: '',
      lmsEquipFiles: []
    }
  },
  methods: {
    _open(id) {
      this.showModal = true
      this.$nextTick(function() {
        this.id = id
        this._page()
        this._repair()
      })
    },
    _page: async function() {
      const obj = Object.assign(
        { repairId: this.id },
        this.$refs.pageTable._searchParams()
      )
      const result = await equipRepairDetail.page(obj)
      if (result) {
        for (let i = 0; i < result.records.length; i++) {
          result.records[i].failureTime = result.records[i].failureTime
            ? new Date(result.records[i].failureTime)
            : ''
          result.records[i].repairStartTimePlan = result.records[i]
            .repairStartTimePlan
            ? new Date(result.records[i].repairStartTimePlan)
            : ''
          result.records[i].repairEndTimePlan = result.records[i]
            .repairEndTimePlan
            ? new Date(result.records[i].repairEndTimePlan)
            : ''
        }
        this.getPage.records = result.records
        this.$refs.pageTable._initTable()
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
      }
    },
    _repair: async function() {
      this.getObj = await equipRepair.getById(this.id)
      this.lmsEquipFiles = this.getObj.lmsEquipFiles
    },
    // 文件预览
    _handleView(data) {
      this.filePath = data.filePath
      const index1 = this.filePath.lastIndexOf('.')
      const index2 = this.filePath.length
      const suffix = this.filePath.substring(index1 + 1, index2) // 后缀名
      if (suffix === 'png' || suffix === 'jpg' || suffix === 'jpeg') {
        this.visible = true
      } else {
        this.$Message.warning({
          content: '非图片文件无法查看，请下载查看',
          duration: 3
        })
        this.visible = false
      }
    },
    // 文件下载
    _downloadFile(file) {
      // this.$Modal.confirm({
      //   title: '提示',
      //   content: '确定要下载？',
      //   onOk: () => {
      const url =
        global.baseURL + '/res/v1/equip_repair/downLoadFile?id=' + file.id
      window.open(url, ' _blank')
      // }
      // })
    }
  }
}
</script>
