<template>
  <div>
    <el-dialog
      :visible.sync="showModal"
      title="流程详情"
      fullscreen
      top="0"
    >
      <!-- 执行顺序 -->
      <Alert class="equip_alert">
        <div>
          <table class="tableClass">
            <tbody>
              <tr>
                <th colspan="6" style="text-align: center;font-size: 15px">
                  耗材使用申请单
                </th>
              </tr>
              <tr>
                <th>编号</th>
                <td>{{ getOrder.num }}</td>
                <th>申请人</th>
                <td>{{ getOrder.applyer }}</td>
                <th>申请时间</th>
                <td>{{ this.$dateformat(getOrder.ctime, 'yyyy-mm-dd HH:MM') }}</td>
              </tr>
              <tr>
                <th>申请原因</th>
                <td colspan="5">
                  {{ getOrder.remark }}
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </Alert>
      <!--内容-->
      <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>
                {{ scope.row[item.key] }}
              </div>
            </template>
          </el-table-column>
        </element-table>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { chemicalRelDelivery, chemicalDeliveryOrder } from '../../../api'

export default {
  data() {
    return {
      id: '',
      pageColumns: [
        { title: '耗材编号', key: 'chemicalNum', width: 160 },
        { title: '耗材名称', key: 'chemicalName', width: 160 },
        { title: '出库数量', key: 'quantity', width: 100 },
        { title: '库存量', key: 'stock', width: 100 },
        { title: '计量单位', key: 'unit', width: 100 },
        { title: '规格', key: 'spec', width: 100 },
        { title: '有效期', key: 'validDate', width: 140, date: true },
        { title: '生产批次', key: 'batchNum', width: 120 },
        { title: '商品编码', key: 'productCode', width: 200 },
        { title: '制造厂商', key: 'manufacturer', width: 200 },
        { title: '备注', key: 'remark', width: 200 }
      ],
      showModal: false,
      getPage: {},
      getOrder: {}
    }
  },
  methods: {
    _open(id) {
      this.showModal = true
      this.$nextTick(function() {
        this.id = id
        this._page()
        this._deliveryOrder()
      })
    },
    _page: async function() {
      const obj = Object.assign(
        { orderId: this.id },
        this.$refs.pageTable._searchParams()
      )
      const result = await chemicalRelDelivery.pageApprove(
        this.$serializeForm(obj)
      )
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
      }
    },
    _deliveryOrder: async function() {
      const result = await chemicalDeliveryOrder.getById(this.id)
      if (result) {
        this.getOrder = result
      }
    },
    _cancel() {
      this.showModal = false
    }
  }
}
</script>
