const _my = require("../../__antmove/api/index.js")(my);
const wx = _my;
const util = require("../func/request");

//检测是否获取手机号
const isGetPhone = e => {
    if (e.detail.errMsg == "getPhoneNumber:ok") {
        return true;
    } else {
        return false;
    }
};

//获取手机号
const getPhone = e => {
    return new Promise((reslove, reject) => {
        wx.showLoading({
            title: "获取中...",
            mask: true
        });
        if (!isGetPhone(e)) {
            wx.hideLoading();
            wx.showToast({
                title: "我们需要获取您的手机号才能进行实名登录哦",
                icon: "none"
            });
            reject();
        } else {
            util.request_wxrlxf({
                url: "/api/next/doGetPhone",
                data: {
                    // code: wx.getStorageSync("wxCode"),
                    iv: e.detail.iv,
                    encryptedData: e.detail.encryptedData
                },
                method: "post",
                type: "application/json"
            }).then(suc => {
                wx.hideLoading();
                reslove(suc.data);
            });
        }
    });
};
module.exports = getPhone;
