|
- // pages/personalCenter/personalCenter.js
-
- const app = getApp()
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- myTicketArrows: true,
- historyTicketArrows: false,
- getUser:false,
- getUserArr: [],//用户信息
- userChuan:[],
- userPhone:"",//用户手机号
- mydeg: 0,
- historydeg: -90,
- pageNum:1,
- pageCount:5,
- historyArr: [],//优惠券使用记录列表
- getHistory: [],//每次接口拉取的数据
- getHistoryArr: [],//全部使用数据
- myTicketArr: [],//我的优惠券列表
- headerImg:"../images/headerImg.png",//默认头像
- userName:"",//昵称
- noUser:false,
- topNum:0,
- showCode:false,//显示二维码
- codeUrl:""//身份码地址
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- },
- getIDCode:function(){//获取身份码
- app.wxRequest(app.globalData.httpUrl + 'front/user/usercode', {}, e => {
- if (e.code == 202) {
- this.setData({
- codeUrl: e.data.user_code_url
- })
- }
- setTimeout(()=>{
- this.getIDCode()
- },10000)
- console.log(this.data.codeUrl)
- }, this)
- },
- getToRsgisterFn:function(){//未注册点击跳到注册页
- var state = wx.getStorageSync('state');
- if(state==0){
- wx.navigateTo({
- url: '/pages/register/register',
- })
- }
- },
- myTicket:function(){//获取用户待使用代金券、菜品券数量
- app.wxRequest(app.globalData.httpUrl + 'front/buy/typenum', {}, e => {
- console.log(e)
- if (e.code == 200) {
- this.setData({
- myTicketArr: e.data
- })
- }
- }, this)
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.setData({
- topNum:0
- })
- this.data.pageNum = 1;
- this.data.getHistoryArr = [];
- if (app.globalData.openId) {
- this.myTicket();
- } else {
- app.globalData.openidSuccessFuc = this.myTicket;
- }
- if (!this.data.getUser) {
- var state = wx.getStorageSync('state');
- if (state == 1) {//已注册
- var userInfo = wx.getStorageSync('userInfo');
- var phone = wx.getStorageSync('user_phone');
- if (!userInfo.avatarUrl){
- this.setData({
- headerImg: "../images/headerImg.png",
- userName: userInfo.nickName,
- userPhone: phone,
- getUserArr:userInfo,
- getUser: true
- })
- console.log(this.data.getUserArr)
- }else{
- this.setData({
- headerImg: userInfo.avatarUrl,
- userName: userInfo.nickName,
- userPhone: phone,
- getUserArr:userInfo,
- getUser: true
- })
- }
- console.log(wx.getStorageSync('noUser'))
- if (wx.getStorageSync('noUser')==0) {
- this.setData({
- noUser: true
- })
- } else if (wx.getStorageSync('noUser') == 1) {
- this.setData({
- noUser: false
- })
- }
- } else if (state == 0) {//未注册
- console.log(app.globalData.noUser)
- this.setData({
- getUser: false,
- noUser: false
- })
- } else if (state == -1) {
- app.globalData.userInfoBackFn = res => {//等待结果
- console.log(res)
- if (res) {
- var userInfo = wx.getStorageSync('userInfo');
- var phone = wx.getStorageSync('user_phone');
- if (!userInfo.avatarUrl) {
- this.setData({
- headerImg: "../images/headerImg.png",
- userName: userInfo.nickName,
- userPhone: phone,
- getUserArr:userInfo,
- getUser: true
- })
- } else {
- this.setData({
- headerImg: userInfo.avatarUrl,
- userName: userInfo.nickName,
- userPhone: phone,
- getUserArr:userInfo,
- getUser: true
- })
- }
- if (wx.getStorageSync('noUser') == 0) {
- this.setData({
- noUser: true
- })
- } else if (wx.getStorageSync('noUser') == 1) {
- this.setData({
- noUser: false
- })
- }
-
- } else {
- this.setData({
- getUser: false,
- noUser: false
- })
- }
- }
- }
- }
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: "老门框爆肚会员",
- success: res => {
- console.log(res, "转发成功")
- },
- }
- },
- lookMyTicket:function(e){
- var index = e.currentTarget.dataset.index;
- wx.navigateTo({
- url: '../myReplace/myReplace?index='+index
- })
- },
-
- lookTicket: function (e) {//查看优惠券
- console.log(e)
- var id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: '../TicketDetails/TicketDetails?id=' + id,
- })
- },
- giveTicket:function(e){//赠送优惠券
- var id = e.target.dataset.id;
- wx.navigateTo({
- url: '../givePage/givePage?id=' + id,
- })
- },
- getUser:function(e){//点击登陆获取用户信息
- console.log(e)
- if (e.detail.userInfo) {
- this.data.userChuan = e.detail.userInfo;
- wx.setStorageSync('noUser', 1);
- wx.setStorageSync("userInfo", e.detail.userInfo)
- this.setData({
- headerImg: e.detail.userInfo.avatarUrl,
- userName: e.detail.userInfo.nickName,
- getUser: true,
- noUser: false
- })
- this.submitUser();
- }
- },
- submitUser: function () {//提交用户信息
- if (this.data.userChuan) {
- var params = {
- "province": this.data.userChuan.province,
- "language": this.data.userChuan.language,
- "city": this.data.userChuan.city,
- "gender": this.data.userChuan.gender,
- "nickname": this.data.userChuan.nickName,
- "headimgurl": this.data.userChuan.avatarUrl,
- }
- app.wxRequest(app.globalData.httpUrl + 'submit', params, e => {
- console.log(e)
- if (e.code == 200) {
-
- }
- }, this, "POST")
- }
-
- },
- showFn:function(){//显示二维码
- this.getIDCode();
- this.setData({
- showCode:true
- })
- },
- hiddenCode:function(){//隐藏二维码
- this.setData({
- showCode:false
- })
- },
- skipScore:function(){//跳转到积分页面
- wx.navigateTo({
- url:"../addScore/addScore"
- })
- }
- })
|