<template>
  <!-- 管理-业务审核-点价 -->
  <div class="business-review-dj"
       :loading="loading">
    <Filter @search="updateColumn">
    </Filter>
    <a-table :columns="columns"
             class="srcollYTable"
             :scroll="{ x: '100%', y: 'calc(100vh - 163px)' }"
             :pagination="false"
             :expandedRowKeys="expandedRowKeys"
             :customRow="Rowclick"
             rowKey="key"
             :data-source="tableList">
      <!-- 额外的展开行 -->
      <template #expandedRowRender="{ record }">
        <BtnList :btnList="handlePermissionBtn(firstBtn, record)"
                 :record="record"
                 class="btn-list-sticky"
                 @click="openComponent" />
      </template>

      <template #pricetype="{ text }">
        <a>{{ getPriceTypeName(text) }}</a>
      </template>

      <template #applystatus="{ text }">
        <a>{{ getApplyStatusName(text) }}</a>
      </template>

      <template #contracttype="{ text }">
        <a>{{ getContractTypeName(text) }}</a>
      </template>

      <template #contractstatus="{ text }">
        <a>{{ getContractStatusName(text) }}</a>
      </template>

      <template #buyusernameOrsellusername="{ record }">
        <a>{{ getAnalogueName(record.contracttype, record.buyusername, record.sellusername) }}</a>
      </template>
    </a-table>
    <!-- 右键 -->
    <contextMenu :contextMenu="contextMenu"
                 @cancel="closeContext"
                 :list="handlePermissionBtn(firstBtn, selectedRow)">
    </contextMenu>
    <component :is="componentId"
               v-if="componentId"
               :selectedRow="selectedRow"
               @cancel="closeComponent"></component>
  </div>
</template>

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

import { Filter, SomepriceDetail, SomepriceAudit, SomepriceCancel } from '../../components';
import { queryTableList, QryBusinessDjRsp } from './setup';
import { getPriceTypeName, getContractStatusName, getContractTypeName, getApplyStatusName } from '@/common/constants/enumsName';
import { getAnalogueName } from '@/views/information/spot-contract/setup';
import { Column, ColumnType } from '@/common/setup/table';
import { ref } from 'vue';
import { BtnListType } from '@/common/components/btnList/interface';
import { EnumRouterName } from '@/common/constants/enumRouterName';
const Detail = defineAsyncComponent(() => import('../../components/somepriceDetail/index.vue'));
const Audit = defineAsyncComponent(() => import('../../components/somepriceAudit/index.vue'));
const Cancel = defineAsyncComponent(() => import('../../components/somepriceCancel/index.vue'));
export default defineComponent({
    name: 'business-review-dj',
    components: {
        contextMenu,
        Filter,
        BtnList,
        [ModalEnum.detail]: Detail,
        [ModalEnum.business_review_someprice_audit]: Audit,
        [ModalEnum.business_review_someprice_cancel]: Cancel,
    },
    setup() {
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList({});
        // 获取列表数据
        const queryTableAction = () => queryTable();
        const filtrFn = (e: Column, item: ColumnType, filtered: any) => {
            if (e.columnfield === 'buyusernameOrsellusername') {
                item.onFilter = (value: string, record: QryBusinessDjRsp) => {
                    const { contracttype, buyusername, sellusername } = record;
                    if (contracttype === 1) {
                        // 采购
                        return sellusername.includes(value);
                    } else {
                        return buyusername.includes(value);
                    }
                };
                item.filteredValue = filtered.buyusernameOrsellusername || null;
            }
        };
        // 表格通用逻辑
        const param: ComposeTableParam = {
            queryFn: queryTableAction,
            menuType: EnumRouterName.business_review_someprice,
            tableName: 'table_pcweb_business_aduit_dj',
            tableFilterKey: ['contracttype', 'contractno', 'deliverygoodsname'],
            tableFilterCB: filtrFn,
            isDetail: true,
        };
        function handlePermissionBtn(btnList: BtnListType[], item: QryBusinessDjRsp) {
            if (item) {
                const { applystatus } = item;
                if (applystatus === 1) {
                    return btnList;
                } else {
                    return btnList.filter((e) => e.code === 'detail');
                }
            } else {
                return [];
            }
        }

        return {
            ...handleComposeTable<QryBusinessDjRsp>(param),
            handlePermissionBtn,
            loading,
            tableList,
            getPriceTypeName,
            getApplyStatusName,
            getContractTypeName,
            getContractStatusName,
            getAnalogueName,
        };
    },
});
</script>

<style lang="less">
.business-review-dj {
}
</style>;

