<template>
  <div class="warehousingAuditDetail-wrap">
    <a-page-header :ghost="false" :backIcon="false" class="warehousingAuditDetail-cont" >
      <!-- 自定义的二级文字标题 -->
      <template slot="subTitle">
        <a id="warehousingAuditDetail-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
        <p style=" display: inline-block;margin: 0 0 0 60px;color: #000;font-size: 16px;font-weight: 600;">单号：{{ (basicInfoData&&basicInfoData.receivingBillNo) || '--' }}</p>
      </template>
      <!-- 操作区，位于 title 行的行尾 -->
      <template slot="extra">
        <a-button key="2" id="warehousingAuditDetail-preview-btn">打印预览</a-button>
        <a-button key="1" type="primary" id="warehousingAuditDetail-print-btn">快速打印</a-button>
      </template>
    </a-page-header>
    <!-- 基础信息 -->
    <a-card size="small" :bordered="false" class="warehousingAuditDetail-cont">
      <a-collapse :activeKey="['1']">
        <a-collapse-panel key="1" header="基础信息">
          <a-descriptions :column="3">
            <a-descriptions-item label="供应商">{{ basicInfoData&&basicInfoData.dealerName ? basicInfoData.dealerName : '--' }}</a-descriptions-item>
            <a-descriptions-item label="入库时间">{{ basicInfoData&&basicInfoData.stockPutTime ? basicInfoData.stockPutTime : '--' }}</a-descriptions-item>
            <a-descriptions-item label="采购单号">{{ basicInfoData&&basicInfoData.purchaseBillNo ? basicInfoData.purchaseBillNo : '--' }}</a-descriptions-item>
          </a-descriptions>
          <a-descriptions :column="3" bordered>
            <a-descriptions-item label="采购总款数">{{ (basicInfoData&&basicInfoData.totalCategory!=0) ? basicInfoData.totalCategory : 0 }}</a-descriptions-item>
            <a-descriptions-item label="采购总数量">{{ (basicInfoData&&basicInfoData.totalQty!=0) ? basicInfoData.totalQty : 0 }}</a-descriptions-item>
            <a-descriptions-item label="采购总成本">￥{{ (basicInfoData&&basicInfoData.totalAmount!=0) ? basicInfoData.totalAmount : 0 }}</a-descriptions-item>
            <a-descriptions-item label="入库总款数">{{ (basicInfoData&&basicInfoData.totalQty!=0) ? basicInfoData.totalQty : 0 }}</a-descriptions-item>
            <a-descriptions-item label="入库总数量">{{ (basicInfoData&&basicInfoData.totalQty!=0) ? basicInfoData.totalQty : 0 }}</a-descriptions-item>
            <a-descriptions-item label="入库总成本">￥{{ (basicInfoData&&basicInfoData.totalPutAmount!=0) ? basicInfoData.totalPutAmount : 0 }}</a-descriptions-item>
          </a-descriptions>
        </a-collapse-panel>
      </a-collapse>
    </a-card>
    <!-- 入库明细 -->
    <a-card size="small" :bordered="false" class="warehousingAuditDetail-cont">
      <a-collapse :activeKey="['1']">
        <a-collapse-panel key="1" header="入库明细">
          <!-- 列表 -->
          <s-table
            class="sTable"
            ref="table"
            size="small"
            :rowKey="(record) => record.id"
            :columns="columns"
            :data="loadData"
            :scroll="{ x: 1520 }"
            bordered>
          </s-table>
        </a-collapse-panel>
      </a-collapse>
    </a-card>
  </div>
</template>

<script>
import { getOperationalPrecision } from '@/libs/tools.js'
import { STable, VSelect } from '@/components'
import { receivingDetailList, receivingDetailSn } from '@/api/receiving'
export default {
  components: { STable, VSelect },
  data () {
    return {
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center', fixed: 'left' },
        { title: '产品编码', dataIndex: 'dealerProductEntity.code', width: 220, align: 'center' },
        { title: '产品名称', dataIndex: 'dealerProductEntity.name', align: 'center', ellipsis: true },
        { title: '原厂编码', dataIndex: 'dealerProductEntity.origCode', width: 220, align: 'center' },
        { title: '采购数量', dataIndex: 'qty', width: 110, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '入库数量', dataIndex: 'putQty', width: 110, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '成本价', dataIndex: 'totalAmount', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '单位', dataIndex: 'dealerProductEntity.unit', width: 100, align: 'center' },
        { title: '入库小计', dataIndex: 'totalAmount', width: 100, align: 'center' },
        { title: '仓库', dataIndex: 'warehouseName', width: 140, align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '仓位', dataIndex: 'warehouseLocationName', width: 140, align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        return receivingDetailList(Object.assign(parameter, { receivingBillSn: this.$route.params.sn })).then(res => {
          const data = res.data
          const no = (data.pageNo - 1) * data.pageSize
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = no + i + 1
            // 入库小计  由于数据库内小数位数为4位，页面则需显示2位。因此会做小数运算精度处理
            data.list[i].warehousingSubtotal = getOperationalPrecision(data.list[i].price, data.list[i].qty)
          }
          this.disabled = false
          return data
        })
      },
      basicInfoData: null //  基本信息
    }
  },
  methods: {
    //  返回列表
    handleBack () {
      this.$router.push({ path: '/financialManagement/warehousingAudit/list' })
    },
    getDetail () {
      receivingDetailSn({ sn: this.$route.params.sn }).then(res => {
        if (res.status == 200) {
          this.basicInfoData = res.data
        } else {
          this.basicInfoData = null
        }
      })
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      vm.getDetail()
    })
  }
}
</script>

<style lang="less">
  .warehousingAuditDetail-cont{
    margin-bottom: 15px;
  }
</style>
