SOURCE

const getPolicyInfo = status => {
    if (status === 'ing') {
        return {
            code: 0,
            policyList: [
                {
                    policyId: 'policy-1', // 保单id
                    productName: '看病能报销', // 保单名称
                    sheet: 'to-draw', // 状态-to-draw=待提现(已申请待体现),paid-ok=已提现(已提现)
                    payTime: undefined, // 支付时间
                    applyTime: 1679382210, // 申请时间
                    payHospital: '北京大学深圳医院',
                    orderMoney: 32,
                },
                {
                    policyId: 'policy-2', // 保单id
                    productName: '看病能报销', // 保单名称
                    sheet: 'to-draw', // 状态-to-draw=待提现(已申请待体现),paid-ok=已提现(已提现)
                    payTime: undefined, // 支付时间
                    applyTime: 1679384410, // 申请时间
                    payHospital: '华中科技大学协和医院测试名称',
                    orderMoney: 100,
                },
                {
                    policyId: 'policy-3', // 保单id
                    productName: '看病能报销', // 保单名称
                    sheet: 'to-draw', // 状态-to-draw=待提现(已申请待体现),paid-ok=已提现(已提现)
                    payTime: undefined, // 支付时间
                    applyTime: 1679484410, // 申请时间
                    payHospital: '南山区人民医院', // 就诊医院
                    orderMoney: 100,
                },
            ],
        }
    }
    return {
        code: 0,
        policyList: [
            {
                policyId: 'policy-1', // 保单id
                productName: '看病能报销', // 保单名称
                sheet: 'paid-ok', // 状态-to-draw=待提现(已申请待体现),paid-ok=已提现(已提现)
                payTime: 1679382210, // 支付时间
                applyTime: undefined, // 申请时间
                payHospital: '北京大学深圳医院',
                orderMoney: 32,
            },
            {
                policyId: 'policy-2', // 保单id
                productName: '看病能报销', // 保单名称
                sheet: 'paid-ok', // 状态-to-draw=待提现(已申请待体现),paid-ok=已提现(已提现)
                payTime: 1679384410, // 支付时间
                applyTime: undefined, // 申请时间
                payHospital: '华中科技大学协和医院测试名称',
                orderMoney: 100,
            },
            {
                policyId: 'policy-3', // 保单id
                productName: '看病能报销', // 保单名称
                sheet: 'paid-ok', // 状态-to-draw=待提现(已申请待体现),paid-ok=已提现(已提现)
                payTime: 1679484410, // 支付时间
                applyTime: undefined, // 申请时间
                payHospital: '南山区人民医院', // 就诊医院
                orderMoney: 100,
            },
        ],
    }
}

const res = getPolicyInfo('ing')

const dateFormat = (timestamp, format) => {
    let date = timestamp;
    if (!(date instanceof Date)) date = new Date(parseInt(timestamp, 10) * 1000);
    let o = {
        'Y+': date.getFullYear(),
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds(),
        'q+': Math.floor((date.getMonth() + 3) / 3),
        'S': date.getMilliseconds()
    };
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    for (let k in o)
        if (new RegExp('(' + k + ')').test(format)) format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));
    return format;
};

const formateData = (policyList) => {
    return policyList.map(item => {
        return {
            policyId: item.policyId,
            sheet: item.sheet,
            productName: item.productName,
            rows: pasrseDataToRows(item)
        }
    })
}


function toFixed(num, s) {
    var times = Math.pow(10, s)
    var des = num * times + 0.5
    des = parseInt(des, 10) / times
    return des + ''
}


function safeDivide(dividend, divisor) {
    const precision = 1000000; // 确定你需要的精度级别
    const quotient = (dividend * precision) / divisor;
    return Math.round(quotient) / precision;
}

const pasrseDataToRows = (data) => {
    const isComplete = data.sheet === 'paid-ok'
    const status = { title: '报销状态', content: isComplete ? '已完成' : '已申请待提现', className: 'success' } // 获取状态
    const time = { title: isComplete ? '支付时间' : '申请时间', content: dateFormat(isComplete ? data.payTime : data.applyTime, 'yyyy.MM.dd hh:mm') } // 支付/申请时间
    const payHospital = { title: '就诊医院', content: data.payHospital } // 就诊医院
    const orderMoney = { title: '订单费用', content: data.orderMoney } // 订单费用
    const expenseMoney = { title: '报销费用', content: safeDivide(data.orderMoney, 10) } // 报销费用的10%
    return [status, time, payHospital, orderMoney, expenseMoney]
}


console.log(formateData(res.policyList))
console 命令行工具 X clear

                    
>
console