import store from '../store/index'

console.log(store.state.mixid,'store.state')
let shopMixid = store.state.mixid;

// wx.getStore
export async function requestGET(url, options) {

    return new Promise((resolve, reject) => {
        wx.request({
            url: url,
            data: options,
            method: "GET",
            header: {
                "Shop-Mixid": store.state.mixid,
                "Offline-Shop-Code": store.state.offlineShopCode,
                "Authorization": wx.getStorageSync('sessionid') || "",
                "Location-Id" : wx.getStorageSync('location') ? JSON.parse(wx.getStorageSync('location')).systemRegionId : ''
                // "dubbo-tag": "ljx"
            },
            success: function (res) {
                resolve(res)
            },
            fail: function (res) {
                reject(res)
            }
        })
    })
}

export async function requestPOST(url, options) {
    return new Promise((resolve, reject) => {
        wx.request({
            url: url,
            data: options,
            method: "POST",
            header: {
                "Shop-Mixid": store.state.mixid,
                "Authorization": wx.getStorageSync('sessionid') || "",
                "Offline-Shop-Code": store.state.offlineShopCode,
                "openId": wx.getStorageSync("openid") || '',
                "Location-Id" : wx.getStorageSync('location') ? JSON.parse(wx.getStorageSync('location')).systemRegionId : ''
                // "dubbo-tag": "ljx"
            },
            success: function (res) {
                resolve(res)
            },
            fail: function (res) {
                reject(res)
            }
        })
    })
}

export function requestPOST1(url, options) {
    return new Promise((resolve, reject) => {
        wx.request({
            url: url,
            data: options,
            method: "POST",
            header: {
                "Content-Type": "application/x-www-form-urlencoded",
                "Shop-Mixid": store.state.mixid,
                Authorization: wx.getStorageSync('sessionid') || "",
                "Offline-Shop-Code": store.state.offlineShopCode,
                // "dubbo-tag": "ljx"
            },
            success: function (res) {
                resolve(res)
            },
            fail: function (res) {
                reject(res)
            }
        })
    })
}

// function getHeader() {
//     let sessionid = wx.getStorageSync('sessionid');
//     let header = {
//         "Content-Type": "application/x-www-form-urlencoded",
//         "Shop-Mixid": shopMixid,
//         Authorization: sessionid
//     };
//     // if (!sessionid) {
//     //     delete header.Authorization
//     // }
//     return header
// }