import axios from 'axios'
import envConfig from '@/config/env-config'

let INFO = {
  // corpId: 'wwd1cdbca7b8b2b6c4',
  // agentId: '1000015',
  corpId: 'ww4df265003b43fa0d',
  agentId: '1000033',
  url: envConfig.appBaseUrlB,
}

// 创建axios实例
const service = axios.create({
  baseURL: INFO.url, // api 的 base_url
  timeout: 50000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(
  (config) => {
    if (sessionStorage['token']) {
      config.headers['token'] = sessionStorage['token']
      config.headers['businessId'] = sessionStorage['businessId']
    } else {
      config.headers['businessId'] = '10'
    }
    return config;
  },
  (error) => {
    Promise.reject(error)
  }
)

// response 拦截器
service.interceptors.response.use(
  response => {
    console.log(response)
    if(response.status == 200) {
      return response.data
    } else {
      Message({
        message: response.data.msg,
        type: 'error',
        duration: 5 * 1000
      })
    }
  },
  error => {
    console.log(error)
  }
)
export default service
