
import request from '../../../../util/request'
import Store from '../../../../store/store'
import {
    Toast
} from "vant";
const BASE_URL = process.env.API_HOST //'https://lzdz3-isv.isvjcloud.com/api';
const getActivityId = () => {
    return Store.state.activityId
}
const postAll = async (path, params,type) => {
    const url = type===1?path: '/dz/keyanshi/game2210/' + path
    const urls =BASE_URL + url 
    const res = await request.post(urls, params)
    return res
}
const Api = {
    activityContent: async (params) => {
        if (Store.state.shareUserId) params.shareUuid = Store.state.shareUserId
        params.channel = ''
        const res = await postAll('activityContent', params)
        return res
    },
    getMyInfo: (params) => postAll('myInfo', params),
    // 获取任务列表
    getTaskList: (params) => postAll('taskList', params),
    getTaskRecord: (params) => postAll('taskRecord', params),
    getMyPrize: (params) => postAll('myPrize', params),
    getAddress: (params) => postAll('getAddress', params),
    saveAddress: (params) => postAll('saveAddress', params),
    draw: (params) => postAll('draw', { ...params, "drawId": "0", }),
    doTask: (params) => postAll('doTask', params), //做任务
    productList: (params) => postAll('productList', { ...params, type: 1 }),//获取加购商品
    rankList: (params) => postAll('rankList', params),//获取排行
    takeRankPrize: (params) => postAll('takeRankPrize', params),//领取排行奖励
    saveLog: (params) => postAll('/dz/qd/common/saveLog', params,1),//领取排行奖励

}
export const getApiData = async (name, params = {},noToast) => {
    console.log(params);
    try {
        params.activityId = getActivityId()
        const { data } = await Api[name](params)
        console.log(data);
        if (data.resp_code === 0) return Promise.resolve(data.data)
        if (data.resp_code !== 0) {
            if (!noToast&&data.resp_msg) Toast(data.resp_msg)
            return Promise.reject(data)
        }
    } catch (error) {
        console.log(error);
        Promise.reject(name, '错误')
        console.log(name, '错误', params, '//////////');
    }


}

