const mapFields = {
    letterNo:'letterNo', //计划预算函编号
    status:'status',  // 状态
    letter:'letter', //计划预算函预览
    budgetAmount:'budgetAmount', //计划预算函金额
    storeName:'storeName', //店铺名称
    companyName:'companyName', //方案上传公司
    creator:'creator', //创建人
    createTime:'createTime' //创建时间
}

const mapTemplateToTable = {
    '计划预算函编号': mapFields.letterNo,
    '状态': mapFields.status,
    '计划预算函预览': mapFields.letter,
    '计划预算函金额': mapFields.budgetAmount,
    '店铺名称': mapFields.storeName,
    '方案上传公司': mapFields.companyName,
    '创建人': mapFields.creator,
    '创建时间': mapFields.createTime
}

export const getTableProperty = (key) => mapTemplateToTable[key]

export const columns = [
    {
        type: 'index',
        label: '序号',
        width: '70px'
    },
    {
        prop: mapFields.letterNo,
        label: '计划预算函编号',
        width: '120px',
        required: true
    },
    {
        prop: mapFields.status,
        label: '状态',
        width: '120px',
        required: true
    },
    {
        prop: mapFields.letter,
        label: '计划预算函预览',
        width: '156px',
        required: true
    },
    {
        prop: mapFields.budgetAmount,
        label: '计划预算函金额',
        width: '180px',
        required: true
    },
    {
        prop: mapFields.supplierStoreName,
        label: '店铺名称',
        width: '156px',
        required: true
    },
    {
        prop: mapFields.supplierCompanyName,
        label: '方案上传公司',
        width: '156px',
        required: false
    },
    {
        prop: mapFields.creator,
        label: '创建人',
        width: '150px',
        required: false
    },
    {
        prop: mapFields.createTime,
        label: '创建时间',
        minWidth: '150px',
        required: false
    },
]

export function createErrorMessage(messages) {
    const rows = Object.keys(messages)
    return rows.reduce((prev, row, index) => {
        const suffix = index === rows.length - 1 ? '</ul>' : ''
        const content = prev + ` <li><strong style="font-weight:700">第${row}行</strong>,${messages[row]} </li> `
        return content + suffix
    }, '<ul>')
}

export const createFieldVerification = (message) => ({
    notValidRows: [],
    isValid: true,
    message
})

export const template = Array(1).fill(1).map(() => Object.keys(mapTemplateToTable).reduce((prev, property) => {
    prev[property] = ''
    return prev
}, {}))


export const requiredFields = []


export const helper = {
    fields(sourceObject) {
        return Object.keys(sourceObject)
    },
    values(sourceObject, fields, index = 0) {
        return fields.map(field => {
            return sourceObject[field][index]
        })
    },
    write(sourceObject, fields) {
        return fields.reduce((prev, currentKey) => ({
            ...prev,
            [currentKey]: sourceObject[currentKey]
        }), {})
    }
}
