import { ref, reactive } from 'vue';
import { BaseTableProps } from '@/components/Table/src/types';

// TODO 应付账单-表格数据
export default function useBillMainTable() {
    const tableActionWidth = ref(90)

    // 报表汇率-table列表数据
    const billMainTableList: BaseTableProps = reactive({
        border: true,
        rowKey: "id",
        columns: [
            {
                prop: "billName",
                label: "账单名称",
                showOverflowTooltip: true,
            },
            {
                prop: "billDate",
                label: "账单日期",
                slot: true,
                slotName: "billDate",
                showOverflowTooltip: true,
            },
            {
                prop: "uploadFileName",
                label: "上传文件名称",
                showOverflowTooltip: true,
            },
            {
                prop: "rateVersionId",
                label: "汇率版本",
                width: 120,
                slot: true,
                slotName: "rateVersionId"
            },
            {
                prop: "stateFlagName",
                label: "状态",
                width: 100,
            },
            {
                prop: "updateUserName",
                label: "操作人员",
                width: 120,
                showOverflowTooltip: true,
            },
            {
                prop: "createTime",
                label: "操作时间",
                width: 180,
                showOverflowTooltip: true,
            },
            {
                prop: "action",
                label: "操作",
                width: 160,
                slot: true,
                slotName: 'action'
            },
        ],
        dataSource: [],//数据
    });
    // 动态表格表单
    const addEditBillMainTable: BaseTableProps = reactive({
        border: true,
        height: 437,
        maxHeight: 437,
        columns: [
            {
                prop: "channelName",
                label: "渠道商名称",
                slot: true,
                showOverflowTooltip: true,
                slotName: 'channelName'
            },
            {
                prop: "billDate",
                label: "账单日期",
                slot: true,
                slotName: 'billDate'
            },
            {
                prop: "waybillNo",
                label: "运单号/提单号",
                slot: true,
                slotName: 'waybillNo'
            },
            {
                prop: "billFee",
                label: "原金额",
                slot: true,
                slotName: 'billFee'
            },
            {
                prop: "enterpriseDominantNameImport",
                label: "所属主体",
                slot: true,
                showOverflowTooltip: true,
                slotName: 'enterpriseDominantNameImport'
            },
            {
                prop: "shareFlag",
                label: "是否均摊",
                slot: true,
                width: 100,
                slotName: 'shareFlag'
            },
            {
                prop: "currencyCode",
                label: "币种",
                width: 90,
                slot: true,
                slotName: 'currencyCode'
            },
            {
                prop: "action",
                label: "操作",
                align: "center",
                width: 120,
                slot: true,
                slotName: 'action',
                // slotHeader: true
            },
        ],
        dataSource: []
    })

    // 查看明细
    const viewBillTable: BaseTableProps = reactive({
        border: true,
        height: 438,
        maxHeight: 438,
        rowSelection: false,
        columns: [
            {
                prop: "channelName",
                label: "渠道商名称",
                showOverflowTooltip: true,
                // slot: true,
                slotName: 'channelName'
            },
            {
                prop: "billDate",
                label: "账单日期",
                width: 110,
                slot: true,
                slotName: 'billDate'
            },
            {
                prop: "waybillNo",
                label: "运单号/提单号",
                // slot: true,
                slotName: 'waybillNo'
            },
            {
                prop: "billFee",
                label: "原金额",
                width: 110,
                showOverflowTooltip: true,
                // slot: true,
                slotName: 'billFee'
            },
            {
                prop: "enterpriseDominantNameImport",
                label: "所属主体(原)",
                showOverflowTooltip: true,
                // slot: true,
                slotName: 'enterpriseDominantNameImport'
            },
            {
                prop: "currencyCode",
                label: "币种",
                width: 90,
                showOverflowTooltip: true,
                // slot: true,
                slotName: 'currencyCode'
            },
            {
                prop: "enterpriseDominantName",
                label: "所属主体(系)",
                showOverflowTooltip: true,
                // slot: true,
                slotName: 'enterpriseDominantName'
            },
            {
                prop: "shareFee",
                label: "金额(分)",
                width: 110,
                showOverflowTooltip: true,
                // slot: true,
                slotName: 'shareFee'
            },
            {
                prop: "sharedResult",
                label: "分摊结果",
            },
            // {
            //     prop: "action",
            //     label: "操作",
            //     align: "center",
            //     width: 60,
            //     slot: true,
            //     slotName: 'action',
            //     slotHeader: true
            // },
        ],
        dataSource: [
            { channelName: '测试2' }
        ]
    })

    // 查看账单主体
    const viewBillMain: BaseTableProps = reactive({
        border: true,
        height: 438,
        maxHeight: 438,
        rowSelection: false,
        loading: true,
        columns: [
            {
                prop: "number",
                label: "序号",
                width: 80,
            },
            {
                prop: "billDateStr",
                label: "月份",
            },
            {
                prop: "channelName",
                label: "渠道商",
            },
            {
                prop: "orderCount",
                label: "票数",
            },
            {
                prop: "shareFee",
                label: "金额",
            },
            {
                prop: "enterpriseDominantName",
                label: "所属主体(系)",
            },
        ],
        dataSource: []
    })

    // 查看汇率表格
    const viewBillRateTable: BaseTableProps = reactive({
        border: true,
        // height: 238,
        maxHeight: 238,
        columns: [
            {
                prop: "currencyCode",
                label: "币种",
            },
            {
                prop: "currencyRate",
                label: "汇率",
            }
        ],
        dataSource: []
    })

    // XXX 动态设置elemnet-table 操作栏宽度
    // onBeforeMount(() => {
    //     if (storeUser) {
    //         const permissions = storeUser.getPermissions
    //         // 过滤用户按钮
    //         const permissionsButton = permissions.filter((item) => item.includes('sys:BillMain:'))
    //         const columnsLength = billMainTableList.columns.length
    //         tableActionWidth.value = (permissionsButton.length - 2) * 80
    //         // 动态加操作栏的宽度
    //         billMainTableList.columns[columnsLength - 1].width = tableActionWidth.value
    //     }
    // })

    return {
        billMainTableList,
        addEditBillMainTable,
        viewBillTable,
        viewBillMain,
        viewBillRateTable
    }
}