import axios from 'axios'
import { Message,Loading } from 'element-ui'

const baseUrl = 'https://oc-testapi.finezb.com';
// const baseUrl = 'http://192.168.3.156:8862';
// const header = {
//     "Token":localStorage.getItem('user_token'),
//     "Encrypt":localStorage.getItem('room_id'),
// }

// if(localStorage.getItem('user_token') == undefined){
    
// }
const request = (url, method, data) => {
    var header = {
        "Token":localStorage.getItem('user_token'),
        "Encrypt":localStorage.getItem('room_id'),
    }
    return new Promise((resolve, reject) => {
       if (method === 'GET') {
            axios({
                    headers:header,
                    method: method,
                    url: baseUrl + url,
                    params: data
                }).then(res => {
                    if (res.data.code === 200) {
                        resolve(res);
                    } else {
                        resolve(res);
                        
                    }
                })
                .catch(err => {
                    reject(err); //失败
                });
        } else if (method === 'POST') {
            axios({
                    headers:header,
                    method: method,
                    url: baseUrl + url,
                    data:data
                }).then(res => {
                    if (res.data.code === 200) {
                        resolve(res);
                    } else {
                        resolve(res);
                    }
                })
                .catch(err => {
                    reject(err); //失败
                });
        }
    })
}

export default request