<template>
  <a-drawer
    v-model:visible="vdata.visible"
    :title=" true ? '渠道账单详情' : '' "
    :body-style="{ paddingBottom: '80px' }"
    width="40%"
    @close="onClose"
  >
    <a-row justify="space-between" type="flex">
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="批次号">
            {{ vdata.detailData.batchNo }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="对账日期">
            {{ dateUtil.formatDate(vdata.detailData.billDate) }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="支付接口">
            {{ vdata.detailData.ifCode }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道商户号">
            {{ vdata.detailData.channelMchNo }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="账单类型">
            {{ vdata.detailData.billType === 'pay' ? '支付': '退款' }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道订单状态">
            {{ vdata.detailData.channelState === 2 ? '支付成功' : vdata.detailData.channelState === 5 ? '退款成功' : '未知' }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="平台订单号">
            {{ vdata.detailData.orderId }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道订单号">
            {{ vdata.detailData.channelOrderNo }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="交易金额">
            {{ (vdata.detailData.channelAmount/100).toFixed(2) }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道手续费">
            {{ (vdata.detailData.channelFeeAmount/100).toFixed(2) }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道交易成功时间">
            {{ vdata.detailData.channelSuccessAt }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :sm="12">
        <a-descriptions>
          <a-descriptions-item label="渠道用户标识">
            {{ vdata.detailData.channelUser }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col v-if="vdata.detailData.orgPayOrderId" :sm="12">
        <a-descriptions>
          <a-descriptions-item label="退款原支付订单号">
            {{ vdata.detailData.orgPayOrderId }}
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
    </a-row>
  </a-drawer>
</template>

<script lang="ts" setup>
import { API_URL_CHANNEL_BILL_LIST, req } from '@/api/manage'
import {reactive} from 'vue'
import dateUtil from '@/utils/dateUtil.js'

const vdata:any = reactive({
  btnLoading: false,
  detailData: {}, // 数据对象
  recordId: null, // 更新对象ID
  visible: false, // 是否显示弹层/抽屉
})

function show (recordId) { // 弹层打开事件
  
  vdata.recordId = recordId
  req.getById(API_URL_CHANNEL_BILL_LIST, recordId).then(res => {
    vdata.detailData = res
  })
  vdata.visible = true
}
function onClose () {
  vdata.visible = false
}

defineExpose({
  show //抛出show函数给父组件
})
</script>
