| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- // index.js
- let myPro = require("../../../utils/wxRequest.js");
- let util = require("../../../utils/util.js");
- Page({
- data: {
- userInfo: null,
- role: null, // 1为商家
- pageTitle: "我的",
- showHeader: false,
- setBgHeight: getApp().globalData.setBgHeight,
- percentLevel: 0, // 等级进度百分比
- fromToNowDays: '' // 相识天数(当前时间-注册时间)
- },
- onLoad: function (options) {
- // Do some initialize when page load.
- let that = this;
- that.setData({
- role: getApp().globalData.role
- });
- },
- onShow: function () {
- // Do something when page show.
- let that = this;
- that.getUserInfo();
- },
- onReady: function () {
- // Do something when page ready.
- let that = this;
- },
- onHide: function () {
- // Do something when page hide.
- },
- onUnload: function () {
- // Do something when page close.
- },
- onPullDownRefresh: function () {
- // Do something when pull down.
-
- },
- onReachBottom: function () {
- // Do something when page reach bottom.
- },
- onShareAppMessage: function () {
- // return custom share data when user share.
- },
- onPageScroll: function (event) {
- // Do something when page scroll
- let that = this;
- let scrollTop = event.scrollTop;
- if(scrollTop >= that.data.setBgHeight){
- that.setData({
- showHeader: true
- });
- }else{
- that.setData({
- showHeader: false
- });
- }
- },
- onResize: function () {
- // Do something when page resize
- },
- // 页面跳转
- goPage(event){
- let that = this;
- console.log(event)
- let url = event.currentTarget.dataset.url;
- wx.navigateTo({
- url: url
- });
- },
- // 用户信息
- getUserInfo(){
- let that = this;
- myPro.wxRequest("user/v2/userinfo","GET",{}).then(res=>{
- that.setData({
- userInfo: res.result
- });
- // 计算相识天数
- let createStr = res.result.created_at; // 为兼容ios
- let createTimesmap = new Date(createStr.replace(/-/g, "/")).getTime();
- let currentTimesmap = new Date().getTime();
- that.setData({
- fromToNowDays: util.computeDays(createTimesmap,currentTimesmap) + 1 // 从注册当天算第1天
- });
- }).catch(err=>{
- console.log('报错信息',err);
- wx.showToast({
- title: err,
- icon: 'none'
- });
- });
- },
- // 去商家中心
- goShopInfo(){
- wx.navigateTo({
- url: '/pages/shopRole/info/index'
- })
- },
- // 订单
- toOrderList(event){
- let that = this;
- // console.log(event)
- let type = event.currentTarget.dataset.type;
- wx.reLaunch({
- url: '/pages/user/order/list/index?type='+type
- })
- },
- // 去买会员卡
- toVipCard(){
- let that = this;
- wx.navigateTo({
- url: '/pages/user/vipcard/index'
- })
- }
- });
|