<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>{{ getOrder.ctime?$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="450"
          :get-page="getPage"
          editable
          @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?item.width:200"
            :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 { chemicalRelPurchase, chemicalPurchaseOrder } from '../../../api'

export default {
  data() {
    return {
      getOrder: {},
      getPage: {},
      pageColumns: [
        { title: '耗材编号', key: 'chemicalNum', width: 160 },
        { title: '耗材名称', key: 'chemicalName', width: 160 },
        { title: '单价', key: 'price', width: 100 },
        { title: '采购数量', key: 'quantity', width: 100 },
        { title: '计量单位', key: 'unit', width: 100 },
        { title: '规格', key: 'spec', width: 100 },
        { title: '等级（纯度）', key: 'quality', width: 100 },
        { title: '供应商', key: 'supplier', width: 200 },
        { title: '制造厂商', key: 'manufacturer', width: 200 },
        { title: '备注', key: 'remark' }
      ],
      id: {},
      showModal: false
    }
  },
  methods: {
    _open(id) {
      this.showModal = true
      this.$nextTick(function() {
        this.id = id
        this._page()
        this._purchaseOrder(this.id)
      })
    },
    _handleRow(data) {
      this.currentRow = data.row
    },
    _page: async function() {
      const obj = Object.assign(
        { purchaseId: this.id },
        this.$refs.pageTable._searchParams()
      )
      const result = await chemicalRelPurchase.purchaseChemicalPage(
        this.$serializeForm(obj)
      )
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
      }
    },
    _purchaseOrder: async function(id) {
      this.getOrder = await chemicalPurchaseOrder.getById(id)
    },
    _cancel() {
      this.showModal = false
    }
  }
}
</script>
