<template>
  <!-- 资金流水 -->
  <mtp-table-scroll>
    <template #default="{ scroll }">
      <a-table :columns="columns" class="srcollYTable" :scroll="scroll" :pagination="false" :loading="loading" :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :expandIcon="expandIcon" :expandIconAsCell="false" :rowKey="(record,index)=>index" :data-source="tableList">
        <!-- 额外的展开行 -->
        <template v-if="auth.length" #expandedRowRender="{ record }">
          <BtnList :btnList="auth" :record="record" class="btn-list-sticky" @click="openComponent" />
        </template>
        <template #createtime="{ record }">
          <a>{{ formatTime(record.createtime) }}</a>
        </template>
      </a-table>
    </template>
  </mtp-table-scroll>
  <component :is="componentId" v-if="componentId" :selectedRow="selectedRow" @cancel="closeComponent"></component>
</template>

<script lang="ts">
import { PropType, onBeforeUnmount } from 'vue';
import MtpTableScroll from '@/common/components/tableScroll/index.vue';
import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
import { queryTableList, BtnList, defineComponent } from '@/common/export/commonTable';
import { WrPerformancePlan } from '@/services/go/wrtrade/interface';
import { handleComposeOrderTable } from '@/common/setup/table/compose';
import { ComposeOrderTableParam } from '@/common/setup/table/interface';
import { queryAmountLog } from '@/services/go/TaAccount';
import { QueryAmountLogReq } from '@/services/go/TaAccount/interface';
import { getSelectedAccountId } from '@/services/bus/account';
import { formatTime } from '@/common/methods';
import Bus from '@/utils/eventBus/index';
import { DynamicComponent } from '@/@next/hooks/common/interface'
import { expandIcon } from '@/common/setup/table/clolumn';

export default defineComponent({
  name: enumOrderComponents.funding_information_funding_log,
  props: {
    parentComponent: {
      type: Object as PropType<DynamicComponent>,
      required: true
    }
  },
  components: {
    MtpTableScroll,
    BtnList,
  },
  setup(props) {
    const { auth } = props.parentComponent;
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<WrPerformancePlan>();
    // 获取列表数据
    const queryTableAction = () => {
      const param: QueryAmountLogReq = {
        accountID: getSelectedAccountId().toString(),
      };

      queryTable(queryAmountLog, param);
    }

    // 表格通用逻辑
    const param: ComposeOrderTableParam = {
      queryFn: queryTableAction,
      tableName: 'table_pcweb_spot_trade_bottom_funding_info_log',
    }

    // 资金变化，重新加载数据
    const stopNotify = Bus.$on('moneyChangedNtf', () => {
      queryTableAction();
    })

    onBeforeUnmount(() => {
      stopNotify();
    })

    return {
      ...handleComposeOrderTable<WrPerformancePlan>(param),
      loading,
      tableList,
      formatTime,
      expandIcon,
      auth
    }
  }
})
</script>