// pages/tabber/my/index.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { btnInfo: null, menuList: [ { icon: '/image/my/youhuiquan.png', text: '优惠券', url: '/pages/my/coupon/coupon' }, // { // icon: '/image/my/fenxianghaoyou.png', // text: '分享好友' // }, { icon: '/image/my/dizhiguanli.png', text: '地址管理', url: '/pages/my/address/address' }, // { // icon: '/image/my/fuwuliucheng.png', // text: '服务流程' // }, { // icon: '/image/my/yonghuxieyi.png', // text: '用户协议' // }, // { // icon: '/image/my/lipeixize.png', // text: '理赔细则' // }, { icon: '/image/my/kefurexian.png', text: '客服热线', url:"" } ], active: true, userInfo: "", hasUserInfo: false, code: "", yue:0, one:'', two:'', three:'', four:'', five:'', six:'', inputValue:'', show:false, focus:false, nid: 0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getUser(); if (this.data.active == true) { this.data.menuList.shift() this.setData({ code: wx.getStorageSync('phone'), menuList: this.data.menuList }) } // this.getwallet(); }, onShow(){ this.getBtnInfo() this.getwallet(); }, goqjm(){ let that = this that.setData({ nid: 0, inputValue:'', one:'', two:'', three:'', four:'', five:'', six:'' }) console.log(that.data.nid) wx.scanCode({ onlyFromCamera: true, success (res) { console.log( res.result.substr(1)); var regstr = new RegExp('(^|&|/?)orde_num=([^&|/?]*)', 'i'); var exp = res.result.match(regstr); console.log(exp[2]); that.setData({nid: exp[2]}) that.onClose() } }) }, finish:function(e){ var that=this var val=e.detail.value; this.setData({ one:val.split('')[0]?val.split('')[0]:'', two:val.split('')[1]?val.split('')[1]:'', three:val.split('')[2]?val.split('')[2]:'', four:val.split('')[3]?val.split('')[3]:'', five:val.split('')[4]?val.split('')[4]:'', six:val.split('')[5]?val.split('')[5]:'' }) if(val.length>=6){ that.submitValue() } }, submitValue:function(){ var that=this if(that.data.inputValue=='') return wx.showToast({title: '存衣码不能为空',icon:'none'}) console.log(that.data.inputValue) wx.showLoading() app.api.useApi(app.globalData.baseAppUrl + "api/open_temporary", { temporary_code: that.data.inputValue, device_id:this.data.nid }, "post").then(function (res) { wx.hideLoading(); wx.showToast({title: res.message.msg,icon:'none'}) if (res.code== 200) { that.setData({ show:!that.data.show, inputValue:'', one:'', two:'', three:'', four:'', five:'', six:'' }) wx.showModal({ title: res.message.data.external_cabinet+'号柜门', content: '请尽快取走衣物', showCancel: false, success (ress) { if (ress.confirm) { // console.log('用户点击确定') } } }) } }).catch(function (err) { console.log(222); }) }, onClose(){ this.setData({ show:!this.data.show }) }, getBtnInfo() { this.setData({ btnInfo: app.globalData.btnInfo }) }, toUrl(e) { let url = e.currentTarget.dataset.url wx.navigateTo({ url, }) }, getUserProfile(e) { // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { // this.setData({ // userInfo: res.userInfo, // hasUserInfo: true // }) this.updateUser(res.userInfo); } }) }, getPhoneNumber(e) { let that = this console.log(e) that.setData({ code: e.detail.code, }) var data = { 'mds': wx.getStorageSync('seisson_key'), 'encryptedData': e.detail.encryptedData, 'errMsg': e.detail.errMsg, 'iv': e.detail.iv, 'appid': wx.getAppBaseInfo().host.appId, } app.api.useApi(app.globalData.baseAppUrl+"api/user/getPhoneNumber",data,"post").then((res)=>{ if (res.code == 200) { var phone = res.message.data.phone console.log(phone); if (phone) { that.setData({ code: phone, }) } that.getUser() } }).catch((err)=>{ console.log(err) }) }, getwallet() { var that = this; app.api.useApi(app.globalData.baseAppUrl + "api/wallet", { }, "get").then(function (res) { if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading({ success: (res) => { }, }) }, 2000); } else { console.log(res.message.data); that.setData({ yue: res.message.data.balance, }) } }).catch(function (err) { console.log(222); }) }, updateUser(userinfo){ wx.showLoading({ title: '更新用户信息中', }) var that=this; var userinfo=userinfo; app.api.useApi(app.globalData.baseAppUrl+"api/user",userinfo,"post").then((res)=>{ if(res.code==200){ wx.hideLoading(); that.getUser() }else{ that.updateUser(userinfo) } }).catch((err)=>{ that.updateUser(userinfo) }) }, /** * 获取用户信息 */ getUser(){ var that=this; app.api.useApi(app.globalData.baseAppUrl+"api/user/getUser","","get").then((res)=>{ if(res.code==200){ wx.hideLoading(); that.setData({ userInfo:res.message.data, hasUserInfo:res.message.data.avatar!=""?true:false }) }else{ that.getUser() } }).catch((err)=>{ that.getUser() }) } })