const getPolicyInfo = status => {
if (status === 'ing') {
return {
code: 0,
policyList: [
{
policyId: 'policy-1',
productName: '看病能报销',
sheet: 'to-draw',
payTime: undefined,
applyTime: 1679382210,
payHospital: '北京大学深圳医院',
orderMoney: 32,
},
{
policyId: 'policy-2',
productName: '看病能报销',
sheet: 'to-draw',
payTime: undefined,
applyTime: 1679384410,
payHospital: '华中科技大学协和医院测试名称',
orderMoney: 100,
},
{
policyId: 'policy-3',
productName: '看病能报销',
sheet: 'to-draw',
payTime: undefined,
applyTime: 1679484410,
payHospital: '南山区人民医院',
orderMoney: 100,
},
],
}
}
return {
code: 0,
policyList: [
{
policyId: 'policy-1',
productName: '看病能报销',
sheet: 'paid-ok',
payTime: 1679382210,
applyTime: undefined,
payHospital: '北京大学深圳医院',
orderMoney: 32,
},
{
policyId: 'policy-2',
productName: '看病能报销',
sheet: 'paid-ok',
payTime: 1679384410,
applyTime: undefined,
payHospital: '华中科技大学协和医院测试名称',
orderMoney: 100,
},
{
policyId: 'policy-3',
productName: '看病能报销',
sheet: '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) }
return [status, time, payHospital, orderMoney, expenseMoney]
}
console.log(formateData(res.policyList))
console