// pages/bound/bound.js import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js' import { UntieDerver, BindConch} from '../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData } = getApp() const { baseImgUrl, thumbnail } = globalData const app = getApp() Page({ /** * 页面的初始数据 */ data: { baseImgUrl, thumbnail, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options) this.setData(options); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { const obj = { navigateTo, redirectTo, navigateBack, viewImage } for (const i in obj) { this[i] = obj[i] } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * 获取定位经纬度 */ getLocation: function () { wx.showLoading({ title: '定位中' }) wx.getLocation({ type: 'wgs84', success: res => { this.setData({ longitude: res.longitude, // '113.36403' || latitude: res.latitude // '23.14203' || }) this.getBindConch() }, fail: res => { wx.showToast({ title: '定位失败', icon: 'none' }) }, complete: res => { wx.hideLoading() } }) }, /** * 获取数据 */ getData: function (cb) { const continuousFn = { fn: this.getData, param: { ...arguments } } const { derver } = this.data UntieDerver({ data: { derver }, continuousFn }).then(res => { wx.showToast({ title: '解绑成功', icon: 'none' }) this.setData({ derver:""}) if (isFn(cb)) cb() }).catch(res => { this.setData({ isLoaded: true }) if (isFn(cb)) cb() }) }, /** * 去绑定 */ getBindConch: function (cb) { const continuousFn = { fn: this.getBindConch, param: { ...arguments } } const { vipId,longitude, latitude } = this.data var that=this wx.scanCode({ onlyFromCamera: true, success: (e) => { console.log(e) // if (e.result.indexOf('https://t.sharingschool.com') != -1) { BindConch({ data: { vipId, qrCode: e.result, longitude, latitude }, continuousFn }).then(res => { const {derver}=this.data; that.setData({derver}) wx.showToast({ title: '绑定成功', icon: 'none' }) if (isFn(cb)) cb() }).catch(res => { this.setData({ isLoaded: true }) if (isFn(cb)) cb() }) // } else { // wx.showToast({ // title: '二维码不正确', // icon: 'none', // duration: 1000 // }) // } } }) } })