Sanakey
2022-10-24 c891bc5ff6b03baf28a9eac7f5a14ade4cea3c23
提交 | 用户 | age
d98d05 1 // pages/order/order.js
S 2 var listData = require('../../data/test-data.js');
3 var utils = require("../../utils/util.js");
4 var app = getApp();
5 var that;
6 let isUsingCoupon = false;
0da8db 7 let selectedCartIds = '';
d98d05 8 // var pointData = {
S 9 //   sum: 1000,
10 //   canUse: 100,
11 //   isUse: false
12 // };
13 // var userData = {
14 //   balance: 1000
15 // }
16 Page({
17   data: {
18     oldTotalMoney: 0,
19     showAddr: false,
20     showAddAddr: true,
21     totalMoney: 0,   // 合计金额
22     sumMoney:0,
23     date: "",
24     showHidelayer:false,
25     voucherCost:-1,
26     deliveryMethodIndex:0,
08a33d 27     minPreSendDate: Math.round(new Date().getTime()/60000)*60000,
S 28     PreSendDateTime:0,
29     PreSendDate:'',
c43500 30     isShowPreSendDate: true,
08a33d 31     formatter(type, value) {
S 32       // console.log(type,value)
33       if (type === "year") {
34         return `${value}年`;
35       } else if (type === "month") {
36         return `${value}月`;
37       } else if (type === "day") {
38         return `${value}日`;
39       }
40       return value;
41     },
d98d05 42     // 发票信息
S 43     invoice: [
44       {
45         id: 0,
46         name: '不要发票'
47       },
48       {
49         id: 1,
50         name: '纸质发票--个人'
51       },
52       {
53         id: 2,
54         name: '纸质发票--企业'
55       },
56       {
57         id: 3,
58         name: '电子发票--个人'
59       },
60       {
61         id: 4,
62         name: '电子发票--企业'
63       }
64     ],
65     // 积分信息
66     // point: {
67     //   sum: pointData.sum,
68     //   canUse: pointData.canUse,
69     //   offMoney: parseInt(pointData.canUse / 100),
70     //   isUse: pointData.isUse
71     // },
72     // 个人余额
73     Balance:0,
74     clientHeight: "100%",
75     overflow: "auto",
76     isSelected: true, //优惠券默认选中不使用
77     isSelected2: true, //积分默认选中不使用
78     isChecked: false,  //默认不选择余额支付
79     id: -1,  // 优惠券栏默认不使用
80     pointId: -1,  // 积分栏默认显示不使用
81     offLast: 0,  //上个折扣值
245dd6 82     newMsg: '',
S 83     isFirstShow: true, //第一次进入当前页
08a33d 84     remark:''
245dd6 85   },
S 86   onHide(){
87     this.setData({
88       isFirstShow: false
89     })
90     console.log('隐藏页面、、、', this.data.isFirstShow);
53cc6f 91
d98d05 92   },
S 93   onShow() {
94     console.log(getCurrentPages())
53cc6f 95
S 96
a50a5b 97     if (!this.data.isFirstShow) {
245dd6 98       console.log('非第一次显示页面、、、', this.data.isFirstShow);
087175 99
245dd6 100       this.getOrderData();
f2daa4 101       // this.getAddressList();
245dd6 102     }
d98d05 103
53cc6f 104
d98d05 105     // // 显示对方发来的最新消息
S 106     // app.globalData.newMsgCallback = onMessage => {
107     //   console.log('订单页监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data))
108     //   utils.msgTimer(that);
109     // }
110     // // 页面显示时更新未读消息的值
111     // utils.refreshUnreadMsgNum(this);
112
113     // wx.request({
114     //   url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
115     //   header: {
116     //     "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
117     //   },
118     //   success: res => {
119
120     //     // if (res.data.cltcode == "") {
121     //     //   wx.navigateTo({
122     //     //     url: '../login/login',
123     //     //   })
124     //     //   return false;
125     //     // }
126     //     wx.hideLoading();
127     //     utils.requestError(res);
128
129     //     this.setData({
130     //       Address: res.data.Address
131     //     })
132     //   },
133     //   fail: function (errmsg) {
134     //     utils.requestFail(errmsg,'/shopping/confirm.do');
135     //   }
136     // })
137
245dd6 138     // wx.request({
S 139     //   url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
140     //   header: {
141     //     "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
142     //   },
143     //   success: res => {
144     //     wx.hideLoading();
145     //     if(!utils.requestError(res)){
146     //       return false;
147     //     }
d98d05 148
245dd6 149     //     this.setData({
S 150     //       Address: res.data.Address,
151     //     })
d98d05 152
245dd6 153     //   },
S 154     //   fail: function (errmsg) {
155     //     utils.requestFail(errmsg, '/shopping/confirm.do');
156     //   }
157     // })
d98d05 158   },
S 159
0da8db 160   refresh(){
S 161     console.log('电话头像授权完成');
a50a5b 162     this.getOrderData();
f2daa4 163     // this.getAddressList();
0da8db 164   },
d98d05 165
S 166
167   /**
168      * 生命周期函数--监听页面初次渲染完成
169      */
170   onReady: function () {
171
172   },
173
174   // 获取地址
175   getAddress() {
176     wx.navigateTo({
177       url: '../addressList/addressList?way=select'
178     })
179   },
a50a5b 180   getAddressList() {
d98d05 181     wx.request({
a50a5b 182       url: utils.getUrl('/shopping/confirm.do?m=getConfirmAddress'),
d98d05 183       header: {
S 184         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
185       },
186       success: res => {
187         wx.hideLoading();
188         if(!utils.requestError(res)){
189           return false;
190         }
191
192         this.setData({
193           Address: res.data.Address,
a50a5b 194           deliveryMethod: res.data.FreeList
S 195         })
196         let Address = res.data.Address;
197         if (Address&&Address.TransDistance) {
198           let distance = Address.TransDistance>1000?(Address.TransDistance/1000).toFixed(1)+'km': Address.TransDistance + 'm'
199           this.setData({
200             ['Address.TransDistance']: distance
201           })
202         }
203
204       },
205       fail: function (errmsg) {
206         utils.requestFail(errmsg, '/shopping/confirm.do?m=getConfirmAddress');
207       }
208     })
209   },
210   getOrderData(){
211     wx.showLoading({
212       title: '加载中',
213     });
214     let url = '';
215     let quantity=this.data.quantity;
216     let matcode=this.data.matCode;
217     let data = {};
218     if (selectedCartIds){
f2daa4 219       url = '/shopping/confirm.do?m=getConfirmInfo&selectedCartIds='+selectedCartIds;
S 220       data={
221         points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
222       }
a50a5b 223     } else{
S 224       let skuIds = this.data.skuIds;
225       url = `/shopping/confirm.do?m=getConfirmInfo&matcode=${matcode}&quantity=${quantity}`
226       data={
227         ...skuIds
228       }
229     }
230     wx.request({
231       url: utils.getUrl(url),
232       header: {
233         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
234       },
235       data,
236       success: res => {
237         wx.hideLoading();
238         if(!utils.requestError(res)){
239           return false;
240         }
241
242         this.setData({
f2daa4 243           Address: res.data.Address,
d98d05 244           totalMoney: res.data.PayAmount,
S 245           CartList: res.data.CartList,
246           CouponList: res.data.CouponList,
247           PointsTimesList: res.data.PointsTimesList,
248           Points: res.data.UserPoints,
249           Balance: res.data.Balance,
250           CurrencySign: res.data.CurrencySign,
251           PreSendDate: res.data.PreSendDate,
252           balance2: res.data.Balance,
253           isAllowPayable:res.data.isAllowPayable,
245dd6 254           VoucherAmount:res.data.VoucherList.VoucherAmount || 0,
c43500 255           deliveryMethod: res.data.FreeList,
d98d05 256         })
c43500 257         if (res.data.PreSendDate) {
S 258           console.log('更新最小送货时间',res.data.PreSendDate);
259           this.setData({
260             minPreSendDate: Math.round(new Date(res.data.PreSendDate).getTime()/60000)*60000
261           })
262         }
f2daa4 263         let Address = res.data.Address;
S 264         if (Address&&Address.TransDistance) {
265           let distance = Address.TransDistance>1000?(Address.TransDistance/1000).toFixed(1)+'km': Address.TransDistance + 'm'
d98d05 266           this.setData({
f2daa4 267             ['Address.TransDistance']: distance
d98d05 268           })
S 269         }
f2daa4 270         // if (res.data.Balance>0){
S 271         //   this.setData({
272         //     isChecked:true
273         //   })
274         // }
d98d05 275         if(res.data.CouponList.length>0){
S 276           this.setData({
277             id:0,
278           })
279         }
a50a5b 280         if (selectedCartIds){
S 281           isUsingCoupon=true;
282         }
283
d98d05 284
S 285       },
286       fail: function (errmsg) {
287         utils.requestFail(errmsg, '/shopping/confirm.do');
288       }
289     })
290   },
53cc6f 291
0da8db 292   onLoad(options) {
S 293     selectedCartIds = options.selectedCartIds;
53cc6f 294     if (selectedCartIds){
S 295       // let deliveryMethod = app.globalData.deliveryMethod&&app.globalData.deliveryMethod.split(';');
296       this.setData({
297         CouponStatus:app.globalData.CouponStatus,
298         VoucherStatus:app.globalData.VoucherStatus,
c43500 299         isShowPreSendDate:app.globalData.isShowPreSendDate
53cc6f 300       })
S 301       // console.log('进入order页',deliveryMethod,this.data.isAllowSelectDeliveryMethod)
302       this.getOrderData();
f2daa4 303       // this.getAddressList();
53cc6f 304     }
a50a5b 305
d98d05 306     this.setData({
S 307       RewardStatus:app.globalData.RewardStatus,
308       isAllowSelectDeliveryMethod:app.globalData.isAllowSelectDeliveryMethod,
f2daa4 309       startingPointForRedemption:app.globalData.startingPointForRedemption,
S 310       isStartupBalancePay:app.globalData.isStartupBalancePay,
d98d05 311     })
f2daa4 312     if (app.globalData.isStartupBalancePay==1){
S 313       this.setData({
314         isChecked:true
315       })
316     }
53cc6f 317     console.log(options);
S 318     let eventChannel = this.getOpenerEventChannel();
319     eventChannel.on('getSelectedGoods', (res)=>{
320       console.log('566',res);
321       this.setData({
322         ...res
323       })
a50a5b 324       this.getOrderData();
f2daa4 325       // this.getAddressList();
53cc6f 326     });
d98d05 327
S 328   },
329   // 日期选择器
08a33d 330   // bindDateChange: function (e) {
S 331   //   this.setData({
332   //     date: e.detail.value,
333   //     PreSendDate: e.detail.value
334   //   })
335   // },
336   showPreSendDatePopup(){
d98d05 337     this.setData({
08a33d 338       isShowPreSendDatePopup: true
d98d05 339     })
08a33d 340   },
S 341   onPreSendDatePopupClose(){
342     this.setData({
343       isShowPreSendDatePopup: false
344     })
345   },
346   onEnterPreSendDate(event) {
347     let detail = event.detail;
348     const dateTime = utils.formatTime(event.detail);
349     console.log("选择交货时间", dateTime,detail);
350     this.setData({
351       PreSendDate: dateTime,
352       PreSendDateTime: detail
353     });
354     this.onPreSendDatePopupClose();
355   },
356   onInputPreSendDate() {},
357   onCancelPreSendDate() {
358     this.onPreSendDatePopupClose();
d98d05 359   },
S 360   // 发票选择
361   // bindPickerChange: function (e) {
362   //   this.setData({
363   //     index: e.detail.value
364   //   })
365   // },
366
367
368   // 积分按钮
369   pointUseTap: function () {
370
371     if (this.data.isShow) {
372       this.hideLayer2();
373     }
374     else {
375       this.showLayer2();
376     }
377   },
378
379   // 余额按钮
380   balanceTap: function () {
381     var check = this.data.isChecked;
382     check = !check;
383     this.setData({
384       isChecked: check
385     })
386
387     if(this.data.isChecked){
388       this.setData({
389         Balance: this.data.balance2
390       })
391     } else{
392       this.setData({
393         Balance: 0
394       })
395     }
a50a5b 396     let data = {};
S 397     if (selectedCartIds){
398       data = {
399         couponCode: this.data.id == -1 ? "" : this.data.CouponList[this.data.id].CouponCode,
400           points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
401           balance: this.data.Balance,
402           isUsingCoupon,
403           selectedCartIds
404       }
405     } else{
406       data = {
407         couponCode:'',
408         points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
409         balance: this.data.Balance,
410         isUsingCoupon:false,
411         quantity: this.data.quantity,
412         matcode: this.data.matCode,
413         ...this.data.skuIds,
414       }
415     }
d98d05 416     wx.showLoading();
S 417     wx.request({
418       url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
419       header: {
420         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
421       },
a50a5b 422       data,
d98d05 423       success: res => {
S 424         wx.hideLoading();
425         if(!utils.requestError(res)){
426           return false;
427         }
428
429         this.setData({
430           totalMoney: res.data.PayAmount,
431           CartList: res.data.CartList,
432           CouponList: res.data.CouponList,
433           PointsTimesList: res.data.PointsTimesList,
434           Points: res.data.UserPoints,
435           Balance: res.data.Balance,
436           PreSendDate: res.data.PreSendDate
437         })
438
439       },
440       fail: function (errmsg) {
441         utils.requestFail(errmsg,'/shopping/confirm.do');
442       }
443     })
444   },
445
446
447
448   // 优惠券栏点击
449   ticketTap: function () {
450     if (this.data.isShow) {
451       this.hideLayer();
452     }
453     else {
454       this.showLayer();
455     }
456   },
457
458 // 选择优惠券
459   ticketItemTap: function (e) {
53cc6f 460
d98d05 461     // 页面显示优惠券选择状态
S 462     var id = parseInt(e.detail.value);
463     this.setData({
464       id: id
465     })
466
467     if (id == -1) {
468       this.setData({
469         isSelected: true
470       })
471       isUsingCoupon=false;
472     } else {
473       this.setData({
474         isSelected: false
475       })
476       isUsingCoupon=true;
477     }
478
479
480     this.hideLayer();
481
482     wx.showLoading();
483     wx.request({
484       url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
485       header: {
486         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
487       },
488       data: {
489         couponCode: this.data.id == -1 ? "" : this.data.CouponList[this.data.id].CouponCode,
490         points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
491         balance: this.data.Balance,
087175 492         isUsingCoupon,
S 493         selectedCartIds
d98d05 494       },
S 495       success: res => {
496         wx.hideLoading();
497         if(!utils.requestError(res)){
498           return false;
499         }
500
501         this.setData({
502           totalMoney: res.data.PayAmount,
503           CartList: res.data.CartList,
504           CouponList: res.data.CouponList,
505           PointsTimesList: res.data.PointsTimesList,
506           Points: res.data.UserPoints,
507           Balance: res.data.Balance,
508           PreSendDate: res.data.PreSendDate
509         })
510
511       },
512       fail: function (errmsg) {
513         utils.requestFail(errmsg,'/shopping/confirm.do');
514       }
515     })
516   },
517
518 // 选择积分
519   pointItemTap: function (e) {
520     console.log(e)
521     // 页面显示积分选择状态
522     var pointId = parseInt(e.detail.value);
523     this.setData({
524       pointId: pointId
525     })
526     this.hideLayer2();
527
528     if (pointId==-1){
529       this.setData({
530         isSelected2: true
531       })
532
533     } else {
534       this.setData({
535         isSelected2: false
536       })
537     }
a50a5b 538     let data = {};
S 539     if (selectedCartIds){
540       data = {
541         couponCode: this.data.id == -1 ? "" : this.data.CouponList[this.data.id].CouponCode,
542         points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
543         balance: this.data.Balance,
544         isUsingCoupon,
545         selectedCartIds
546       }
547     } else{
548       data = {
549         couponCode:'',
550         points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
551         balance: this.data.Balance,
552         isUsingCoupon:false,
553         quantity: this.data.quantity,
554         matcode: this.data.matCode,
555         ...this.data.skuIds,
556       }
557     }
d98d05 558     wx.showLoading();
S 559     wx.request({
560       url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
561       header: {
562         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
563       },
a50a5b 564       data,
d98d05 565       success: res => {
S 566         wx.hideLoading();
567         if(!utils.requestError(res)){
568           return false;
569         }
570
571         this.setData({
572           totalMoney: res.data.PayAmount,
573           CartList: res.data.CartList,
574           CouponList: res.data.CouponList,
575           PointsTimesList: res.data.PointsTimesList,
576           Points: res.data.UserPoints,
577           Balance: res.data.Balance,
578           PreSendDate: res.data.PreSendDate
579         })
580
581       },
582       fail: function (errmsg) {
583         utils.requestFail(errmsg,'/shopping/confirm.do');
584       }
585     })
586
587   },
588   openHidelayer() {
589     this.setData({
590       showHidelayer: true
591     });
592     // setTimeout(()=>{
53cc6f 593
d98d05 594     // },200)
S 595
596   },
597   maskTap(event) {
598     this.setData({
599       showHidelayer: event.detail.isShow
600     });
601   },
602
603   getPresentCode(e){
604     let presentCode = e.detail.value.presentCode;
605     wx.request({
606       url: utils.getUrl('/shopping/voucher.do?m=get&voucherCode='+presentCode),
607       header: {
608         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
609       },
610       success: res => {
611         wx.hideLoading();
612         if(!utils.requestError(res)){
613           return false;
614         }
615
616         // wx.showModal({
617         //   title:'提示',
618         //   content: '礼品券使用成功! '
619         // })
620         if(res.data.state=='success'){
621           this.getOrderData();
622           wx.showToast({
623             title: '礼品券使用成功!',
624             icon: 'success',
625             duration: 2000
626           })
627           this.setData({
628             showHidelayer: false,
629             // voucherCost:res.data.voucherCost
630           });
631         }
632
633       },
634       fail: function (errmsg) {
635         utils.requestFail(errmsg, '/shopping/voucher.do?m=get&voucherCode=');
636       }
637     })
638   },
639
640   showLayer: function () {
641     // 优惠券隐藏层滑入
642     var that = this;
643     utils.showLayer(that, "translateY", 300, 0, "animationData","isShow");
644   },
645
646   hideLayer: function () {
647     // 优惠券隐藏层滑出
648     var that = this;
649     utils.hideLayer(that, "translateY", 300, "animationData", "isShow");
650   },
651
652   showLayer2: function () {
653     // 积分隐藏层滑入
654     var that = this;
655     utils.showLayer(that, "translateY", 300, 0, "animationData2", "isShow2");
656   },
657
658   hideLayer2: function () {
659     // 积分隐藏层滑出
660     var that = this;
661     utils.hideLayer(that, "translateY", 300, "animationData2", "isShow2");
662   },
663
664   // preventMove: function () {
665   //   // 利用catchtouchmove阻止背景滚动 不用添加任何代码
666   // },
667   // getAuthorize(e){
668   //   console.log(e)
669   // },
53cc6f 670
d98d05 671   deliveryMethodIndexChange(e) {
S 672     console.log('picker发送选择改变,携带值为', e.detail.value)
673     this.setData({
674       deliveryMethodIndex: e.detail.value
675     })
676   },
08a33d 677   getRemark(event){
S 678     console.log(event.detail.value);
679     this.setData({
680       remark:event.detail.value
681     })
682   },
d98d05 683   postOrder(event){
08a33d 684     // console.log(event)
S 685     let deliveryMethodIndex = this.data.deliveryMethodIndex||0;
245dd6 686     let delivery = this.data.deliveryMethod[deliveryMethodIndex];
08a33d 687     console.log(deliveryMethodIndex, this.data.deliveryMethod,delivery);
53cc6f 688
0da8db 689     if (delivery.isRequiredAddress&&!this.data.Address.FullAddress || (this.data.Address.FullAddress&&this.data.Address.FullAddress.trim() == '')) {
S 690       wx.showToast({
691         title: '请选择地址',
692         icon: 'none',
693         duration: 1500
694       })
695       return false
696     }
53cc6f 697
0da8db 698     if (delivery.isRequiredAddress&&!this.data.Address.AddressName) {
245dd6 699       wx.showModal({
S 700         title: '提示',
701         content: '当前选择地址定位有误,请核对',
702         success: (res)=> {
703         if (res.confirm) {
704           console.log('用户点击确定');
705           wx.navigateTo({
706             url: '../address/address?hidebtn=1&seqid='+this.data.Address.paymentaddress,
707           })
708         } else if (res.cancel) {
709           console.log('用户点击取消')
710         }
711         }
712       })
713       return;
714     }
d98d05 715     // return
S 716     // if (this.data.isChecked && this.data.Balance < this.data.totalMoney) {
717     //   wx.showToast({
718     //     title: '余额不足',
719     //     icon: 'none',
720     //     duration: 1500
721     //   })
722     //   return false
723     // }
a50a5b 724     let data = {};
S 725     let url = '';
53cc6f 726     if (selectedCartIds){
a50a5b 727       url = '/shopping/confirm.do?m=save';
S 728       data = {
729         paymentaddress: this.data.Address.paymentaddress,
730         couponCode: this.data.id == -1 ? "" : this.data.CouponList[this.data.id].CouponCode,
08a33d 731         presenddate: this.data.PreSendDate,
S 732         paymentcomment: this.data.remark,
a50a5b 733         points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
S 734         balance: this.data.isChecked ? this.data.Balance : 0,
735         isUsingCoupon,
736         freeid:delivery.FreeId||'',
737         FromOpenId:app.globalData.FromOpenId||'',
738         selectedCartIds
739       }
740     } else{
741       url = '/shopping/confirm.do?m=saveGroupBuyingOrder';
742       data = {
743         paymentaddress: this.data.Address.paymentaddress,
744         couponCode: "",
08a33d 745         presenddate: this.data.PreSendDate,
S 746         paymentcomment: this.data.remark,
a50a5b 747         points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
S 748         balance: this.data.isChecked ? this.data.Balance : 0,
749         isUsingCoupon:false,
750         freeid:delivery.FreeId||'',
751         FromOpenId:app.globalData.FromOpenId||'',
752         quantity:this.data.quantity,
753         matcode: this.data.matCode,
754         ...this.data.skuIds,
755         groupBuyingDocCode:this.data.groupCode
756       }
757     }
758     wx.showLoading()
759     wx.request({
760       url: utils.getUrl(url),
761       header: {
762         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
763       },
764       // method:'POST',
765       data,
766       success: res => {
767         wx.hideLoading();
768         if(!utils.requestError(res)){
769           return false;
770         }
771         // utils.cartNum();
772         // let weiXinPayAmount = 0
773         if (res.data.weiXinPayAmount == 0){
d98d05 774
a50a5b 775           // docstatus = 0 and  isAllowPayable = 0
S 776           wx.redirectTo({
777             url: '../orderSuccess/orderSuccess?doccode='+ res.data.doccode+'&linkman='+this.data.Address.LinkName + '&isCustomer=1'+'&formid='+res.data.formid,
778           })
779
780
781         } else {
782
783           if(res.data.DocStatus == 0 && res.data.isAllowPayable == 0){
d98d05 784             // docstatus = 0 and  isAllowPayable = 0
S 785             wx.redirectTo({
0da8db 786               url: '../orderSuccess/orderSuccess?doccode='+ res.data.doccode+'&linkman='+this.data.Address.LinkName + '&isCustomer=1'+'&formid='+res.data.formid,
d98d05 787             })
S 788           } else {
53cc6f 789             wx.redirectTo({
a50a5b 790               url: '../orderPay/orderPay?doccode=' + res.data.doccode+'&formid='+res.data.formid,
53cc6f 791             })
S 792           }
793         }
a50a5b 794
S 795
796       },
797       fail: function (errmsg) {
798         utils.requestFail(errmsg,'/shopping/confirm.do');
799       }
800     })
801
53cc6f 802
d98d05 803   },
S 804   onDialogClose(){
805     this.setData({
806       isShowDialog:false
807     })
808     // this.postOrder(this.data.dataEvent);
809   },
c891bc 810
d98d05 811
S 812   placeOrder: function (event) {
813     console.log('提交订单事件',event)
814     // return;
815     let orderTemplateId = app.globalData.orderNoticeTemplateIdList;
816     let ids = [];
e35b15 817     try {
S 818       if(this.data.isAllowPayable==0){
d98d05 819       ids = [orderTemplateId.payableTemplateId,orderTemplateId.templateId,orderTemplateId.shippedTemplateId];
S 820     } else {
821       ids = [orderTemplateId.shippedTemplateId,orderTemplateId.templateId];
822     }
53cc6f 823
d98d05 824     utils.subscribeMessage({
S 825       ids:ids,
826       callback:()=>{
827         this.postOrder(event);
828         // utils.isAuthorize(this,()=>{
829         //   if (this.data.isAuthorize) {
830         //     this.postOrder(event);
831         //   } else {
832         //     this.setData({
833         //       isShowDialog: true,
834         //       dataEvent:event
835         //     })
836         //   }
837         // });
53cc6f 838
d98d05 839       }
S 840     })
e35b15 841     } catch (error) {
S 842       console.log(error)
843       this.postOrder(event);
844     }
53cc6f 845
S 846
d98d05 847
S 848
849     // if (this.data.showAddAddr) {
850     //   utils.showTip("请填写收货地址", "none");
851     //   return false;
852     // }
853     // else if (event.detail.value.date == "" && !this.data.PreSendDate) {
854     //   utils.showTip("请填写交货日期","none");
855     //   return false;
856     // }
857
858   //   // 发起支付
859   //   var orderDetail = this.data.detail;
860   //   var userInfo = { name: this.data.name, tel: this.data.tel, addrdetail: this.data.addrdetail };
861   //   var totalPrice = this.data.totalMoney;
862   //   var remarks = event.detail.value.remark;
863   //   wx.getStorage({
864   //     key: 'openid',
865   //     success: function (res) {
866   //       var openId = res.data;
867   //       if (!openId) {
868   //         console.log('未获取到openId请刷新重试');
869   //         return false;
870   //       }
871
872
873
874   //       //传参数金额,名称,描述,openid
875   //       Bmob.Pay.wechatPay(totalPrice, '小程序商城', '描述', openId).then(function (resp) {
876
877   //         //服务端返回成功
878   //         var timeStamp = resp.timestamp,
879   //           nonceStr = resp.noncestr,
880   //           packages = resp.package,
881   //           orderId = resp.out_trade_no,//订单号,如需保存请建表保存。
882   //           sign = resp.sign;
883   //         //发起支付
884   //         wx.requestPayment({
885   //           'timeStamp': timeStamp,
886   //           'nonceStr': nonceStr,
887   //           'package': packages,
888   //           'signType': 'MD5',
889   //           'paySign': sign,F
890   //           'success': function (res) {
891   //             //付款成功,这里可以写你的业务代码
892   //             var User = Bmob.Object.extend("_User");
893   //             var currentUser = Bmob.User.current();
894   //             var objectid = currentUser.id;
895   //             var Order = Bmob.Object.extend("Order");
896   //             var Order = new Order();
897   //             var me = new Bmob.User();
898   //             me.id = objectid;
899   //             Order.set("remarks", remarks);
900   //             Order.set("orderUser", me);
901   //             Order.set("totalprice", parseFloat(totalPrice));
902   //             Order.set("orderDetail", orderDetail);
903   //             Order.set("orderId", orderId);
904   //             Order.set("status", 1);
905   //             Order.set("userInfo", userInfo);
906   //             Order.save(null, {
907   //               success: function (result) {
908   //                 wx.redirectTo({
909   //                   url: '../order/index'
910   //                 })
911   //               },
912   //               error: function (result, error) {
913
914   //               }
915   //             });
916   //           },
917   //           'fail': function (res) {
918   //             console.log(res)
919   //             var User = Bmob.Object.extend("_User");
920   //             var currentUser = Bmob.User.current();
921   //             var objectid = currentUser.id;
922   //             var Order = Bmob.Object.extend("Order");
923   //             var Order = new Order();
924   //             var me = new Bmob.User();
925   //             me.id = objectid;
926   //             Order.set("remarks", remarks);
927   //             Order.set("orderUser", me);
928   //             Order.set("totalprice", parseInt(totalPrice));
929   //             Order.set("orderDetail", orderDetail);
930   //             Order.set("status", 0);
931   //             Order.set("userInfo", userInfo);
932   //             Order.set("orderId", orderId);
933   //             Order.save(null, {
934   //               success: function (result) {
935   //                 console.log(result.id)
936   //               },
937   //               error: function (result, error) {
938
939   //               }
940   //             });
941   //           }
942   //         })
943
944   //       }, function (err) {
945   //         console.log('服务端返回失败');
946   //         console.log(err);
947   //       });
948
949   //     }
950   //   })
951
952   // console.log(event);
953
954
955
956   }
957
958 });