<template>
  <div class="storeTransferOutDetail-wrap">
    <a-page-header :ghost="false" :backIcon="false" class="storeTransferOutDetail-back" >
      <!-- 自定义的二级文字标题 -->
      <template slot="subTitle">
        <a id="storeTransferOutDetail-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
      </template>
      <!-- 操作区，位于 title 行的行尾 -->
      <template slot="extra">
        <a-button key="2" id="storeTransferOutDetail-preview-btn">打印预览</a-button>
        <a-button key="1" type="primary" id="storeTransferOutDetail-print-btn">快速打印</a-button>
      </template>
    </a-page-header>
    <a-card size="small" :bordered="false" class="storeTransferOutDetail-cont">
      <a-collapse :activeKey="['1']">
        <a-collapse-panel key="1" header="基础信息">
          <a-descriptions :column="3">
            <a-descriptions-item label="调往对象名称">{{ (basicInfoData&&basicInfoData.putPersonName) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="店内调出单号">{{ (basicInfoData&&basicInfoData.storeCallOutNo) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="业务状态">{{ (basicInfoData&&basicInfoData.stateDictValue) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="财务状态">{{ (basicInfoData&&basicInfoData.settleStateDictValue) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="调拨类型">{{ (basicInfoData&&basicInfoData.callOutTypeName) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="备注">{{ (basicInfoData&&basicInfoData.remarks) || '--' }}</a-descriptions-item>
          </a-descriptions>
        </a-collapse-panel>
      </a-collapse>
    </a-card>
    <a-card size="small" :bordered="false" class="storeTransferOutDetail-cont">
      <!-- 总计 -->
      <a-alert type="info" showIcon style="margin-bottom:15px">
        <div slot="message">总款数 <strong>{{ (productTotal&&productTotal.productTotalCategory) || 0 }}</strong> ，总数量 <strong>{{ (productTotal&&productTotal.productTotalQty) || 0 }}</strong> ，总成本￥<strong>{{ (productTotal&&productTotal.productTotalCost) || 0 }}</strong></div>
      </a-alert>
      <!-- 列表 -->
      <s-table
        class="sTable"
        ref="table"
        size="small"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data="loadData"
        :scroll="{ x: 995 }"
        bordered>
      </s-table>
    </a-card>
  </div>
</template>

<script>
import { STable, VSelect } from '@/components'
import { getOperationalPrecision } from '@/libs/tools.js'
import { storeCallOutDetailList, storeCallOutDetailCount, storeCallOutDetailSn } from '@/api/storeCallOut'
export default {
  components: { STable, VSelect },
  data () {
    return {
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center', fixed: 'left' },
        { title: '产品编码', dataIndex: 'productCode', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品名称', dataIndex: 'productName', align: 'center', ellipsis: true },
        { title: '单位', dataIndex: 'productUnit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '成本价(￥)', dataIndex: 'outCost', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '调出仓库', dataIndex: 'warehouseName', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '调出数量', dataIndex: 'outQty', width: 100, align: 'center' },
        { title: '成本小计(￥)', dataIndex: 'costSubtotal', width: 115, align: 'center' }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return storeCallOutDetailList(Object.assign(parameter, { storeCallOutSn: 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].costSubtotal = getOperationalPrecision(data.list[i].outCost, data.list[i].outQty)
          }
          return data
        })
      },
      basicInfoData: null, //  基本信息
      productTotal: null //  合计
    }
  },
  methods: {
    //  返回列表
    handleBack () {
      this.$router.push({ path: '/allocationManagement/storeTransferOut/list' })
    },
    // 基本信息
    getDetail () {
      storeCallOutDetailSn({ sn: this.$route.params.sn }).then(res => {
        if (res.status == 200) {
          this.basicInfoData = res.data
        } else {
          this.basicInfoData = null
        }
      })
    },
    // 合计
    getDetailCount () {
      storeCallOutDetailCount({ storeCallOutSn: this.$route.params.sn }).then(res => {
        if (res.status == 200) {
          this.productTotal = res.data
        } else {
          this.productTotal = null
        }
      })
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      vm.getDetail()
      vm.getDetailCount()
    })
  }
}
</script>

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