import request from '../../../util/request'
import sensors from "sa-sdk-javascript";
import {
    addRecord
} from '../../../api/index'

const getCode = data => request({
    url: '/checkSendSmsCode',
    method: 'post',
    data
})
const login = data => request({
    url: '/smsNumber',
    method: 'post',
    data
})
const getUserInfo = data => request({
    url: '/useryearorder',
    method: 'post',
    data,
    loading: true
})


const loginClick = () => {
    sensors.para.server_url = 'https://data.mige.tv/tsa/sdata/sa.gif?project=simplePage&ptype=simpleReport'
    let channel = 'bbbbbbbbbbbb'
    let user = localStorage.getItem('reportUser')
    let fromSource = '年度账单'
    addRecord({
        userid: user,
        accessResource: "发起登录",
        channelKey: channel,
        eventType: '7',
        fromSource: fromSource,
        productId: 0,
        anonymousId: sensors.store._state.$device_id,
        testId: 0,
        testGroupId: 0,
        taskid: 0
    });
    sensors.track("reportLoginClick", {
        attr1: '999990999999'
    });
};
const showSP = () => {
    sensors.para.server_url = 'https://data.mige.tv/tsa/sdata/sa.gif?project=simplePage&ptype=simpleReport'
    let channel = 'bbbbbbbbbbbb'
    let user = localStorage.getItem('reportUser')
    let fromSource = '年度账单'
    addRecord({
        userid: user,
        accessResource: "商品浏览",
        channelKey: channel,
        eventType: '0',
        fromSource: fromSource,
        productId: 0,
        anonymousId: sensors.store._state.$device_id,
        testId: 0,
        testGroupId: 0,
        tid: 0
    });
    sensors.track("reportOpenPage", {
        attr1: '999990999999'
    });
};
const loginSuccess = () => {
    sensors.para.server_url = 'https://data.mige.tv/tsa/sdata/sa.gif?project=simplePage&ptype=simpleReport'
    let channel = 'bbbbbbbbbbbb'
    let user = localStorage.getItem('reportUser')
    let fromSource = '年度账单'
    addRecord({
        userid: user,
        accessResource: "登录成功",
        channelKey: channel,
        eventType: '8',
        fromSource: fromSource,
        productId: 0,
        anonymousId: sensors.store._state.$device_id,
        testId: 0,
        testGroupId: 0,
        tid: 0
    });
    sensors.login(user)
    sensors.track("reportLoginSuccess", {
        attr1: '999990999999'
    });
};

const reportShare = () => {
    sensors.para.server_url = 'https://data.mige.tv/tsa/sdata/sa.gif?project=simplePage&ptype=simpleReport'
    let channel = 'bbbbbbbbbbbb'
    let user = localStorage.getItem('reportUser')
    let fromSource = '年度账单'
    addRecord({
        userid: user,
        accessResource: "分享",
        channelKey: channel,
        eventType: '23',
        fromSource: fromSource,
        productId: 0,
        anonymousId: sensors.store._state.$device_id,
        testId: 0,
        testGroupId: 0,
        tid: 0
    });
    sensors.track("reportShareClick", {
        attr1: '999990999999'
    });
};
export default {
    loginSuccess,
    showSP,
    loginClick,
    reportShare,
    getCode,
    login,
    getUserInfo
}
