<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">
              <span>{{ scope.row[item.key] }}</span>
            </template>
          </el-table-column>
        </element-table>
      </div>
      <Form id="scrap-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 { equipScrapDetail } from '../../../../api'

export default {
  data() {
    return {
      id: {},
      showModal: false,
      pageColumns: [
        { title: '仪器编号', key: 'labNum', width: 160, fixed: true },
        { title: '仪器名称', key: 'name', width: 160 },
        { title: '报废原因', key: 'reason', width: 160 },
        { title: '金额', key: 'money', width: 160 },
        { title: '备注', key: 'remark', width: 160 },
        { title: '规格型号', key: 'spec', width: 160 },
        { title: '制造厂商', key: 'productPlace', width: 160 }
      ],
      getPage: {
        records: []
      },
      getObj: {},
      dataObj: {
        scrapId: ''
      },
      filePath: '',
      lmsEquipFiles: []
    }
  },
  methods: {
    _open(id) {
      this.showModal = true
      this.$nextTick(function() {
        this.id = id
        this._page()
      })
    },
    _page: async function() {
      const obj = Object.assign(
        { repairId: this.id },
        this.$refs.pageTable._searchParams()
      )
      const result = await equipScrapDetail.getById(obj)
      if (result) {
        this.getObj = result
        this.lmsEquipFiles = this.getObj.lmsEquipFiles
        this.getPage = {
          records: result.lmsEquipScrapDetailVOList
        }
        this.$refs.pageTable._initTable()
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
      }
    },
    // 文件预览
    _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) {
      const url =
        global.baseURL + '/res/v1/equip_scrap/downLoadFile?id=' + file.id
      window.open(url, ' _blank')
    }
  }
}
</script>
