/**
 * 该js为APP通用utils
 * 与逻辑流程无强烈关联的方法放置于此
 */


/**
 * 获取系统类型
 * 1: android 
 * 2: linux
 * 3: pc
 * 4: web
 */
function getOSType() {
}

/**
 * 获取文件日志
 */
function getKtLog() {
}

/**
 * 获取本地时间 格式:HH:mm:ss
 */
function getTime() {
}

/**
 *  获取本地日期 格式:yyyy/MM/dd
 */
function getDate() {
}

/**
 *  date转long
 */
function dateToLong() {
}

/**
 * 获得长宽
 */
function getScreen() {
    var screenInfo = {
        w: "",
        h: ""
    }
}

/**
 * 横屏还是竖屏
 */
function isLandScreen() {
}

var appConfig = null

var AppUtils = {
    /**
     * 初始化应用配置
     */
    setAppConfig(app) {
        appConfig = app
    },
    /**
     * 获取应用配置
     */
    getAppConfig() {
        if (appConfig) {
            return appConfig
        } else {
            return ("app暂未初始化, 请先初始化")
        }
    },
    /**
     * 获取平台名称 
     * win 或者 android 或者 ios . 该方法不能作为主要判断平台的方式. 
     * 需要判断  is.cordova => 使用 cordova 
     * 需要判断  is.Electron => 使用Electron
     * 建议从 getAppConfig中去判定
     */
    getAppPlaform() {
        if (appConfig) {
            return (appConfig.platform.is.platform)
        } else {
            return ("app暂未初始化, 请先初始化")
        }
    },
    /**
     * 用于存储应用内容, 类似于安卓的 Pref. putString .
     * @param {标签} label 
     * @param {内容} string 
     */
    putStringStorage(label, string) {
        appConfig.localStorage.set(label, string)
    },
    /**
     * 通过标签获取数据
     * @param {标签} label 
     */
    getStringStorage(label) {
        if (appConfig.localStorage.has(label)) { return appConfig.localStorage.getItem(label) } else
            return ""
    },
    /**
     * 时间戳, 到日 2019-08-07
     */
    timeStapInDay() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        month = month.toString()
        if (month.length == 1) {
            month = "0" + month
        }
        var day = date.getDate();
        day = day.toString()
        if (day.length == 1) {
            day = "0" + day
        }
        return (year + '-' + month + '-' + day)
    },
    /**
     * 时间戳, 到毫秒
     * 2019-08-07 09:57:27:258
     */
    timeStap() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        month = month.toString()
        if (month.length == 1) {
            month = "0" + month
        }
        var day = date.getDate();
        day = day.toString()
        if (day.length == 1) {
            day = "0" + day
        }
        var hour = date.getHours();
        hour = hour.toString()
        if (hour.length == 1) {
            hour = "0" + hour
        }
        var minute = date.getMinutes();
        minute = minute.toString()
        if (minute.length == 1) {
            minute = "0" + minute
        }
        var second = date.getSeconds();
        second = second.toString()
        if (second.length == 1) {
            second = "0" + second
        }
        var mis = date.getMilliseconds();
        mis = mis.toString()
        if (mis.length == 1) {
            mis = "00" + mis
        } else if (mis.length == 2) {
            mis = "0" + mis
        }
        return (year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second + "." + mis)
    },
    changeMoney(num) {
        var regexp = /(?:\.0*|(\.\d+?)0+)$/
        num = (num / 100).toFixed(2)
        num = num.replace(regexp, '$1')
        var numArray = num.split(".")
        console.log(numArray)
        if (numArray.length > 0) {
            if (numArray.length == 1) {
                return numArray[0] + ".00"
            }
            if (numArray[1].length == 1) {
                numArray[1] = numArray[1] + "0"
            }
            return numArray[0] + "." + numArray[1]
        }
        return num
    },
    showErrorNotify(msg) {
        this.getAppConfig().notify({ color: 'negative', message: msg, icon: 'report_problem' })
    },
    showNormalNotify(msg) {
        this.getAppConfig().notify({ color: 'teal', message: msg })
    },
    showLoading() {
        this.getAppConfig().loading.show({
            // spinner: KtApp.getAppConfig().QSpinnerGears,
            message: '请稍等...'
        })
        // 超时时间
        loadingTimer = setTimeout(() => {
            this.hideLoading()
            loadingTimer = void 0
        }, 10000)
    },
    hideLoading() {
        this.getAppConfig().loading.hide()
        window.clearTimeout(loadingTimer);//去掉定时器 
    }
}

module.exports = AppUtils;