<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="key" :data-source="tableList">
        <template #createtime="{ record }">
          <a>{{ formatTime(record.createtime) }}</a>
        </template>
      </a-table>
    </template>
  </mtp-table-scroll>
</template>

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

export default defineComponent({
  components: {
    MtpTableScroll
  },
  setup() {
    // 表格列表数据
    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',
      recordList: getRecordItemTab(),
    }

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

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

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