<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 #expandedRowRender="{ record }">
          <BtnList :btnList="handleBtnList(buttons, record)" :record="record" class="btn-list-sticky" @click="openComponent" />
        </template>
        <!-- applytype 类型-->
        <template #applytype="{ record }">
          <span>{{ getPickUpStatusName(record.applytype) }}</span>
        </template>
        <template #expresscompany="{ record, text }">
          <span>{{ (text && text !== '--') ? text + record.expressnum : '--' }}</span>
        </template>
        <!-- applystatus 状态 -->
        <template #applystatus="{ record }">
          <span>{{ getPickUpTypeName(record.applystatus) }}</span>
        </template>
      </a-table>
    </template>
  </mtp-table-scroll>
  <component :is="componentId" v-if="componentId" :selectedRow="selectedRow" @cancel="closeComponent"></component>
</template>

<script lang="ts">
import { PropType } from 'vue';
import { queryTableList, BtnList, defineAsyncComponent, defineComponent, ModalEnum } from '@/common/export/commonTable';
import { queryWrOutInApply } from '@/services/go/wrtrade';
import { WrOutInApply } from '@/services/go/wrtrade/interface';
import { handleComposeOrderTable } from '@/common/setup/table/compose';
import { ComposeOrderTableParam } from '@/common/setup/table/interface';
import { expandIcon } from '@/common/setup/table/clolumn';
import { BtnListType } from '@/common/components/btnList/interface';
import { getPickUpStatusName, getPickUpTypeName } from '@/common/constants/enumsName';
import MtpTableScroll from '@/common/components/tableScroll/index.vue';
import { DynamicComponent } from '@/@next/hooks/common/interface'

export default defineComponent({
  props: {
    parentComponent: {
      type: Object as PropType<DynamicComponent>,
      required: true
    }
  },
  components: {
    BtnList,
    MtpTableScroll,
    confirm: defineAsyncComponent(() => import('./components/pick_up/index.vue')), // 确认提货
    cacel: defineAsyncComponent(() => import('./components/cancel/index.vue')), // 撤销
  },
  setup(props) {
    const { buttons } = props.parentComponent;
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<WrOutInApply>();

    // 获取列表数据
    const queryTableAction = () => {
      queryTable(queryWrOutInApply);
    };

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

    function handleBtnList(btnList: BtnListType[], item: WrOutInApply) {
      const { applystatus, applytype } = item;
      if (applystatus === 0 && applytype === 4) {
        return btnList.filter((e) => e.code === ModalEnum.spot_warrant_in_and_out_warehouse_sure_pick_up);
      } else if (applystatus === 1 && applytype === 2) {
        return btnList.filter((e) => e.code === ModalEnum.spot_warrant_in_and_out_warehouse_revoke);
      } else {
        return [];
      }
    }

    return {
      ...handleComposeOrderTable<WrOutInApply>(param),
      loading,
      tableList,
      buttons,
      expandIcon,
      handleBtnList,
      getPickUpStatusName,
      getPickUpTypeName,
    }
  }
})
</script>
