123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- var util = require('../../../utils/util.js');
- var api = require('../../../config/api.js');
- var user = require('../../../services/user.js');
- var app = getApp();
- // 定义插件变量 引入方法
- const tempUserInfo = {
- nickName: 'Hi,游客',
- userName: '点击去登录',
- avatarUrl: 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png'
- }
- Page({
- data: {
- userInfo: {},
- hasMobile: '',
- imgServer: util.imgServer,
- all: {
- icon: 'ct1',
- name: '全部订单',
- id: -1
- },
- orderList:[
-
- {
- icon: 'ct2',
- name: '待付款',
- id: 0
- },
- {
- icon: 'ct3',
- name: '待发货',
- id: 201
- },
- {
- icon: 'ct4',
- name: '待收货',
- id: 300
- },
- {
- icon: 'ct5',
- name: '已完成',
- id: 301
- }
- ],
- barList:[
- {
- icon: 'cb1',
- url: '/pages/ucenter/collect/collect',
- name: '我的收藏',
- id: 0
- },
- {
- icon: 'cb2',
- url: '/pages/ucenter/footprint/footprint',
- name: '我的足迹',
- id: 1
- },
- {
- icon: 'cb3',
- url: '/pages/ucenter/feedback/feedback',
- name: '意见反馈',
- id: 2
- }
- ],
- relatedGoods: [],
- isLogin: app.globalData.isLogin
- },
- getGoodsRelated: function () {
- let that = this;
- util.request(api.GoodsRelated, {}).then(function (res) {
- if (res.errno === 0) {
- that.setData({
- relatedGoods: res.data.goodsList,
- });
- }
- });
- },
-
- tapByIdx:function(e){
- let {
- url
- } = e.currentTarget.dataset;
- console.log(app.globalData)
- if (this.data.isLogin) {
- wx.navigateTo({
- url: url,
- success: function (res) { },
- fail: function (res) { },
- complete: function (res) { },
- })
- } else {
- wx.navigateTo({
- url: '/pages/auth/btnAuth/btnAuth',
- })
- // wx.showModal({
- // title: '提示',
- // content: '请登录后查看',
- // showCancel: false,
- // confirmColor: '#1fe4dc',
- // success: res=>{
- // }
- // });
- }
- },
- onLoad: function (options) {
- // 页面初始化 options为页面跳转所带来的参数
- this.getGoodsRelated()
-
- },
- onReady: function () {
- },
- onShow: function () {
- let userInfo = wx.getStorageSync('userInfo');
- let token = wx.getStorageSync('token');
- // 页面显示
- if (userInfo && token) {
- app.globalData.userInfo = userInfo;
- app.globalData.token = token;
- }
- this.setData({
- userInfo: app.globalData.userInfo,
- token: app.globalData.token
- });
- util.request(api.CartList).then((res) => {
- let isLogin = false
- if (res.errno === 401) {
- isLogin = false
- app.globalData.userInfo = tempUserInfo;
- app.globalData.token = '';
- } else {
- isLogin = true
- app.globalData.userInfo = userInfo;
- app.globalData.token = token;
- }
- if (!isLogin){
- this.setData({
- token:'',
- userInfo: tempUserInfo
- });
- }
- this.setData({
- isLogin
- });
- });
- if (typeof this.getTabBar === 'function' && this.getTabBar()) {
- this.getTabBar().setData({
- selected: 3
- })
- }
- },
- onPullDownRefresh() {
-
- },
- onHide: function () {
- // 页面隐藏
- },
- onUnload: function () {
- // 页面关闭
- },
- bindGetUserInfo(e) {
- let userInfo = wx.getStorageSync('userInfo');
- let token = wx.getStorageSync('token');
- if (userInfo && token) {
- return;
- }
- if (e.detail.userInfo){
- //用户按了允许授权按钮
- user.loginByWeixin(e.detail).then(res => {
- this.setData({
- userInfo: res.data.userInfo,
- isLogin: true
- });
- app.globalData.userInfo = res.data.userInfo;
- app.globalData.token = res.data.token;
-
- }).catch((err) => {
- this.setData({
- token: '',
- userInfo: tempUserInfo
- });
- app.globalData.userInfo = tempUserInfo;
- app.globalData.token = '';
- console.log(err)
- });
- } else {
- //用户按了拒绝按钮
- // wx.showModal({
- // title: '温馨提示',
- // content: '您点击了"取消"授权,将无法获取四维线上博览会完整服务。请“授权”以保证各项功能正常使用。',
- // confirmText:'授权',
- // success: function (res) {
- // if (res.confirm) {
- // wx.openSetting({
- // success: (res) => {
- // if (res.authSetting["scope.userInfo"]) {////如果用户重新同意了授权登录
- // user.loginByWeixin(e.detail).then(res => {
- // this.setData({
- // userInfo: res.data.userInfo
- // });
- // app.globalData.userInfo = res.data.userInfo;
- // app.globalData.token = res.data.token;
- // }).catch((err) => {
- // console.log(err)
- // });
- // }
- // }
- // })
- // }
- // }
- // });
- }
- },
- exitLogin: function () {
- wx.showModal({
- title: '',
- confirmColor: '#b4282d',
- content: '退出登录?',
- success: function (res) {
- if (res.confirm) {
- wx.removeStorageSync('token');
- wx.removeStorageSync('userInfo');
- wx.switchTab({
- url: '/pages/index/index'
- });
- }
- }
- })
- }
- })
|