let tools = {}
/**
 * 大小判断
 * @param a
 * @param b
 * @returns {number}
 */
tools.sortNumber = function (a, b) {
    return a - b;
}


/**
 * 保留两位小数
 * @param num
 * @returns {string}
 */
tools.twoFloating = function (num) {
    // 获取两位小数
    let price = "";
    price = num * 1;
    price = String(price).split(".")[1];
    if (price !== undefined && price.length === 1) {
        price = `.${price}0`;
    } else {
        price === undefined ? (price = ".00") : (price = `.${price}`);
    }
    return price;
}
tools.formatDecimal = function (num, decimal) {
    num = num.toString()
    let index = num.indexOf('.')
    if (index !== -1) {
        num = num.substring(0, decimal + index + 1)
    } else {
        num = num.substring(0)
    }
    return parseFloat(num).toFixed(decimal)
}

/**
 * 错误提示
 * @param msg
 */
tools.error = function (msg) {
    console.log(msg)
}

/**
 * 成功提示
 * @param msg
 */
tools.success = function (msg) {
    console.log(msg)
}

/**
 * 显示Loading
 */
tools.showLoading = function () {

}

/**
 * 关闭Loading
 */
tools.hideLoading = function () {

}

/**
 * 获取时间戳（毫秒）
 * @returns {number}
 */
tools.getTime = function () {
    return new Date().getTime();
}



/**
 * uniapp  html图片显示控制
 * @param str
 * @returns {*}
 */
tools.imgDeal = function (str) {
    console.log(str)


}


/**
 * 获取平台类型  1：微信，2：支付宝
 * @returns {boolean|number}
 */
tools.platformType = function () {
    let ua = window.navigator.userAgent.toLowerCase();
    if (ua.indexOf('micromessenger') != -1) {
        return 1;
    } else if (ua.indexOf('alipay') != -1) {
        return 2;
    } else {
        return 0;
    }
}




tools.leftClick=function (){

}

/**
 * 跳转到异常界面
 * @param errorType
 */
tools.goToError=function (errorType){
    console.log(errorType)
}

tools.toError=function (errorMsg){
    console.log(errorMsg)
}



tools.getShowAddress=function (address){
    return (address.substr(0,8)+'...'+address.substr(address.length-4))
}

tools.getAddress=function (address){
    return address.substr(0,4)+'...'+address.substr(-4);
}

tools.isDevelopment=function () {
    if(process.env.NODE_ENV==='development'){
        return true
    }else {
        return false
    }
}


export default tools
