<template>
  <div class="companyCollectionPaymentDetail-wrap">
    <a-page-header :ghost="false" :backIcon="false" class="companyCollectionPaymentDetail-cont" >
      <!-- 自定义的二级文字标题 -->
      <template slot="subTitle">
        <a id="companyCollectionPaymentDetail-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.unitSettleNo) || '--' }}</p>
      </template>
      <!-- 操作区，位于 title 行的行尾 -->
      <template slot="extra">
        <a-button key="2" id="companyCollectionPaymentDetail-preview-btn">打印预览</a-button>
        <a-button key="1" type="primary" id="companyCollectionPaymentDetail-print-btn">快速打印</a-button>
      </template>
    </a-page-header>
    <!-- 基础信息 -->
    <a-card size="small" :bordered="false" class="companyCollectionPaymentDetail-cont">
      <a-collapse :activeKey="['1']">
        <a-collapse-panel key="1" header="基础信息">
          <a-descriptions :column="3">
            <a-descriptions-item label="单位名称">{{ (basicInfoData&&basicInfoData.settleClientName) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="单位类型">{{ (basicInfoData&&basicInfoData.settleClientTypeDictValue) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="结算类型">{{ (basicInfoData&&basicInfoData.settleTypeDictValue) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="应结算金额">{{ (basicInfoData&&basicInfoData.settleAmount) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="折让金额">{{ discountAmount || '--' }}</a-descriptions-item>
            <a-descriptions-item label="实结算金额">{{ (basicInfoData&&basicInfoData.realSettleAmount) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="结算时间">{{ (basicInfoData&&basicInfoData.createDate) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="操作人">{{ (basicInfoData&&basicInfoData.operateName) || '--' }}</a-descriptions-item>
            <a-descriptions-item label="结算方式">{{ (basicInfoData&&basicInfoData.settleStyleName) || '--' }}</a-descriptions-item>
          </a-descriptions>
        </a-collapse-panel>
      </a-collapse>
    </a-card>
    <!-- 收款明细 -->
    <a-card size="small" :bordered="false" class="companyCollectionPaymentDetail-cont">
      <a-collapse :activeKey="['1']">
        <a-collapse-panel key="1" header="收款明细">
          <!-- alert -->
          <a-alert type="info" showIcon style="margin-bottom:15px">
            <div slot="message">共 <strong>{{ total }}</strong> 条明细，金额合计 <strong>￥{{ (basicInfoData&&basicInfoData.totalAmount) || 0 }}</strong> ，结算金额合计 <strong>￥{{ (basicInfoData&&basicInfoData.realSettleAmount) || 0 }}</strong> </div>
          </a-alert>
          <!-- 列表 -->
          <s-table
            class="sTable"
            ref="table"
            size="default"
            :rowKey="(record) => record.id"
            :columns="columns"
            :data="loadData"
            bordered>
          </s-table>
        </a-collapse-panel>
      </a-collapse>
    </a-card>
  </div>
</template>

<script>
import { STable, VSelect } from '@/components'
import { settleUnitDetailList, settleUnitDetail } from '@/api/settle'
export default {
  components: { STable, VSelect },
  data () {
    return {
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', align: 'center' },
        { title: '单据号', dataIndex: 'bizNo', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '类型', dataIndex: 'bizTypeDictValue', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '金额', dataIndex: 'totalAmount', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '结算金额', dataIndex: 'settleAmount', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        return settleUnitDetailList(Object.assign(parameter, { unitSettleSn: 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
          }
          this.disabled = false
          this.total = data.list.length
          return data
        })
      },
      total: 0, //  总条数
      basicInfoData: null //  基本信息
    }
  },
  computed: {
    discountAmount () {
      let val = 0
      if (this.basicInfoData && this.basicInfoData.discountAmount) {
        val = Math.abs(this.basicInfoData.discountAmount)
      }
      return val
    }
  },
  methods: {
    //  返回列表
    handleBack () {
      this.$router.push({ path: '/financialManagement/companyCollectionPayment/list' })
    },
    // 详情
    getDetail () {
      settleUnitDetail({ id: this.$route.params.id }).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">
  .companyCollectionPaymentDetail-cont{
    margin-bottom: 15px;
  }
</style>
