//人民币小写转大写
export function rmb (num) {
const numArray = num.split('.')
const numList = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
const radiceList = ['', '拾', '佰', '仟']
const unitList = ['', '万', '亿', '兆']
const decList = ['角', '分']
const num1 = numArray[0].split('').reverse().map((num, index) => {
const unit = unitList[index / 4] || ''
return numList[Number(num)] + radiceList[index % 4] + unit
}).reverse()
const num2 = numArray[1] === '00' ? ['整'] : numArray[1].split('').map((num, index) => numList[Number(num)] + decList[index])
return [
...num1,
'元',
...num2
].join('')
}
export function formatDateRange (obj) {
if(!obj) return null;
let startDate = obj[0];
startDate.setHours(0);
startDate.setMinutes(0);
startDate.setSeconds(0);
let endDate = obj[1];
endDate.setHours(23);
endDate.setMinutes(59);
endDate.setSeconds(59);
return [
startDate.getTime(),
endDate.getTime()
]
}
//树形结构格式转换
export function treeFormat (list, key = 'value', parentKey = 'parentId', childKey = 'children') {
let sNodes = cloneDeep(list)
let i, j, k, l, len, len1, r, tmpMap
if (isArray(sNodes)) {
r = []
tmpMap = []
for (k = 0, len = sNodes.length; k < len; k++) {
i = sNodes[k]
i.text = i.label
tmpMap[i[key]] = i
}
for (l = 0, len1 = sNodes.length; l < len1; l++) {
j = sNodes[l]
if (tmpMap[j[parentKey]] && j[key] !== j[parentKey]) {
if (!tmpMap[j[parentKey]][childKey]) {
tmpMap[j[parentKey]][childKey] = []
}
tmpMap[j[parentKey]][childKey].push(j)
} else {
r.push(j)
}
}
return r
} else {
return [sNodes]
}
}
transfromTime(time) {
if (time) {
var now = new Date(time),
y = now.getFullYear(),
m = now.getMonth() + 1,
d = now.getDate();
return (
y +
"-" +
(m < 10 ? "0" + m : m) +
"-" +
(d < 10 ? "0" + d : d) +
" " +
now.toTimeString().substr(0, 5)
);
} else {
return null;
}
},
dateFormat: function(row, column) {
var date = row[column.property];
if (date == undefined) {
return "-";
}
return moment(date).format("YYYY-MM-DD HH:mm:ss");
}