<template>
  <!-- 采购: 全部-->
  <div class="purchase-all"
       :loading="loading">
    <filterCustomTable @search="updateColumn">
      <BtnList :btnList="firstBtn"
               @click="openComponent" />
    </filterCustomTable>
    <a-table :columns="columns"
             class="srcollYTable"
             :scroll="{ x: '100%', y: 'calc(100vh - 163px)' }"
             :pagination="false"
             :loading="loading"
             :expandedRowKeys="expandedRowKeys"
             :customRow="Rowclick"
             rowKey="key"
             :data-source="tableList">
      <!-- 额外的展开行 -->
      <template #expandedRowRender="{ record }">
        <BtnList :btnList="secondBtn"
                 :record="record"
                 @click="openComponent" />
      </template>
    </a-table>
    <!-- 右键 -->
    <contextMenu :contextMenu="contextMenu"
                 @cancel="closeContext"
                 :list="secondBtn">
    </contextMenu>
    <component :is="componentId"
               v-if="componentId"
               :selectedRow="selectedRow"
               @cancel="closeComponent"></component>
  </div>
</template>

<script lang="ts">
import { queryTableList, BtnList, contextMenu, defineAsyncComponent, defineComponent, ModalEnum, handleComposeTable, ComposeTableParam } from '@/common/export/commonTable';

import { Ermcp3SellBuyContract } from '../index';
import { filterCustomTable } from '../../components';
import { QueryPurchase } from '@/services/go/ermcp/purchase';
import { EnumRouterName } from '@/common/constants/enumRouterName';

const Detail = defineAsyncComponent(() => import('../../components/detail/index.vue'));
const Settlement = defineAsyncComponent(() => import('../../components/settlement/index.vue')); //交收登记
const Funds = defineAsyncComponent(() => import('../../components/funds/index.vue')); // 款项登记
const Invoice = defineAsyncComponent(() => import('../../components/invoice/index.vue')); // 发票登记
const Storage = defineAsyncComponent(() => import('../../components/storage/index.vue')); // 入库登记
const SomePrice = defineAsyncComponent(() => import('../../components/someprice/index.vue')); //采购点价登记

export default defineComponent({
    name: EnumRouterName.purchase_all,
    components: {
        contextMenu,
        filterCustomTable,
        Detail,
        BtnList,
        [ModalEnum.detail]: Detail,
        [ModalEnum.purchase_pending_settlement]: Settlement,
        [ModalEnum.purchase_pending_funds]: Funds,
        [ModalEnum.purchase_pending_invoice]: Invoice,
        [ModalEnum.purchase_pending_storage]: Storage,
        [ModalEnum.purchase_pending_someprice]: SomePrice,
    },
    setup() {
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList<Ermcp3SellBuyContract>();
        // 获取列表数据
        const queryTableAction = () => queryTable(QueryPurchase, { querytype: 1 });
        // 表格通用逻辑
        const param: ComposeTableParam = {
            queryFn: queryTableAction,
            menuType: EnumRouterName.purchase_all,
            tableName: 'table_pcweb_purchase_all',
            tableFilterKey: ['accountname', 'contractno', 'deliverygoodsname', 'convertfactor', 'goodsname'],
            isDetail: true,
        };
        return {
            ...handleComposeTable<Ermcp3SellBuyContract>(param),
            tableList,
            loading,
        };
    },
});
</script>

<style lang="less">
.purchase-history {
}
</style
>;
