Sanakey
2021-07-09 3fc241d02fb8b671289de3d9d80bf848349c04d4
提交 | 用户 | age
67dc7b 1 // index.ts
S 2 // 获取应用实例
3dd7c0 3 // import appModule from '../../modules/app';
67dc7b 4 Page({
S 5   data: {
6     userInfo: {},
701f60 7     isFirstOpen:true,
67dc7b 8     hasUserInfo: false,
S 9     canIUse: wx.canIUse('button.open-type.getUserInfo'),
f9ad6c 10     promotionsList:[]
67dc7b 11   },
a3c13b 12   async onLoad(options) {
282d69 13     if (!wx.globalData.OpenId){
3dd7c0 14       wx.globalData.indexCallback = ()=>{
282d69 15         this.setGlobalData();
27d5ae 16         this.getBalance();
f9ad6c 17         this.getPanicBuyingList();
3dd7c0 18       }
282d69 19     } else{
S 20       console.log('不是初次打开首页');
21       this.setGlobalData();
22       this.getBalance();
f9ad6c 23       this.getPanicBuyingList();
3dd7c0 24     }
a3c13b 25     let minHeight = wx.globalData.systemInfo.windowHeight - 325
S 26     console.log('minHeight',minHeight);
27     this.setData({
28       minHeight
29     })
30     setTimeout(()=>{
31       if (options.open) {
32         this.setData({
33           isShowDialog:true
34         })
35       }
36     },1000)
27d5ae 37   },
282d69 38   setGlobalData(){
58c889 39     wx.$utils.setShopName(this);
S 40     wx.$utils.setLoginData(this);
a3c13b 41     // let minHeight = wx.globalData.systemInfo.windowHeight - 365
S 42     // console.log('minHeight',minHeight);
43     this.setData({
44       appVersion: wx.globalData.miniProgramInfo.version,
45       // minHeight
46     })
58c889 47     // let loginData = wx.globalData.loginData;
S 48     // let settings = wx.globalData.settings;
49     // console.log('<<<<<<<<<获取loginData',loginData);
50     // this.setData({
51     //   loginData,
52     // })
53     // wx.setNavigationBarTitle({
54     //   title:settings.name
55     // })
282d69 56   },
S 57   async onShow() {
701f60 58     let isFirstOpen = this.data.isFirstOpen;
S 59     if (!isFirstOpen){
60       console.log('不是第一次打开');
61       this.getBalance();
f9ad6c 62       this.getPanicBuyingList();
a3c13b 63       wx.$utils.setLoginData(this);
701f60 64     }
S 65   },
66   onHide() {
67     this.setData({
68       isFirstOpen:false
69     })
70   },
27d5ae 71   async getBalance(){
S 72     let [error, result] = await wx.$utils.to(
73       wx.$http.request({
701f60 74         url:`/shopping/panicBuyingBalance.do?m=getBalance`,
f207f5 75         isShowLoading:false
67dc7b 76       })
27d5ae 77     )
S 78     if (error){
79       console.log(error);
80       return;
67dc7b 81     }
27d5ae 82     console.log(result);
S 83     this.setData({
84       ...result
85     })
67dc7b 86   },
f9ad6c 87   async getPanicBuyingList(){
S 88     let [error, result] = await wx.$utils.to(
89       wx.$http.request({
90         url:`/shopping/panicBuying.do?m=getPanicBuyingListForHomePage`,
91       })
92     )
93     if (error){
94       console.log(error);
95       return;
96     }
97     console.log(result);
98     this.setData({
99       promotionsList:result.list,
100     })
101   },
282d69 102   authorizeComplete(){
S 103     console.log(999);
104   },
f9ad6c 105   showPromotionLayer(){
S 106     // console.log(111111111111);
107     this.setData({
108       isShowDialog:true
109     })
110   },
111   closeDialog(){
112     this.setData({
113       isShowDialog:false
114     })
67dc7b 115   },
a38dad 116   scanQrCode(){
S 117     wx.scanCode({
118       success: async (res) => {
119         console.log(res)
120         if(res.result){
121           wx.navigateTo({
122             url: `/pages/scanCode/scanCode?qrcode=${res.result}`,
123           })
124         }
125       }
126     })
a3c13b 127   },
3fc241 128   refreshAuthorizeInfo(){
S 129     wx.$utils.setLoginData(this);
130   },
a3c13b 131   onShareAppMessage(){
S 132     return {
133       // title: utils.getShareTitle(),
134       title: ``,
135       imageUrl:'',
136       path: `/pages/index/index`,
137     }
a38dad 138   }
67dc7b 139 })