<template>
  <div>
    <!--1.技术主管审批-->
    <div>
      <!-- 执行顺序 -->
      <Alert class="equip_alert">
        <div>
          <table class="tableClass table1Class">
            <tbody>
              <tr>
                <th>计划名称</th>
                <td>{{ getObj.name }}</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>
              <tr>
                <th>技术主管</th>
                <td>{{ getObj.firstStepName }}</td>
                <th>技术主管审批时间</th>
                <td>{{ this.$dateformat(getObj.firstStepTime, "yyyy-mm-dd HH:MM") }}</td>
              </tr>
              <tr>
                <th>技术主管意见</th>
                <td colspan="3">
                  {{ getObj.firstStepAdvice }}
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </Alert>
    </div>

    <div style="margin-bottom: 10px">
      <element-table
        ref="pageTable"
        :page-columns="pageColumns"
        :get-page="getPage"
        :table-height="360"
        @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.date">
              {{ scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd'):'' }}
            </div>
            <div v-else>
              {{ scope.row[item.key] }}
            </div>
          </template>
        </el-table-column>
      </element-table>
    </div>
    <Form id="edit-form" :label-width="90" inline>
    <Form-item label="附件报告单" style="width: 98.6%;">
        <div v-for="item in lmsEquipFiles" class="file-upload-list" :key="item.id">
          <div>
            <div class="file-upload-list-cover">
              <Icon type="ios-cloud-download-outline" @click.native="_downloadFile(item)" />
            </div>
          </div>
          {{ item.orginName }}
        </div>
      </Form-item>
    </Form>
    <!--操作-->
    <div slot="footer" align="center" style="margin-top: 100px;">
      <Button type="error" @click="_approve()">
        确认
      </Button>
    </div>
  </div>
</template>
<script>
import { equipMaintain, equipMaintainDetail, equipFile } from '../../../../api'
import global from '../../../../api/config'

export default {
  data() {
    return {
      lmsEquipFiles: [], // 文件集合
      id: '',
      pageColumns: [
        {
          title: '仪器名称',
          key: 'name',
          width: 160,
          fixed: true
        },
        { title: '仪器编号', key: 'equipNum', width: 160 },
        { title: '规格型号', key: 'spec', width: 160 },
        { title: '实验室编号', key: 'labNum', width: 160 },
        { title: '使用科别', key: 'departmentName', width: 160 },
        {
          title: '购买日期',
          key: 'buyDate',
          width: 160,
          date: true
        },
        {
          title: '有效日期',
          key: 'effectDate',
          width: 160,
          date: true
        },
        {
          title: '维保项目名称',
          key: 'projectName',
          width: 160
        },
        {
          title: '维保内容',
          key: 'maintainContent',
          width: 160
        },
        { title: '备注', key: 'remark', width: 160 }
      ],
      getPage: {},
      getObj: {}
    }
  },

  mounted() {
    this.id = this.$route.query.id
    this._page()
    this._maintain()
    this._getEquipFileList()
  },
  methods: {
    _page: async function() {
      const obj = Object.assign(
        { maintainId: this.id },
        this.$refs.pageTable._searchParams()
      )
      const result = await equipMaintainDetail.page(obj)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
      }
    },
    _maintain: async function() {
      this.getObj = await equipMaintain.getById(this.id)
    },
    _approve() {
      this.$Modal.confirm({
        title: '提示',
        content: '确认？',
        onOk: () => {
          const data = {}
          data.id = $('#flowFrame', parent.document).attr('data-tid')
          data.status = 'success'
          this._approveOk(data)
        }
      })
    },
    _approveOk: async function(data) {
      const result = await equipMaintain.approve(data)
      if (result) {
        this.$Message.success('审批成功！')
        setTimeout(() => {
          parent.location.replace(global.webURL + '/sys/workflow/flow_task')
        }, 200)
      }
    },
    _getEquipFileList: async function() {
      this.lmsEquipFiles = await equipFile.getFileList({ relId: this.id })
    },
    _downloadFile(file) {
      // 下载文件
      this.$Modal.confirm({
        title: '提示',
        content: '确定要下载？',
        onOk: () => {
          const url =
            global.baseURL + '/res/v1/equip_maintain/downLoadFile?id=' + file.id
          window.open(url)
        }
      })
    }
  }
}
</script>
