const _my = require("../../__antmove/api/index.js")(my);
const wx = _my;
//设置域名
const dev_baseUrl_wxrlxf = "http://192.168.11.11:9100/yx-fyzd"; //测试
const pro_baseUrl_wxrlxf = "https://tx.hz-hanghui.com:8088/yx-fyzd"; //正式

//是否是正式环境
const wx_rlxf = true;
const baseUrl = wx_rlxf ? pro_baseUrl_wxrlxf : dev_baseUrl_wxrlxf;

//https请求
const request_wxrlxf = e => {
    return new Promise(function(resolve, reject) {
        wx.request({
            url: e.url.startsWith('http') ? e.url : (wx_rlxf
                ? pro_baseUrl_wxrlxf + e.url
                : dev_baseUrl_wxrlxf + e.url),
            data: e.data,
            method: e.method,
            header: {
                "content-type": e.type
            },
            success: res => {
                if (res.statusCode == 200) {
                    resolve(res.data);
                } else {
                    reject(res.data);
                }
            },
            fail: error => {
                reject(error.errMsg);
            }
        });
    });
};

//是否是正式环境
const env = true;

//设置域名
const dev_baseUrl = "http://192.168.11.11:9100"; //测试
const pro_baseUrl = "https://renhe.hz-hanghui.com"; //正式

//https请求
const request = e => {
    return new Promise(function(resolve, reject) {
        wx.request({
            url: e.url.startsWith('http') ? e.url : (env ? pro_baseUrl + e.url : dev_baseUrl + e.url),
            data: e.data,
            method: e.method,
            header: {
                "content-type": e.type
            },
            success: res => {
                if (res.statusCode == 200) {
                    resolve(res.data);
                } else {
                    reject(res.data);
                }
            },
            fail: error => {
                reject(error.errMsg);
            }
        });
    });
};
//提示框
const showToast = title => {
    wx.showToast({
        title: title,
        icon: "none",
        duration: 3000
    });
};
const showModal = (
    { text, title = "提示", showCancel = false } = {},
    successCallback = function() {}
) => {
    return wx.showModal({
        title: title,
        content: text,
        showCancel: showCancel,
        success: res => {
            if (res.confirm) {
                successCallback();
            } else if (res.cancel) {
                console.log("用户点击取消");
            }
        }
    });
};
// 等待
const showLoading = title => {
    wx.showLoading({
        title: title
    });
};
module.exports = {
    wx_rlxf: wx_rlxf,
    baseUrl,
    dev_baseUrl_wxrlxf: dev_baseUrl_wxrlxf,
    pro_baseUrl_wxrlxf: pro_baseUrl_wxrlxf,
    request_wxrlxf: request_wxrlxf,
    env: env,
    dev_baseUrl: dev_baseUrl,
    pro_baseUrl: pro_baseUrl,
    request: request,
    showToast,
    showModal,
    showLoading
};
