Utils.js 4.97 KB
'use strict';
import ReactNative from 'react-native';

/**
 *正则替换卡号,保留后4位,并且四位插入一个空格
 **/
function replaceBankCardNo(cardNo){

    let newCardNo = cardNo ? cardNo.replace(/(\d+)(\d{4})$/, (a, b, c)=> {
        return b.replace(/\d/g, '*') + c;
    }) : "";

    //newCardNo = newCardNo.replace(/(\w{4})(?=\w)/g, '$1 ');

    return newCardNo;
}

/**
 *将卡号四位插入一个空格
 **/
function formatBankCardNo(cardNo){
    let newCardNo = cardNo ? cardNo.replace(/\s/g, '') : "";
    newCardNo = newCardNo.replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ');
    return newCardNo;
}

/**
 *替换空格为空
 **/
function replaceSpace(cardNo){
    let newCardNo = cardNo ? cardNo.replace(/\s/g, '') : "";
    return newCardNo;
}


/**
 *保留银行卡最后4位
 **/
function splitLast4Number(cardNo){
    let newCardNo = cardNo ? cardNo.substring(cardNo.length - 4, cardNo.length) : "";
    return newCardNo;
}


/**
 *获取银行卡大图
 **/
function getBankBigImage(bank){
    let bankImg;
    switch(bank){
        case "ABC":
            bankImg = require('../image/bank/b-ABC.png');
            break;
        case "BOC":
            bankImg = require('../image/bank/b-BOC.png');
            break;
        case "CCB":
            bankImg = require('../image/bank/b-CCB.png');
            break;
        case "CEB":
            bankImg = require('../image/bank/b-CEB.png');
            break;
        case "CGB":
            bankImg = require('../image/bank/b-CGB.png');
            break;
        case "CIB":
            bankImg = require('../image/bank/b-CIB.png');
            break;
        case "CITIC":
            bankImg = require('../image/bank/b-CITIC.png');
            break;
        case "CMBC":
            bankImg = require('../image/bank/b-CMBC.png');
            break;
        case "ICBC":
            bankImg = require('../image/bank/b-ICBC.png');
            break;
        case "PAYH":
            bankImg = require('../image/bank/b-PAYH.png');
            break;
        case "PSBC":
            bankImg = require('../image/bank/b-PSBC.png');
            break;
        default:
            bankImg = require('../image/bank/bank-EMPTY.png');
            break;
    }
    return bankImg;
}

/**
 *获取银行卡大图
 **/
function getBankSmallImage(bank){
    let bankImg;
    switch(bank){
        case "ABC":
            bankImg = require('../image/bank/ABC.png');
            break;
        case "BOC":
            bankImg = require('../image/bank/BOC.png');
            break;
        case "CCB":
            bankImg = require('../image/bank/CCB.png');
            break;
        case "CEB":
            bankImg = require('../image/bank/CEB.png');
            break;
        case "CGB":
            bankImg = require('../image/bank/CGB.png');
            break;
        case "CIB":
            bankImg = require('../image/bank/CIB.png');
            break;
        case "CITIC":
            bankImg = require('../image/bank/CITIC.png');
            break;
        case "CMBC":
            bankImg = require('../image/bank/CMBC.png');
            break;
        case "ICBC":
            bankImg = require('../image/bank/ICBC.png');
            break;
        case "PAYH":
            bankImg = require('../image/bank/PAYH.png');
            break;
        case "PSBC":
            bankImg = require('../image/bank/PSBC.png');
            break;
        default:
            bankImg = require('../image/bank/bank-EMPTY.png');
            break;
    }
    return bankImg;
}

/**
 *获取银行卡背景图
 **/
function getBankBackgroundImage(bank){
    let bankImg;
    switch(bank){
        case "ABC":
            bankImg = require('../image/bank/bank-ABC.png');
            break;
        case "BOC":
            bankImg = require('../image/bank/bank-BOC.png');
            break;
        case "CCB":
            bankImg = require('../image/bank/bank-CCB.png');
            break;
        case "CEB":
            bankImg = require('../image/bank/bank-CEB.png');
            break;
        case "CGB":
            bankImg = require('../image/bank/bank-CGB.png');
            break;
        case "CIB":
            bankImg = require('../image/bank/bank-CIB.png');
            break;
        case "CITIC":
            bankImg = require('../image/bank/bank-CITIC.png');
            break;
        case "CMBC":
            bankImg = require('../image/bank/bank-CMBC.png');
            break;
        case "ICBC":
            bankImg = require('../image/bank/bank-ICBC.png');
            break;
        case "PAYH":
            bankImg = require('../image/bank/bank-PAYH.png');
            break;
        case "PSBC":
            bankImg = require('../image/bank/bank-PSBC.png');
            break;
        default:
            bankImg = require('../image/bank/bank-EMPTY.png');
            break;
    }
    return bankImg;
}

module.exports = {
	getBankBigImage,
	getBankSmallImage,
    getBankBackgroundImage,
    replaceBankCardNo,
    formatBankCardNo,
    replaceSpace,
    splitLast4Number,
};