
import { ref, reactive, watchEffect, onUnmounted } from 'vue';
import { BasicTableProps, VxeBasicTable, VxeGridInstance } from '@/components/VxeTable/index';
import useResizeHeight from '@/hooks/useResizeHeight';

/**
 * 客户总账-费用明细数据
 */
function userMoneySumDetailSource(minusNum = 30) {
    // vxe-table ref
    const tableRef = ref<VxeGridInstance>();
    // 表格自适应屏幕高度 
    const { tableHeight } = useResizeHeight()
    // 基础数据
    const usermoneyGridOptions = reactive<BasicTableProps>({
        id: 'usermoney_detail_table',
        border: true,
        keepSource: true,
        showOverflow: true,
        height: 520,
        loading: false,
        columnConfig: {
            resizable: true
        },
        customConfig: {
            storage: {
                visible: true,
            }
        },
        toolbarConfig: {
            custom: true,
        },
        columns: [
            { field: 'customerName', title: '客户', minWidth: 180 },
            { field: 'salesmanName', title: '业务员', minWidth: 80 },
            { field: 'accountPeriodName', title: '账期类型', width: 80 },
            { field: 'createTime', title: '创建时间', width: 150 },
            { field: 'feeAmount', title: '金额', width: 110 },
            { field: 'orderId', title: '单号', width: 180 },
            { field: 'trackingNumber', title: '跟踪号', width: 160 },
            { field: 'transferNumber', title: '转单号', width: 130 },
            { field: 'productName', title: '产品名称', minWidth: 130 },
            { field: 'countryName', title: '国家/地区', minWidth: 120 },
            { field: 'orderPieces', title: '订单件数', width: 90 },
            { field: 'weight', title: '实际重量', width: 90 },
            { field: 'countFeeWeight', title: '计费重量', width: 90 },
            { field: 'volumeWeight', title: '体积重量', width: 90 },
            { field: 'currencyCode', title: '币种', width: 70 },
            { field: 'transactionNumber', title: '交易号', width: 120 },
            { field: 'bankAccount', title: '银行账号', width: 120 },
            { field: 'operatingTypeName', title: '操作类型', width: 95 },
            { field: 'customerTypeName', title: '费用类型', width: 95 },
            { field: 'feeTypeName', title: '数据类型', width: 95 },
            { field: 'orgName', title: '分公司', width: 95 },
            { field: 'packageTypeName', title: '包装类型', width: 95 },
            { field: 'formulaDescription', title: '计费公式', minWidth: 120 },
            { field: 'remark', title: '备注', minWidth: 120 },
            { field: 'createUserName', title: '创建人', width: 90 },
            { title: '操作', slots: { default: 'actions' }, width: 130, fixed: "right" },
        ],
        data: []
    })

    const stop = watchEffect(() => {
        if (tableHeight.value > 520) usermoneyGridOptions.height = tableHeight.value - minusNum
    }, { flush: "post" })

    onUnmounted(() => {
        stop()
    })

    return {
        tableRef,
        usermoneyGridOptions,
        VxeBasicTable
    }
}

export {
    userMoneySumDetailSource
}