const app = getApp(); var http = require("../../utils/http.js"); Page({ /** * 页面的初始数据 */ data: { code: "", check: false, nvabarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: "微信登录", //导航栏 中间的标题 }, // 此页面 页面内容距最顶部的距离 height: app.globalData.height * 2 + 20, picImg: http.picImg }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, // 监听单选 radiocon: function () { this.setData({ check: !this.data.check, }); }, getPhoneNumber(e) { if (!this.data.check) { this.showDialogBtn(); return; } console.log('11111') this.w_login(e.detail.iv, e.detail.encryptedData); }, showDialogBtn: function () { wx.showModal({ content: "请阅读并勾选注册服务协议", showCancel: false, }); }, w_login: function (iv, encryptedData) { var that = this; wx.login({ success: function (res) { if (res.code) { that.setData({ code: res.code, }); that.getPhone(iv, encryptedData); } else { console.log("登录失败!" + res.errMsg); } }, fail: function () { wx.hideLoading(); wx.showModal({ title: "提示", content: "网络连接异常", showCancel: false, }); }, }); }, getPhone: function (ivParameter, enData) { console.log('3333') var that = this; var sessionKey = wx.getStorageSync("sessionKey"); wx.request({ url: app.globalData.devUrl + "/api/v1/cooperation/bindByWx", data: { iv: ivParameter, encryptedData: enData, sessionkey: sessionKey, }, success: function (res) { if (res.data.code == 0) { wx.setStorageSync("phoneSupply", res.data.data.phone); that.Login(res.data.data.phone); } else { // wx.showModal({ // title: '提示', // content: res.data.msg, // showCancel: false, // }) } }, fail: function () { wx.showModal({ title: "提示", content: "网络连接异常", showCancel: false, }); }, }); }, Login: function (phone) { wx.showLoading({ title: "加载中...", }); wx.request({ url: app.globalData.devUrl + "/api/v1/cooperation/login", method: "POST", header: { "content-type": "application/x-www-form-urlencoded", }, data: { phone: phone, weChatId: wx.getStorageSync("weChatId"), }, success: function (res) { wx.hideLoading(); if (res.data.code == 0) { if (res.data.data.state === 0) { wx.showModal({ title: "提示", content: "您的手机号暂未绑定加油站信息", showCancel: false, }); } else { if (res.data.data.cooperations) { wx.setStorageSync("cooperations", res.data.data.cooperations); } if (res.data.data.cooperation) { wx.setStorageSync("cooperation", res.data.data.cooperation); } wx.setStorageSync('kybUser', res.data.data.kybUser) wx.reLaunch({ url: "/pages/oilManage/oilManage", }); } } else { wx.showModal({ title: "提示", content: res.data.msg, showCancel: false, }); } }, error: function (res) { wx.hideLoading(); wx.showModal({ title: "提示", content: res.data.msg, showCancel: false, }); }, fail: function () { wx.hideLoading(); wx.showModal({ title: "提示", content: "网络连接异常", showCancel: false, }); }, }); }, sign: function () { var that = this; if (that.data.check) { wx.navigateTo({ url: "/pages/login/login", }); } else { that.showDialogBtn(); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, });