var t = require("../../provider/dataApi.js");

getApp();

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        phone: "",
        phoneTest: "",
        code: "",
        codeText: "获取验证码"
    },
    onLoad: function(t) {
        this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight
        }), this.init();
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    init: function() {
        var e = this;
        t.getBind({
            uid: wx.getStorageSync("uid")
        }).then(function(t) {
            if (console.log(t), 0 == t.errno) {
                t = t.data.data.phone;
                var n = e.handlePhone(t);
                e.setData({
                    phone: t,
                    phoneTest: n
                });
            }
        }).catch(function(t) {
            console.log(t);
        });
    },
    handlePhone: function(t) {
        return t.slice(0, 3) + "****" + t.slice(t.length - 4, t.length);
    },
    sendCode: function() {
        var e = this;
        /^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.data.phone) ? "获取验证码" == this.data.codeText || "重新发送" == this.data.codeText ? t.userinfo({
            phone: this.data.phone,
            uid: wx.getStorageSync("uid"),
            op: "getcode"
        }).then(function(t) {
            e.setData({
                codeText: "60秒"
            });
            var n = 60, o = setInterval(function() {
                n--, e.setData({
                    codeText: n + "秒"
                }), n <= 0 && (e.setData({
                    codeText: "重新发送"
                }), clearInterval(o));
            }, 1e3);
        }).catch(function(t) {
            console.log(t), wx.showToast({
                icon: "none",
                title: t.message
            });
        }) : wx.showToast({
            icon: "none",
            title: "请不要重复发送~"
        }) : wx.showToast({
            icon: "none",
            title: "请输入正确的手机号~"
        });
    },
    getCode: function(t) {
        this.setData({
            code: t.detail.value
        });
    },
    untyingBtn: function() {
        var e = this.data.code;
        "" == e ? wx.showToast({
            icon: "none",
            title: "请输入验证码"
        }) : t.relieve({
            uid: wx.getStorageSync("uid"),
            code: e,
            phone: this.data.phone
        }).then(function(t) {
            console.log(t), wx.showToast({
                icon: "none",
                title: t.message
            }), 0 == t.errno && setTimeout(function() {
                wx.switchTab({
                    url: "../mine/mine"
                });
            }, 1e3);
        }).catch(function(t) {
            console.log(t), wx.showToast({
                icon: "none",
                title: t.message
            });
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});