import axios  from 'axios';
import {callMobile} from "./common";

// baseURL: process.env.VUE_APP_BASE_URL,
var apiInstance=axios.create({
    baseURL: process.env.VUE_APP_BASE_URL,
    timeout:10000,
    withCredentials:true
})

/*为请求添加请求头中的token*/
apiInstance.interceptors.request.use(config=>{
    // let tokenInfo = JSON.parse(window.sessionStorage.getItem('mobileTokenIno')).token
    // if (tokenInfo) {
    //     config.headers.Authorization = tokenInfo;
        if (typeof (config.params) == "undefined") {
            config.params = {}
        }
        return config;//赋值完后把config返回回去
    // } else {
    //     callMobile("goIndex", {});
    //     return
    // }
    // return config;//赋值完后把config返回回去
},error => {
    // 请求错误后把我们的error返回回去
    return Promise.reject(error);
})


//拦截请求结果判断token是否失效
apiInstance.interceptors.response.use( res =>{
    let data = res
    let result = res.data
    //比如响应一些报错信息
   /* if (res.status == '401') {
        callMobile("goIndex", {});
        return
    }*/
    if (result.code == 'BIZ.TOKEN_EXPIRATION') {
        callMobile("goIndex", {});
        return
    }
    return data
}, error => {
    callMobile("goIndex", {});
    return
})

/*获取网点*/
export const getNetworkInfo = params =>{
    return apiInstance.get(`/basic-info/v1/api/phone-h5/basic-network-info/get-network-info`,{params});
};

//获取用领取记录
export const getUserCollectRecord = params => {
    return apiInstance.get(`/stock-info/v1/api/phone-h5/stock-provide-record/page`, {params})
}

//获取用户领取记录（可申领）
export const getUserLossReportRecord = params => {
    return apiInstance.get(`/stock-info/v1/api/phone-h5/stock-provide-record/anew-page`, {params})
}

//药具重新申领申请
export const addLossReport = params => {
    return apiInstance.post(`/stock-info/v1/api/phone-h5/stock-provide-record/anew`, params)
}

//根据领取单号获取领取记录
export const getUserCollectRecordByNo = params => {
    return apiInstance.get(`/stock-info/v1/api/phone-h5/stock-provide-record/query-by-no/${params.no}`, {params})
}

//获取库存信息
export const getStockInfo = params => {
    return apiInstance.get(`/stock-info/v1/api/phone-h5/stock-basic-info/basic-info`, {params})
}

//判断用户首次领取是否已填随访
export const getUserReceiveNum = params => {
    return apiInstance.get(`/stock-info/v1/api/phone-h5/stock-provide-record/number/${params.residentId}`, {params})
}

//填写随访记录
export const addVisitRecord = params => {
    return apiInstance.post(`/stock-info/v1/api/phone-h5/stock-visit-info/add-visit-record`, params)
}

//确认领取药具
export const addMedicalRecord = params => {
    return apiInstance.post(`/stock-info/v1/api/phone-h5/stock-provide-record/add-medical-record`, params)
}

//获取人工网点药具信息
export const getManualNetworkMedical = params => {
    return apiInstance.get(`/stock-info/v1/api/phone-h5/stock-basic-info/phone-network-stock-info`, {params})
}

//人工网点领取
export const addManualMedicalRecord = params => {
    return apiInstance.post(`/stock-info/v1/api/phone-h5/admin/stock-provide-record/artificial-receive`, params)
}

//人工网点单个药具领取
export const addSingleManualMedicalRecord = params => {
    return apiInstance.post(`/stock-info/v1/api/phone-h5/stock-provide-record/artificial-receive-of-phone`, params)
}
//药具领取发送短息验证码
export const getShortMessage = params => {
    return apiInstance.get(`/stock-info/v1/api/phone-h5/sms/send`, {params})
}

//药具领取验证短息验证码
export const getCheckShortMessage = params => {
    return apiInstance.get(`/stock-info/v1/api/phone-h5/sms/check`, {params})
}

//领取记录报损申请
export const addDestroyApply = params => {
    return apiInstance.put(`/stock-info/v1/api/phone-h5/stock-provide-record/loss-reporting`, params)
}

//根据身份证号获取家签居民基本信息
export const getUserInfoByIdCard = params => {
    return apiInstance.get(`/stock-info/v1/api/phone-h5/stock-provide-record/get-residents-info-by-id-card`, {params})
}
