<template>
  <!-- 采购: 待点价-->
  <div class="purchase-peddding"
       :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"
                 class="btn-list-sticky"
                 @click="openComponent" />

      </template>
      <template #pricedqty="{ text, record }">
        <span>{{ handleEnumdic(text, record) }}</span>
      </template>
      <template #unsureqty="{ text, record }">
        <span>{{ handleEnumdic(text, record) }}</span>
      </template>
      <template #qty="{ text, record }">
        <span>{{ handleEnumdic(text, record) }}</span>
      </template>
      <template #unpricedqty="{ text, record }">
        <span>{{ handleEnumdic(text, record) }}</span>
      </template>
        <template #unpayamount="{ text, record }">
            <span>{{ record.unpayamount.toFixed(2) }}</span>
        </template>
        <template #daikaiamount="{ text, record }">
            <span>{{ record.daikaiamount.toFixed(2) }}</span>
        </template>



        <template #deliverystartdate,deliveryenddate="{ record }">
            <span>{{ formatValue(formatTime(record.deliverystartdate, "d") + '--' +
                        formatTime(record.deliveryenddate, "d"))  }}</span>
        </template>
        <template #startdate,enddate="{ record }">
            <span>{{ formatValue(formatTime(record.startdate, "d") + '--' +
                        formatTime(record.enddate, "d"))  }}</span>
        </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';
import { handleEnumdic } from '../setup';
import {formatTime, formatValue} from "@/common/methods";

const Detail = defineAsyncComponent(() => import('../../components/detail/index.vue'));
const SomePrice = defineAsyncComponent(() => import('../../components/someprice/index.vue')); //采购点价登记

export default defineComponent({
    name: EnumRouterName.purchase_pending,
    components: {
        contextMenu,
        filterCustomTable,
        BtnList,
        [ModalEnum.detail]: Detail,
        [ModalEnum.purchase_pending_someprice]: SomePrice,
    },
    setup() {
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList<Ermcp3SellBuyContract>();
        // 获取列表数据
        const queryTableAction = () => queryTable(QueryPurchase, { querytype: 2 });
        // 表格通用逻辑
        const param: ComposeTableParam = {
            queryFn: queryTableAction,
            menuType: EnumRouterName.purchase_pending,
            tableName: 'table_pcweb_purchase_pointprice',
            tableFilterKey: ['accountname', 'contractno', 'deliverygoodsname', 'convertfactor', 'goodsname'],
            isDetail: true,
        };

        return {
            ...handleComposeTable<Ermcp3SellBuyContract>(param),
            tableList,
            loading,
            handleEnumdic,
            formatTime,
            formatValue
        };
    },
});
</script>

<style lang="less">
.spot-contract-peddding {
}
</style
>;
