Sanakey
2021-06-04 355a84d740a2a9dfa1d67cb2d2e11843d42809ac
提交 | 用户 | age
c09e73 1 const app = getApp<IAppOption>();
S 2 Page({
3   data: {
a38dad 4     promotionsData:{} as any,
S 5     doccode:'',
7a3e75 6     formId:'',
a38dad 7     orderKeyword: '',
S 8     ranksKeyword: '',
9     orderListBackup:[],
282d69 10     sellerRankingListBackup:[],
S 11     showShare: false,
f9ad6c 12     searchKey:'',
282d69 13     shareOptions: [
S 14       { name: '微信', icon: 'wechat', openType: 'share' },
15       // { name: '分享海报', icon: 'poster' },
16       // { name: '二维码', icon: 'qrcode' },
17     ],
c09e73 18   },
27d5ae 19   onLoad(options) {
c09e73 20     console.log(app);
27d5ae 21     this.setData({
S 22       doccode:options.doccode,
282d69 23       formId:options.formId,
S 24       themeColor: wx.globalData.themeColor
27d5ae 25     })
f46177 26     wx.globalData.detailSocketCallback = (onMessage:any)=>{
S 27       console.log('活动管理页收到消息 ',onMessage);
28       let msgData = JSON.parse(onMessage.data);
29       let doccode = this.data.doccode;
30       let msg = msgData.info.msg || '';
31       if (doccode === msg){
32         console.log('websocket有新消息,需要更新当前活动状态');
33         this.getPromotionsData();
34       }
35     }
282d69 36   },
S 37   onShow() {
a38dad 38     this.getPromotionsData();
f46177 39   },
S 40   onUnload(){
41     wx.globalData.detailSocketCallback = ()=>{};
c09e73 42   },
d38be7 43   async addGoodsToLive(){
d8c37e 44     let doccode = this.data.promotionsData.doccode||'';
d38be7 45     if (await wx.$commonRequest.addGoodsToLive({
S 46       url:`/shopping/panicBuyingLiveGoods.do?m=add`,
47       data:{
48         doccode
49       }
50     })){
51       this.setData({
52         [`promotionsData.isGoodsInLive`]:true
53       })
54     }
55   },
f9ad6c 56   async orderExport(){
S 57     let [error, result] = await wx.$utils.to(
58       wx.$http.request({
59         url:`/shopping/export/generateExcelFromOrderList.do`,
60         data:{
61           doccode:this.data.promotionsData.doccode,
62           searchKey:this.data.searchKey,
63         }
64       })
65     )
66     if (error){
67       console.log(error);
68       return;
69     }
70     console.log(result);
71     wx.setClipboardData({
72       data: result.downloadUrl,
73       success () {
74         wx.hideToast();
75         // console.log('复制成功');
76         wx.showModal({
77           title:'提示',
78           content: `下载链接已复制,请在电脑浏览器中打开下载(有效期${result.validDays||0}天)。`,
79           showCancel:false
80         })
81       }
82     })
83     // wx.downloadFile({
84     //   url: 'https://mp.onbus.cn/shopping/inquire.pdf',
85     //   success (res) {
86     //     // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
87     //     if (res.statusCode === 200) {
88     //       let tempFilePath = res.tempFilePath;
89     //       wx.saveFile({
90     //         tempFilePath,
91     //         success(res) {
92     //           const savedFilePath = res.savedFilePath;
93     //           console.log('保存地址为',savedFilePath);
94     //           // 打开文件
95     //           wx.openDocument({
96     //             filePath: savedFilePath as any ,
97     //             success() {
98     //               console.log('打开文档成功')
99     //             },
100     //           });
101     //         },
102     //         fail(err) {
103     //           console.log('保存失败:', err)
104     //         }
105     //       });
106     //     }
107     //   }
108     // })
a38dad 109   },
S 110   async getPromotionsData(){
111     let [error, result] = await wx.$utils.to(
112       wx.$http.request({
113         url:`/shopping/panicBuying.do?m=getPanicBuyingSummary`,
114         data:{
115           doccode:this.data.doccode
116         }
117       })
118     )
119     if (error){
120       console.log(error);
121       return;
122     }
123     console.log(result);
124     this.setData({
125       promotionsData: result.list[0],
126       sellerRankingList: result.sellerRankingList,
127       sellerRankingListBackup: result.sellerRankingList,
128       orderList:result.orderList,
129       orderListBackup:result.orderList
130     })
131   },
132
133   async changePanicBuyingStatus(status:any){
134     let promotionsData = this.data.promotionsData;
135     let [error, result] = await wx.$utils.to(
136       wx.$http.request({
137         url:`/shopping/panicBuying.do?m=changePanicBuyingStatus`,
138         data:{
139           doccode:promotionsData.doccode,
140           status
141         }
142       })
143     )
144     if (error){
145       console.log(error);
146       return;
147     }
148     console.log(result);
149     if (result.state=="success"){
150       this.getPromotionsData();
151     }
152
153   },
154
155   continuePromotion(){
156     let promotionsData = this.data.promotionsData;
157     if (promotionsData.isShowContinueButton) {
158       this.changePanicBuyingStatus(2);
159       console.log('继续活动');
160     }
161   },
162   stopPromotion(){
163     let promotionsData = this.data.promotionsData;
164     if (promotionsData.isShowStopButton) {
165       this.changePanicBuyingStatus(3);
166       console.log('停止活动');
167     }
168   },
169
282d69 170   completeGroupBuying(){
S 171     wx.pro.showModal({
172       title: '提示',
173       content: '确定要完成拼团吗?选择确定,拼团将直接成功',
174     }).then((res:any) => {
175       // on close
176       console.log(res);
177       if (res.confirm){
178         console.log('确认');
179         this.completeGroupBuyingRequest();
180       }
181     });
182   },
183   cancelGroupBuying(){
184     wx.pro.showModal({
185       title: '提示',
186       content: '确定要取消拼团吗?选择确定,拼团将直接失败,所有已支付订单将原路退还!',
187     }).then((res:any) => {
188       // on close
189       console.log(res);
190       if (res.confirm){
191         console.log('确认');
f46177 192         this.cancelGroupBuyingRequest();
282d69 193       }
S 194     });
195   },
196
197   async completeGroupBuyingRequest(){
198     let promotionsData = this.data.promotionsData;
7a3e75 199     let formid = this.data.formId;
282d69 200     let [error, result] = await wx.$utils.to(
S 201       wx.$http.request({
202         url:`/shopping/panicBuying.do?m=groupBuyingSuccess`,
203         data:{
7a3e75 204           doccode: promotionsData.doccode,
S 205           formid
282d69 206         }
S 207       })
208     )
209     if (error){
210       console.log(error);
211       return;
212     }
213     console.log(result);
f46177 214     this.getPromotionsData();
282d69 215   },
S 216
217   async cancelGroupBuyingRequest(){
218     let promotionsData = this.data.promotionsData;
7a3e75 219     let formid = this.data.formId;
282d69 220     let [error, result] = await wx.$utils.to(
S 221       wx.$http.request({
222         url:`/shopping/panicBuyingOrder.do?m=doReturnOrderAllByCreator`,
223         data:{
7a3e75 224           doccode: promotionsData.doccode,
S 225           formid
282d69 226         }
S 227       })
228     )
229     if (error){
230       console.log(error);
231       return;
232     }
233     console.log(result);
f46177 234     this.getPromotionsData();
282d69 235   },
S 236
f9ad6c 237   setSearchKey(event:any){
S 238     this.setData({
239       searchKey:event.detail
240     })
241     console.log('关键词',event.detail);
242   },
243
a38dad 244   async onSearchOrder(event:any){
S 245     console.log('准备搜索订单', event.detail);
246     let promotionsData = this.data.promotionsData;
247     let [error, result] = await wx.$utils.to(
248       wx.$http.request({
249         url:`/shopping/panicBuying.do?m=getOrderListForSellerRanking`,
250         data:{
251           doccode: promotionsData.doccode,
252           searchKey: event.detail,
253         }
254       })
255     )
256     if (error){
257       console.log(error);
258       return;
259     }
260     console.log(result);
261     this.setData({
262       orderList:result.orderList
263     })
264   },
265
266   onClearSearchOrder(){
267     console.log(888);
268     this.setData({
269       orderList:this.data.orderListBackup
270     })
271   },
272
273   async onSearchRanks(event:any){
274     console.log('准备搜索排行',event.detail);
f9ad6c 275     // this.setData({
S 276     //   searchKey:event.detail
277     // })
a38dad 278     let promotionsData = this.data.promotionsData;
S 279     let [error, result] = await wx.$utils.to(
280       wx.$http.request({
281         url:`/shopping/panicBuying.do?m=getSellerRankingList`,
282         data:{
283           doccode: promotionsData.doccode,
284           searchKey: event.detail,
285         }
286       })
287     )
288     if (error){
289       console.log(error);
290       return;
291     }
292     console.log(result);
293     this.setData({
294       sellerRankingList:result.sellerRankingList
295     })
296   },
297   onClearSearchRanks(){
298     console.log(999);
299     this.setData({
300       sellerRankingList:this.data.sellerRankingListBackup
301     })
302   },
303
282d69 304   goOrderDetail(event:any){
S 305     let doccode = event.currentTarget.dataset.doccode;
306     let url = `/pages/orderDetail/orderDetail?from=&doccode=${doccode}`
307     wx.navigateTo({
308       url,
309       events: {
310         // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
311         detailCheckCode: (data: any)=> {
312           console.log('选择的商品',data)
313           this.triggerEvent('comeback',data);
314           // console.log(_this,this);
315           // let [errMsg,qrRes] = await this.getPosterQrCode({
316           //   QrCodeType:30,
317           //   matcode: data.goods
318           // });
319           // if (errMsg) {
320           //   return;
321           // }
322           // this.setData({
323           //   qrRes,
324           //   selectedQr:index
325           // })
326         }
327       }
328     })
329   },
330
331   async doHeXiao(event:any){
332     console.log(event);
333     // return false;
334     // let formid = this.data.promotionsData.formId;
335     let doccode = event.currentTarget.dataset.doccode;
336     wx.pro.showModal({
337       title: '提示',
338       content: '确定要核销此订单吗?',
339     }).then((res:any) => {
340       // on close
341       console.log(res);
342       if (res.confirm){
343         console.log('确认');
344         this.checkHXData(doccode);
345       }
346     });
347   },
348   async checkHXData(doccode:string){
349     let [error, result] = await wx.$utils.to(
350       wx.$http.request({
351         url:`/shopping/panicBuyingOrder.do?m=doHeXiao`,
352         data:{
353           doccode
354         }
355       })
356     )
357     if (error){
358       console.log(error);
359       return;
360     }
361     console.log(result);
362     this.onSearchOrder({detail:''});
363   },
364
f46177 365   // async refundRequest(doccode:string,formid:number){
S 366   //
367   //   let [error, result] = await wx.$utils.to(
368   //     wx.$http.request({
369   //       url:`/shopping/panicBuyingOrder.do?m=doReturnOrderByCreator`,
370   //       data:{
371   //         doccode,
372   //         formid,
373   //       }
374   //     })
375   //   )
376   //   if (error){
377   //     console.log(error);
378   //     return;
379   //   }
380   //   console.log(result);
381   //   if (result.state=='success') {
382   //     wx.showToast({title:`${result.message}`})
383   //   }
384   //   // let result = {
385   //   //   "state":"failed",    //成功时,返回 success ,失败时返回 failed
386   //   //   "message":"商家[张三]账户余额[980元]不足以扣除本单退款所需要的金额[1000元],退款失败!",
387   //   //   "isAllowRefund":false ,  //是否允许退款
388   //   //   "serviceCltCode":"200873" ,  //商家编号
389   //   //   "serviceCltName":"张三" ,  //商家名称
390   //   //   "serviceTelephone":"13888888888" ,  //商家电话
391   //   //   "sellerId":1 ,  //营销人员ID
392   //   //   "sellerName":"李四" , //营销人员姓名
393   //   //   "sellerTelephone":"138888888888" , //营销人员电话
394   //   //   "payableAmount":1000 ,  //应退金额
395   //   //   "serviceBalance":980  ,  //商家可退款余额 ; 如果 应退金额  大于 商家可退款余额 手续费,则不能退款
396   //   //   "paidFeeAmount":20  , //应退手续费
397   //   //   "customerCltCode":"200823" ,  //客户编号
398   //   //   "customerCltName":"王五",   //客户名称
399   //   //   "customerTelephone":"1388888888888"   //客户电话
400   //   // }
401   //   if (result.state=='failed'&&result.isAllowRefund===false){
402   //     this.setData({
403   //       refundResult: result,
404   //       isShowDialog:true
405   //     })
406   //   }
407   //   this.onSearchOrder({detail:''});
408   // },
409   // onDialogClose(){
410   //   this.setData({
411   //     isShowDialog:false
412   //   })
413   // },
a38dad 414   async doRefund(event:any){
S 415     console.log(event);
416     let formid = this.data.promotionsData.formId;
f46177 417     let refundDialog = this.selectComponent('#refund-dialog');
S 418     let result = await refundDialog.doRefund(event.currentTarget.dataset,formid);
419     console.log('退款result',result);
420     if (result){
421       setTimeout(() => {
422         this.onSearchOrder({detail:''});
423       },1500)
424     }
425     // return false;
426     // let formid = this.data.promotionsData.formId;
427     // let {doccode,cltname} = event.currentTarget.dataset;
428     // wx.pro.showModal({
429     //   title: '提示',
430     //   content: `确定要退款给[${cltname}]吗?`,
431     // }).then((res:any) => {
432     //   // on close
433     //   console.log(res);
434     //   if (res.confirm){
435     //     console.log('确认');
436     //     this.refundRequest(doccode,formid);
437     //   }
438     // });
a38dad 439   },
S 440
355a84 441   // sellerVerify(){
S 442   //   this.setData({
443   //     showShare:true
444   //   })
445   //   // console.log(getCurrentPages());
446   // },
447   // onShareClose(){
448   //   this.setData({
449   //     showShare:false
450   //   })
451   // },
452   // onShareSelect(event:any) {
453   //   console.log(event.detail);
454   //   this.onShareClose();
455   // },
456   // onShareAppMessage() {
457   //   let doccode:string = this.data.promotionsData.doccode || '';
458   //   // let title:string = this.data.promotionsData.title || '';
459   //   let imageUrl:string = this.data.promotionsData.coverImageUrl || '';
460   //   let sellerUnCheckedNames:string = this.data.promotionsData.sellerUnCheckedNames || '';
461   //   return {
462   //     // title: utils.getShareTitle(),
463   //     title: `请营销人员[${sellerUnCheckedNames}]验证身份`,
464   //     imageUrl,
465   //     path: `pages/sellerVerify/sellerVerify?doccode=${doccode}`,
466   //   }
467   // }
c09e73 468 })
S 469 export {}