import { SubmitCurrencyRateModel } from "@/api/costdata/currencyrate/CurrencyRateModle";
import { BaseTableProps } from "@/components/Table/src/types";
import { reactive } from "vue";

export default function useBaseModel() {

    //表单验证
    const rules = reactive({
        currencyCode: [{
            required: true,
            message: '请填写三字简码',
            trigger: 'change'
        },
        { pattern: /^[A-Z]{3}$/, message: '请输入三位大写字母' }
        ],
        currencyRate: [
            { required: true, message: '请填写汇率', trigger: 'change' },
            { pattern: /^\d+(\.{0,1}\d+){0,1}$/, message: '请输入正数' }
        ],

        startDate: [
            { required: true, message: '请选择日期', trigger: 'change' }
        ],
        titleName: [{ required: true, message: "请输入名称", trigger: "blur" }],
        date: [{ required: true, message: "请选择时间", trigger: "blur" }]
    });
    //表单数据
    const dialogModel = reactive<SubmitCurrencyRateModel>({
        id: "",
        currencyCode: "",
        currencyRate: 1.0,
        startDate: '',
        endDate: '',
        type: "0"
    })

    // 动态表格表单
    const addEditCustomerRateTable: BaseTableProps = reactive({
        border: true,
        maxHeight: 300,
        columns: [
            {
                prop: "currencyCode",
                label: "币种",
                align: "center",
                slot: true,
                slotName: 'currencyCode'
            },
            {
                prop: "currencyRate",
                label: "汇率",
                align: "center",
                slot: true,
                slotName: 'currencyRate'
            },
            {
                prop: "action",
                label: "操作",
                align: "center",
                width: 80,
                slot: true,
                slotName: 'action',
                slotHeader: true
            },
        ],
        dataSource: []
    })

    return {
        rules,
        dialogModel,
        addEditCustomerRateTable,
    }
}