import request from '../../utils/request.js'
import { getMobileCache } from '../../utils/user'

class Statistics extends request {
    static done(params) {
        const accountInfo = wx.getAccountInfoSync()
        const pages = getCurrentPages()
        const path = pages[pages.length - 1].route
        const options =  wx.getLaunchOptionsSync()
        const referrerInfo = options.referrerInfo || {}
        const extraData = referrerInfo.extraData || {}
        const department = extraData.department || ''
        const channel = extraData.channel || ''

        let postParam = {
            source: 'WX_MINI_APP',
            channel: params.channel || channel,
            module: params.module,
            action: params.action,
            appid: accountInfo.miniProgram.appId,
            path,
            scene: options.scene,
            fromAppid: referrerInfo.appId || '',
            department: params.department || department,
            mobile: getMobileCache(),
            businessId: params.businessId || '',
        }
        this.postRequest(`${this.BASE_URL}open/statistics/record-app-visit-log`, postParam, true).then(_=>{}).catch(_=>{})

        return postParam;
    }
}

export default Statistics