<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>{{ getOrder.num }}</td>
                  <th>申请人</th>
                  <td>{{ getOrder.applyer }}</td>
                </tr>
                <tr>
                  <th>申请原因</th>
                  <td>{{ getOrder.reason }}</td>
                  <th>申请时间</th>
                  <td>{{ this.$dateformat(getOrder.ctime, "yyyy-mm-dd HH:MM") }}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </Alert>
      </div>
      <!--内容-->
      <div>
        <element-table
          ref="pageTable"
          :table-height="300"
          :get-page="getPage"
          @on-result-change="_tableResultChange"
        >
          <el-table-column
            v-for="item in pageColumns"
            :key="item.key"
            show-overflow-tooltip
            sortable
            :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>
    </el-dialog>
  </div>
</template>
<script>
import { equipRelDelivery, equipDeliveryOrder } from '../../../../api'

export default {
  data() {
    return {
      id: {},
      showModal: false,
      pageColumns: [
        { title: '仪器编号', key: 'equipNum', width: 120 },
        { title: '仪器名称', key: 'equipName', width: 160 },
        { title: '使用人', key: 'applyName', width: 160 },
        {
          title: '使用开始时间',
          key: 'useStartTime',
          width: 180,
          datetime: true
        },
        {
          title: '使用结束时间',
          key: 'useEndTime',
          width: 180,
          datetime: true
        },
        { title: '开始性能', key: 'performanceStart', width: 120 },
        { title: '结束性能', key: 'performanceEnd', width: 120 },
        { title: '用途', key: 'uses', width: 160 },
        { title: '备注', key: 'remark', width: 210 },
        { title: '制造厂商', key: 'manufacturer', width: 200 },
        { title: '规格', key: 'spec', width: 200 }
      ],
      getPage: {},
      getOrder: {}
    }
  },
  methods: {
    _open(id) {
      this.showModal = true
      this.$nextTick(function() {
        this.id = id
        this._page()
        this._purchase()
      })
    },
    _page: async function() {
      const obj = Object.assign(
        { orderId: this.id },
        this.$refs.pageTable._searchParams()
      )
      const result = await equipRelDelivery.equipPageTemp(obj)
      if (result) {
        for (let i = 0; i < result.records.length; i++) {
          result.records[i].useStartTime = result.records[i].useStartTime
            ? new Date(result.records[i].useStartTime)
            : ''
          result.records[i].useEndTime = result.records[i].useEndTime
            ? new Date(result.records[i].useEndTime)
            : ''
        }
        this.getPage.records = result.records
        this.$refs.pageTable._initTable()
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
      }
    },
    _purchase: async function() {
      this.getOrder = await equipDeliveryOrder.getEquipOutById(this.id)
    }
  }
}
</script>
