const app = getApp() var http = require("../../utils/http.js"); Page({ /** * 页面的初始数据 */ data: { phone: "", password: "", _num: 1, codeDis: true, phoneCode: "验证码", nvabarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: '登录', //导航栏 中间的标题 }, // 此页面 页面内容距最顶部的距离 height: app.globalData.height * 2 + 20, picImg:http.picImg }, 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, }); }, }); }, getPhoneNumber(e) { this.w_login(e.detail.iv, e.detail.encryptedData); }, getPhone: function (ivParameter, enData) { 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 { console.log(1111,res.data) if(res.data.cooperations){ wx.setStorageSync("cooperations", res.data.cooperations); } if(res.data.data.cooperation){ wx.setStorageSync("cooperation", res.data.data.cooperation); } 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, }); }, }); }, phoneinput(e) { let value = e.detail.value this.setData({ telephone: value }) }, codeinput(e) { let value = e.detail.value this.setData({ codePhone: value }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, //获取用户输入 phone: function (e) { this.setData({ phone: e.detail.value }) }, password: function (e) { this.setData({ password: e.detail.value }) }, getMa: function (e) { var that = this; if (that.data.phoneCode == '验证码' || that.data.phoneCode == 0) { if (!that.data.phone) { wx.showModal({ title: '提示', content: '请输入手机号', showCancel: false, }) return; } wx.showLoading({ title: '加载中....', }); wx.request({ type: "POST", header: { "Content-Type": "application/json" }, url: app.globalData.devUrl + "/api/v1/cooperation/register/code", data: { phone: that.data.phone, }, error: function (data) { wx.hideLoading() wx.showToast({ title: '呜呜呜,出问题了' }); that.setData({ phoneCode: "", codeDis: false }) }, success: function (data) { wx.hideLoading() if (data.data.code == 0) { wx.showToast({ title: '请查收短信' }); that.setData({ phoneCode: 60, codeDis: true }) let time = setInterval(() => { let phoneCode = that.data.phoneCode phoneCode-- that.setData({ phoneCode: phoneCode }) if (phoneCode == 0) { clearInterval(time) that.setData({ phoneCode: "验证码", codeDis: false }) } }, 1000) } else { wx.showToast({ title: data.data.msg }); } }, fail: function (data) { wx.showModal({ title: '提示', content: '网络传输异常', showCancel: false, }) } }); } }, loginIn: function () { console.log('25555') var that = this; if (that.data.phone == "" || that.data.password == "") { wx.showModal({ title: '提示', content: '请检查输入项', showCancel: false, }) return; } var phone = that.data.phone; var password = that.data.password; wx.showLoading({ title: '加载中....', }); wx.request({ url: app.globalData.devUrl + "/api/v1/cooperation/login", header: { 'content-type': 'application/x-www-form-urlencoded' }, method: "POST", data: { phone: phone, code: password, role: 1, weChatId: wx.getStorageSync("weChatId"), paltform: 2, }, 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 (data) { wx.showModal({ title: '提示', content: '网络传输异常', showCancel: false, }) } }) } })