123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- // pages/person/person.js
- const app = getApp()
- import Order from '../../api/order'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- hasUserInfo: false,
- canWriteOff: 'no'
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: async function () {
- await app.wxLogin({"type":"slince"})
- let userInfo = await app.getWxUserInfo()
- if (userInfo) {
- console.log(userInfo)
- this.setData({
- userInfo: userInfo,
- hasUserInfo: userInfo.avatarUrl.length > 1 ? true :false,
- hasMobile: userInfo.mobile ? true : false
- })
- }
- if (userInfo.mobile) {
- const rs = await Order.writeOffStaff({phone: userInfo.mobile})
- this.setData({
- canWriteOff: rs.canWriteOff
- })
- }
-
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- getInfo: async function () {
- const _self = this
- // let userInfo = e.detail.userInfo
- // userInfo['encryptedData'] = e.detail.encryptedData
- // userInfo['iv'] = e.detail.iv
- let userInfo = {}
- userInfo['type'] = 'userInfo'
- userInfo['openId'] = this.data.userInfo.openId
- wx.getUserProfile({
- desc: '用于完善会员资料',
- success: async (res) =>{
- console.log(res)
- userInfo['encryptedData'] = res.encryptedData
- userInfo['iv'] = res.iv
- let info = await app.wxLogin(userInfo);
- let hasMobile = false;
- if (info.mobile) {
- hasMobile = true
- }
- _self.setData({
- hasUserInfo: true,
- userInfo: info,
- hasMobile: hasMobile,
- })
- }
- })
-
- },
- gotoComment: async function (e) {
- console.log(this)
- const isAuth = await app.isAuth()
- if (!isAuth) {
- wx.redirectTo({
- url: '/pages/prompt/prompt?page=pages/comments/comments',
- })
- return
- }
- wx.navigateTo({
- url: '../comments/comments?title=我的评论&commentstype=my',
- })
- },
- gotoPersonInfo: function (e) {
- wx.navigateTo({
- url: '../personinfo/personinfo',
- })
- },
- gotoOrder: function (e) {
- wx.switchTab({
- url: '../couponList/couponList',
- })
- },
- getMobile: async function (params) {
- console.log(params);
- let _self = this
- const data = {
- encryptedData:params.detail.encryptedData,
- iv: params.detail.iv
- }
- const userInfo = await app.getPhoneNumber(data)
- console.log(userInfo)
- let hasMobile = false
- if (userInfo.mobile > 1) {
- hasMobile:true
- }
- _self.setData({
- hasMobile: hasMobile,
- mobile: userInfo.mobile,
- userInfo
- })
- },
- async gotoMoney() {
- const self = this
- const rs = await wx.scanCode({onlyFromCamera: true, scanType: ['qrCode']})
- const couponInfo = await Order.couponInfo({couponSn: rs.result})
- console.log(couponInfo)
- wx.showModal({
- title: "提示",
- content: '你确定要核销 '+couponInfo['couponName']+' 的优惠券吗?',
- success:async (res) =>{
- if (res.confirm) {
- const data = {
- heXiaoPhone: self.data.userInfo.mobile,
- couponSn: rs.result,
- errMsg: 'modal'
- }
- const writeOff = await Order.writeOffCoupon(data)
- console.log(writeOff)
- wx.showModal({
- title: "提示",
- content: "核销成功"
- })
- }
- }
- })
-
-
- }
- })
|