/**
 * 手机号加掩码
 * 15112345678 => 151****5678
 */
export function maskPhoneNumber(phoneNumber) {
    // 检查手机号码是否合法
    if (!/^1\d{10}$/.test(phoneNumber)) {
        return ''
    }
    return phoneNumber.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}

/**
 * 身份证号码加掩码
 * 110101198506020011 => 1101********0011
 */
export function maskIdNumber() {
    return idNumber.replace(/(\d{4})\d+(\d{4})$/, '$1****$2');
}

/**
 * 金额格式化
 * num 金额
 * decimals 保留几位小数，默认2位
 * units 默认 units ¥ 
 */
export function formatMoney(num, decimals,units){
    units = units || '¥ '

    num = parseFloat(num/100);
    if (isNaN(num)) return units+0;
    
    decimals = typeof decimals === 'undefined' ? 2 : decimals;
    
    var parts = num.toFixed(decimals).split('.');
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    
    let retVal = 0;
    // let part1 = parts[1]
    // if(parseInt(part1)==0){
    //     retVal = parts[0];
    // }else{
        retVal = parts.join('.');
    // }

    return units+retVal;
}