Sanakey
2021-06-04 355a84d740a2a9dfa1d67cb2d2e11843d42809ac
提交 | 用户 | age
d34532 1 const app = getApp<IAppOption>();
S 2 Page({
3   data: {
f207f5 4     isFirstOpen:true,
d34532 5     isLoading: true,
282d69 6     noticeText:'',
27d5ae 7     doccode:'',
d34532 8     detail: {
27d5ae 9     } as any,
S 10     sellerList:[]
d34532 11   },
S 12   onLoad(options) {
13     console.log(app);
f46177 14     console.log('商品详情页链接参数',options);
27d5ae 15     this.setData({
S 16       fromPage:options.from,
f46177 17       doccode:options.doccode||'',
27d5ae 18     });
f207f5 19     if (!wx.globalData.OpenId){
S 20       wx.globalData.indexCallback = ()=>{
f46177 21         console.log('初次打开小程序,直接进入详情页');
355a84 22         wx.$commonRequest.getPromotionsDetails(this);
f207f5 23       }
S 24     } else{
f46177 25       console.log('不是初次打开小程序,其他页面进入详情页');
355a84 26       wx.$commonRequest.getPromotionsDetails(this);
f46177 27     }
S 28     wx.globalData.detailSocketCallback = (onMessage:any)=>{
29       console.log('商品详情页收到消息 ',onMessage);
30       let msgData = JSON.parse(onMessage.data);
31       let doccode = this.data.doccode;
32       let msg = msgData.info.msg || '';
33       if (doccode === msg){
34         console.log('websocket有新消息,需要更新当前商品状态');
355a84 35         wx.$commonRequest.getPromotionsDetails(this);
f46177 36       }
f207f5 37     }
701f60 38     // if (options.from === 'myOrder') {
S 39     //   this.getOrderDetail();
40     // } else{
d38be7 41
701f60 42     // }
d34532 43     console.log(this.data.noticeText);
d38be7 44   },
S 45   onShow() {
f207f5 46     let isFirstOpen = this.data.isFirstOpen;
S 47     if (!isFirstOpen){
48       console.log('不是第一次打开');
355a84 49       wx.$commonRequest.getPromotionsDetails(this)
f207f5 50     }
S 51   },
52   onHide() {
53     this.setData({
54       isFirstOpen:false
55     })
f46177 56   },
S 57   onUnload(){
58     wx.globalData.detailSocketCallback = ()=>{};
d34532 59   },
355a84 60   // async getDetails() {
S 61   //   let doccode = this.data.doccode;
62   //   let [error, result] = await wx.$utils.to(
63   //     wx.$http.request({
64   //       url:`/shopping/panicBuying.do?m=getPanicBuyingDetail`,
65   //       data:{
66   //         doccode,
67   //         isEdit:false,
68   //         RefOpenId:wx.globalData.FromOpenId
69   //       }
70   //     })
71   //   )
72   //   if (error){
73   //     console.log(error);
74   //     return;
75   //   }
76   //   console.log(result);
77   //   this.setData({
78   //     detail: result.list[0],
79   //     [`detail.coverImageUrl`]:[result.list[0].coverImageUrl],
80   //     isLoading: false,
81   //     sellerList:result.sellerList
82   //   });
83   //   wx.globalData.FromOpenId = result.list[0].lastReferralsOpenId || '';
84   // },
a38dad 85
282d69 86   async onCountDownFinish(){
355a84 87     // await wx.$commonRequest.getPromotionsDetails(this);
282d69 88     // let goodsAction = this.selectComponent('#goods-action');
S 89     // goodsAction.getNotice();
90   },
91
a38dad 92   async sendShareRecord(){
S 93     let [error, result] = await wx.$utils.to(
94       wx.$http.request({
95         url:`/shopping/panicBuying.do?m=saveSharedTraceRecord`,
96         data:{
97           doccode: this.data.doccode
98         }
99       })
100     )
101     if (error){
102       console.log(error);
103       return;
104     }
105     console.log(result);
106   },
107   onShareAppMessage() {
108     this.sendShareRecord();
282d69 109     let FromUserId:string= wx.globalData.FromUserId || '';
S 110     let FromOpenId:string = wx.globalData.FromOpenId||'';
111     let doccode:string = this.data.doccode||'';
355a84 112     let price:string = this.data.detail.salesPrice||'0';
f9ad6c 113     let detail:any = this.data.detail as any||{};
S 114     let sellerList:any = this.data.sellerList[0] as any||[];
355a84 115     let imageUrl:string = '';
S 116     let path = `pages/detail/detail?FromUserId=${FromUserId}&FromOpenId=${FromOpenId}&OpenFrom=fromShare&doccode=${doccode}`;
117     let title = `【¥${price}】${sellerList.sellerName||''}邀请您参加${detail.formName||'活动'} · ${detail.title||''}`;
118     if (!detail.panicBuyingStatus) {
119       path = `/pages/error/error?doccode=${doccode}`;
120       title = '该活动尚未发布';
121       imageUrl = '/assets/images/wen-xin-tips.png';
122     }
a38dad 123     return {
355a84 124       title,
S 125       imageUrl,
a38dad 126       // title: utils.getShareTitle(),
355a84 127       path,
a38dad 128     }
27d5ae 129   }
S 130
d34532 131 });
S 132 export {};