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

// TODO 校验：应付账单表单
export default function useBillMainModel(tableData: BaseTableProps) {
    // XXX  自定义校验函数
    const validateCurrencyCode = (rule: Recordable, value: any, callback: any) => {
        if (!value) {
            return callback(new Error('请选择内容'))
        }
        if (tableData.dataSource.length > 1) {
            let index = 0
            for (const item of tableData.dataSource) {
                if (item.currencyCode === value) {
                    index++
                }
            }
            if (index > 1) {
                callback(new Error('选择的币种不能重复！'))
            } else {
                callback()
            }
        } else {
            callback()
        }
    }
    // 账单主体-表单校验
    const ruleBillMainForm = reactive({
        channelName: [{ required: true, message: "请输入内容", trigger: "blur" }],
        billDate: [{ required: true, message: "请输入内容", trigger: "blur" }],
        waybillNo: [{ required: true, message: "请输入内容", trigger: "blur" }],
        billFee: [{ required: true, message: "请输入内容", trigger: "blur" }],
        enterpriseDominantNameImport: [{ required: true, message: "请输入内容", trigger: "blur" }],
        shareFlag: [{ required: true, message: "请输入内容", trigger: "blur" }],
        currencyCode: [{ required: true, message: "请选择内容", trigger: "blur" }],
        rules: {
            billName: [{ required: true, message: "请输入名称", trigger: "blur" }],
            rateVersionId: [{ required: true, message: "请选择汇率版本", trigger: "blur" }],
        }
    })

    return {
        ruleBillMainForm
    }
}