<template>
  <div class="companyCollectionPaymentDetail-wrap">
    <a-spin :spinning="spinning" tip="Loading...">
      <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>
      </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 || basicInfoData.settleAmount==0)) ? toThousands(basicInfoData.settleAmount) : '--' }}</a-descriptions-item>
              <a-descriptions-item label="折让金额">{{ (discountAmount || discountAmount==0) ? toThousands(discountAmount) : '--' }}</a-descriptions-item>
              <a-descriptions-item label="实结算金额">{{ (basicInfoData&&(basicInfoData.realSettleAmount || basicInfoData.realSettleAmount==0)) ? toThousands(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.settleStyleSnDictValue) || '--' }}</a-descriptions-item>
              <a-descriptions-item label="备注">{{ (basicInfoData&&basicInfoData.remark) || '--' }}</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" style="margin-bottom:10px">
              <div slot="message">
                共 <strong>{{ total }}</strong> 条明细，
                金额合计 <strong>{{ (basicInfoData&&(basicInfoData.totalSettleAmount || basicInfoData.totalSettleAmount==0)) ? toThousands(basicInfoData.totalSettleAmount) : '--' }}</strong> ，
                结算金额合计 <strong>{{ (basicInfoData&&(basicInfoData.realSettleAmount || basicInfoData.realSettleAmount==0)) ? toThousands(basicInfoData.realSettleAmount) : '--' }}</strong>
              </div>
            </a-alert>
            <!-- 列表 -->
            <s-table
              class="sTable"
              ref="table"
              size="small"
              :rowKey="(record) => record.id"
              :columns="columns"
              :data="loadData"
              :defaultLoadData="false"
              bordered>
            </s-table>
          </a-collapse-panel>
        </a-collapse>
      </a-card>
    </a-spin>
  </div>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { STable, VSelect } from '@/components'
import { settleUnitDetailList, settleUnitDetail } from '@/api/settle'
export default {
  name: 'CompanyCollectionPaymentDetail',
  components: { STable, VSelect },
  mixins: [commonMixin],
  data () {
    const _this = this
    return {
      spinning: false,
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', align: 'center', width: '10%' },
        { title: '单据号', dataIndex: 'bizNo', align: 'center', width: '25%', customRender: function (text) { return text || '--' } },
        { title: '类型', dataIndex: 'bizTypeDictValue', align: 'center', width: '25%', customRender: function (text) { return text || '--' } },
        { title: '金额', dataIndex: 'totalAmount', align: 'right', width: '20%', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
        { title: '结算金额', dataIndex: 'settleAmount', align: 'right', width: '20%', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        this.spinning = true
        return settleUnitDetailList(Object.assign(parameter, { unitSettleSn: this.$route.params.sn })).then(res => {
          let data
          if (res.status == 200) {
            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.count || 0
          }
          this.spinning = false
          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
        }
      })
    }
  },
  mounted () {
    if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
      this.$refs.table.refresh(true)
      this.getDetail()
    }
  },
  activated () {
    // 如果是新页签打开或者进入新的子页（例：存在列表第2条数据编辑页页签时再打开第4条数据的编辑页），则重置当前页面
    if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
      this.$refs.table.refresh(true)
      this.getDetail()
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {})
  }
}
</script>

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