// pages/handleLogin/index.js import { userValidate } from "../../service/user"; import { alertInfo, alertSuccess, loadingFunc, wxLogin } from "../../utils/index"; import request from "../../utils/request" const { OK } = request; Page({ /** * 页面的初始数据 */ data: { phone: "", name: "", parkName: "", park: "", tenementName: "", tenement: "", canBack: true, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, 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("扫码失败,请稍后重试") } }) }, })