<template>
  <div class="detail-container">
    <el-page-header @back="goBack" content="详情"></el-page-header>

    <div id="printData">
      <div class="main-title">
        <div class="title">采购订单</div>
      </div>

      <div class="diy-table-1">
        <el-row>
          <el-col :span="8" class="item">
            <div class="label">业务类型</div>
            <div class="value">{{ detailData.businessType }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">采购日期</div>
            <div class="value">{{ detailData.fdate | dateToDayFilter }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">订单编号</div>
            <div class="value">{{ detailData.billNo }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">采购类型</div>
            <div class="value">{{ detailData.businessType | businessTypeFilter }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">供应商</div>
            <div class="value">{{ detailData.assignSupplierId }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">部门</div>
            <div class="value">{{ detailData.purchaseDeptId }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">业务员</div>
            <div class="value">{{ detailData.purchaserId }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">税率</div>
            <div class="value">{{ detailData.billTaxAmount }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">付款条件</div>
            <div class="value">{{ detailData.payConditionId }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">币种</div>
            <div class="value">{{ detailData.settleCurr }}</div>
          </el-col>
          <el-col :span="16" class="item">
            <div class="label">备注</div>
            <div class="value">{{ detailData.abcdRemarks }}</div>
          </el-col>
        </el-row>
      </div>

      <div class="table" style="margin-top: 20px; margin-bottom: 20px">
        <el-table
          :data="detailData.kingDeePurchaseOrderItems"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
          stripe
          max-height="400"
        >
          <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
          <el-table-column
            align="center"
            label="存货编号"
            prop="materialNumber"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="存货名称"
            prop="materialName"
            min-width="180"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="规格型号"
            prop="model"
            min-width="120"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="主计量单位"
            prop="unit"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="数量"
            prop="qty"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="原币含税单价"
            prop="taxPrice"
            min-width="120"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="原币单价"
            prop="price"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="原币税额"
            prop="entryTaxAmount"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="原币价税合计"
            prop="billAllAmount"
            min-width="120"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="采购单价"
            prop="price"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
        </el-table>
      </div>

      <div class="diy-table-1">
        <el-row>
          <el-col :span="8" class="item">
            <div class="label">制单人</div>
            <div class="value">{{ detailData.createBy }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">审核人</div>
            <div class="value">{{ detailData.approverName }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">变更人</div>
            <div class="value">{{ detailData.changerName }}</div>
          </el-col>
        </el-row>
      </div>
    </div>

    <div class="page-footer">
      <div class="footer" :class="classObj">
        <el-button type="primary" icon="el-icon-printer" v-print="printObj">打 印</el-button>
        <el-popconfirm title="确定关闭吗？" @onConfirm="goBack" style="margin-left: 10px">
          <el-button slot="reference">关 闭</el-button>
        </el-popconfirm>
      </div>
    </div>
  </div>
</template>

<script>
import print from 'vue-print-nb'
import { getPurchaseDetail } from '@/api/supply/purchase'

export default {
  name: 'PurchaseDetail',
  componentName: 'PurchaseDetail',
  props: ['listItem'],
  directives: {
    print
  },
  filters: {
    businessTypeFilter(val) {
      const MAP = {
        CG: '标准采购'
      }
      return MAP[val]
    }
  },
  data() {
    return {
      printObj: {
        id: 'printData'
      },
      detailData: {}
    }
  },

  computed: {
    sidebar() {
      return this.$store.state.app.sidebar
    },
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened
      }
    }
  },

  created() {
    this.getDetail()
  },

  methods: {
    // 返回列表
    goBack() {
      this.$emit('close')
    },

    // 获取详情
    getDetail() {
      getPurchaseDetail({ id: this.listItem.id }).then(res => {
        this.detailData = res.data
      })
    }
  }
}
</script>

<style scoped lang="scss">
.detail-container {
  width: 100%;
  height: 100%;
}
.main-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 30px;
  height: 60px;
  border-bottom: 1px solid #dcdfe6;
  margin-bottom: 20px;
  .title {
    font-size: 16px;
    font-weight: 600;
    padding-left: 10px;
  }
}
</style>
