var clientData = getSystemInfo()
var header = {
    'appChannel': clientData.channel,
    'appType': 1,
    'platform': ClientOs() == 'Win7' ? 4 : 6,
    'appVersion': clientData.version,
    'deviceId': clientData.device_id,
    'mainBoardId': clientData.cs_product_uuid || 0
}

function recordEventAction(dataItem) {
    var otherHeader = {
        'system': checkProcessor(),
        'networkType': clientData.network_type == 1 ? 2 : 1,
        'userId': localStorage.getItem('userId') || 0,
        'userType': localStorage.getItem('userId') ? 1 : 0
    }
    var recordData = {
        'optime': new Date().format('yyyyMMddHHmmss'),
        'gameid': dataItem.gameId || '',
        'gamename': dataItem.gameName || '',
        'eventtype': dataItem.eventType, // 事件类型
        'url': dataItem.url || '', // 事件类型
        'rese1': dataItem.rese1 || '',
        'rese2': dataItem.rese2 || '',
        'rese3': dataItem.rese3 || '',
        'rese4': dataItem.rese4 || '',
        'rese5': dataItem.rese5 || '',
        'rese6': (dataItem.rese6 || dataItem.rese6 == 0) ? dataItem.rese6 : '',
        'rese7': dataItem.rese7 || '',
        'rese8': dataItem.rese8, // 事件描述
        'rese9': dataItem.rese9 || '',
        'rese10': dataItem.rese10 || '',
        'rese11': dataItem.rese11 || '',
        'rese12': dataItem.rese12 || '',
        'rese13': dataItem.rese13 || '',
        'rese14': dataItem.rese14 || '',
        'rese15': dataItem.rese15 || '',
        'rese16': dataItem.rese16 || '',
        'rese17': dataItem.rese17 || '',
        'rese18': dataItem.rese18 || '',
        'rese19': dataItem.rese19 || '',
        'rese20': dataItem.rese20 || '',
        'reason': dataItem.reason || '',
        'definition': '',
        'keyword': dataItem.keyword || '',
        'pagename': dataItem.pageName || '',
        'indexno': dataItem.indexno || '',
        'topicIndex': dataItem.topicIndex || '',
        'topicName': dataItem.topicName || '',
        'labelName': dataItem.labelName || ''
    }
    var param = {
        headers: Object.assign(header, otherHeader),
        data: {
            'data': [recordData]
        }
    }
    console.log(new Date().format('yyyyMMddHHmmss'), param)
    postJinFenLogApi(param)
}


function postJinFenLog(dataItem) {
    if (!header.deviceId) {
        Client.getSystemInfo().then((res) => {
            clientData = JSON.parse(res)
            if (clientData) {
                header = {
                    'appChannel': clientData.channel,
                    'appType': 1,
                    'platform': ClientOs() == 'Win7' ? 4 : 6,
                    'appVersion': clientData.version,
                    'deviceId': clientData.device_id,
                    'mainBoardId': clientData.cs_product_uuid || 0
                }
                recordEventAction(dataItem)
            }
        })
    } else {
        recordEventAction(dataItem)
    }
}

// 获得pc的操作系统
function ClientOs() {
    var sUserAgent = navigator.userAgent
    var isWin = (navigator.platform === 'Win32') || (navigator.platform === 'Windows')
    var isMac = (navigator.platform === 'Mac68K') || (navigator.platform === 'MacPPC') || (navigator.platform === 'Macintosh') || (navigator.platform === 'MacIntel')
    if (isMac) return 'Mac'
    var isUnix = (navigator.platform === 'X11') && !isWin && !isMac
    if (isUnix) return 'Unix'
    var isLinux = (String(navigator.platform).indexOf('Linux') > -1)
    if (isLinux) return 'Linux'
    if (isWin) {
        var isWin2K = sUserAgent.indexOf('Windows NT 5.0') > -1 || sUserAgent.indexOf('Windows 2000') > -1
        if (isWin2K) return 'Win2000'
        var isWinXP = sUserAgent.indexOf('Windows NT 5.1') > -1 || sUserAgent.indexOf('Windows XP') > -1
        if (isWinXP) return 'WinXP'
        var isWin2003 = sUserAgent.indexOf('Windows NT 5.2') > -1 || sUserAgent.indexOf('Windows 2003') > -1
        if (isWin2003) return 'Win2003'
        var isWinVista = sUserAgent.indexOf('Windows NT 6.0') > -1 || sUserAgent.indexOf('Windows Vista') > -1
        if (isWinVista) return 'WinVista'
        var isWin7 = sUserAgent.indexOf('Windows NT 6.1') > -1 || sUserAgent.indexOf('Windows 7') > -1
        if (isWin7) return 'Win7'
    }
    return 'other'
}