import { userValidate } from "../../service/user"; import { alertInfo, alertSuccess, loadingFunc, wxLogin } from "../../utils/index"; import request from "../../utils/request" const { OK } = request; // pages/handleLogin/index.js Page({ /** * 页面的初始数据 */ data: { phone: "", name: "", parkName: "", park: "", tenementName: "", tenement: "", canBack: true, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const { canBack } = options if (canBack === 'false') { this.setData({ canBack: false }) } }, onChangeName(e) { this.setData({ name: e.detail }) }, onChangePhone(e) { this.setData({ phone: e.detail }) }, onChoosePark(e) { const { data } = e.detail; this.setData({ park: data.id, parkName: data.name }) }, onChooseTenement(e) { const { data } = e.detail; this.setData({ tenement: data.id, tenementName: data.name }) }, callPhone(e) { const { phone } = e.currentTarget.dataset; wx.makePhoneCall({ phoneNumber: phone, }) }, handleSubmit() { const { park, tenement, name, phone } = this.data; if (!park) { alertInfo("请选择园区") return } if (!tenement) { alertInfo("请选择商户") return } if (!phone) { alertInfo("请输入预留手机号") return } if (!name) { alertInfo("请输入你的昵称") return } loadingFunc(async () => { const wxLoginCode = await wxLogin() const { code, message, data } = await userValidate({ park, tenement, phone, name, code: wxLoginCode }) if (code !== OK) { alertInfo(message) return } const { exist, user } = data; if (!exist) { alertInfo("绑定失败,请检查信息") return } alertSuccess("绑定成功") const { token, ...currentUser } = user; wx.setStorageSync('user', currentUser) wx.setStorageSync('token', token) wx.switchTab({ url: '/pages/home/index', }) }) }, scan() { wx.scanCode({ scanType: "qrCode", success: ({ path }) => { wx.navigateTo({ url: '/' + path, }) }, fail: err => { console.log('scan code err', err) alertInfo("扫码失败,请稍后重试") } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })