Sanakey
2022-10-28 0e185fa6db8e3f4209e63c079750a26fe3feddaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
// pages/detail/detail.js
var listData = require('../../data/test-data.js');
// var WxParse = require('../../src/wxParse/wxParse.js');
// var Quantity = require('../template/cart-input/cart-input-template.js');
var utils = require("../../utils/util.js")
var app = getApp();
let isLogin = false;
let matcode = "";
let imgDownloadSum = 0;
let imgDownloadObj = {
  isComplete:false
};
import {Http} from "../../utils/http-p.js";
const Request = new Http();
// Object.assign({}, Quantity,
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    navTitle: [{
        text: "商品描述",
        id: 0
      },
      {
        text: "商品属性",
        id: 1
      },
      {
        text: "售后服务",
        id: 2
      }
    ],
    isShow: false,
    isPanicCanBuy:true,
    isGroupCanBuy:true,
    isSelectedAllSku:true,
    actionType: "payOrder",
    Quantity: {
      quantity: 1,
      min: 1,
      max: 999999
    },
    clientHeight: "100%",
    overflow: "auto",
    list: [],
    isPullTelephone: false,
    cltcode: '',
    isShowBuyingButton:true,
    attrList:[
      {
        title: '颜色',
        list: [
          {
            name:'红',
            checked: true
          },
          {
            name:'黄',
            checked: false
          },
 
        ]
      },
      {
        title: '尺寸',
        list: [
          {
            name:'大',
            checked: false
          },
          {
            name:'小',
            checked: true
          },
 
        ]
      }
    ]
  },
 
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // homeLayoutStyle = options.homeLayoutStyle;
    imgDownloadSum = 0;
 
    // this.setData({
    //   homeLayoutStyle: homeLayoutStyle
    // })
 
    // if (homeLayoutStyle) {
    //   return false;
    // }
 
    // const query = wx.createSelectorQuery()
    //   console.log('query.select(#myCanvas)',query.select('#myCanvas'))
    //   query.select('#myCanvas')
    //   .fields({ node: true, size: true })
    //   .exec((res) => {
    //     const canvas = res[0].node
    //     const ctx = canvas.getContext('2d')
    //     console.log(canvas,ctx)
    //     this.setData({
    //       canvas,
    //       context:ctx
    //     })
    //   })
 
    this.setData({
      cltcode: app.globalData.Cltcode
    })
    console.log('cltcode', this.data.cltcode);
    // this.getSetting()
    matcode = options.matcode;
    wx.showLoading({
      mask: false,
      title: '加载中',
    })
    if (!app.globalData.openID || !app.globalData.FromUserId) {
      app.globalData.indexCallback = (res) => {
        // console.log('没有。。。。')
        this.getSetting();
        this.getDetailData();
      }
    } else{
      this.getSetting();
      this.getDetailData();
    }
 
 
  },
  onCountDownFinish(){
    console.log('倒计时结束了。。。')
    this.getDetailData ();
  },
  getDetailData () {
    var that = this;
    // option接收其他页面传递过来的值,?后面的变量名id
    wx.request({
      url: utils.getUrl('/shopping/getMatCode.do?matcode=' + matcode),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      method: "GET",
      success: (res)=> {
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
        that.setData({
          goodsItem: res.data.list,
          CouponList:res.data.CouponList,
          groupBuyingList:res.data.groupBuyingList,
          SkuParameterList:res.data.SkuParameterList,
          SkuMatCodeList:res.data.SkuMatCodeList,
          title: res.data.list.MatName,
          num: 0,
          description: res.data.list.Description,
          Mininum: res.data.list.Mininum||1,
          ['Quantity.quantity']: res.data.list.Mininum||1
          // price: goodsItem.Price
        })
        this.handleNoticeText(res.data.list);
 
        // WxParse.wxParse('article', 'html', res.data.list.Description, that, 5);
        this.getPosterQrCode();
        this.handleCurrentGoods();
        wx.setNavigationBarTitle({
          title: res.data.list.MatName,
        })
      },
      fail: function (errmsg) {
        utils.requestFail(errmsg,'/shopping/getMatCode.do');
      }
 
    });
 
    /**
     * WxParse.wxParse(bindName , type, data, target,imagePadding)
     * 1.bindName绑定的数据名(必填)
     * 2.type可以为html或者md(必填)
     * 3.data为传入的具体数据(必填)
     * 4.target为Page对象,一般为this(必填)
     * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
     */
  },
 
  handleNoticeText(res){
    this.setData({
      isPanicCanBuy:true,
      isGroupCanBuy:true
    })
    let {
      Quantity,
      isRestrictQuantity,
      isStartupPanicBuying,
      PanicBuyingStartTimeBalance,
      PanicBuyingEndTimeBalance,
      PanicBuyingStartTime,
      PanicBuyingEndTime,
      isStartupGroupBuying,
      GroupBuyingMembers,
      GroupBuyingPrice,
      GroupBuyingStartTime,
      GroupBuyingEndTime,
      GroupBuyingStartTimeBalance,
      GroupBuyingEndTimeBalance
    } = res;
    if (isStartupPanicBuying&&PanicBuyingStartTimeBalance>0) {
      this.setData({
        noticeText:`未开抢,开抢时间${PanicBuyingStartTime}至${PanicBuyingEndTime}`,
        isPanicCanBuy:false
      })
    }
    else if (isStartupPanicBuying&&PanicBuyingStartTimeBalance<=0&&PanicBuyingEndTimeBalance>0) {
      this.setData({
        noticeText:`商品抢购中,结束时间为${PanicBuyingEndTime}`,
        isPanicCanBuy:true
      })
    }
    else if (isStartupPanicBuying&&PanicBuyingEndTimeBalance<=0) {
      this.setData({
        noticeText:`本次商品抢购已结束`,
        isPanicCanBuy:false
      })
    }
 
    if (isStartupGroupBuying&&GroupBuyingStartTimeBalance>0) {
      this.setData({
        noticeText:`未开抢,开抢时间${GroupBuyingStartTime}至${GroupBuyingEndTime}`,
        isGroupCanBuy:false
      })
    }
    else if (isStartupGroupBuying&&GroupBuyingStartTimeBalance<=0&&GroupBuyingEndTimeBalance>0) {
      this.setData({
        noticeText:`商品拼团抢购中,结束时间为${GroupBuyingEndTime}`,
        isGroupCanBuy:true
      })
    }
    else if (isStartupGroupBuying&&GroupBuyingEndTimeBalance<=0) {
      this.setData({
        noticeText:`本次商品限时团购已结束`,
        isGroupCanBuy:false
      })
    }
 
    if (isRestrictQuantity&&Quantity<=0) {
      this.setData({
        noticeText:`该商品已售罄`,
        isPanicCanBuy:false
      })
    }
 
    console.log('isPanicCanBuy',this.data.isPanicCanBuy);
    console.log('isGroupCanBuy',this.data.isGroupCanBuy);
  },
 
  btnTap: async function (e) {
    // var that =  this;
    // var isGet = this.data.isGet;
    // isGet = !isGet;
    // wx.showLoading({
    //   title: '',
    // });
    // setTimeout(function () {
    //   wx.hideLoading();
    //   that.setData({
    //     isGet: isGet
    //   })
    // }, 800);
    // await utils.isAuthorize(this);
    // if(!this.data.isAuthorize){
    //   if (!await utils.authorize(e, this)){
    //       return;
    //   }
    // }
    var id = e.target.dataset.couponid;
    var index = e.target.dataset.index;
    console.log('领取index',index)
    // couponStatus :  //0 正常:可以抢 ;  1 已经抢完 ;  2 未开抢 ; 3 已经抢过了,不能重复抢 ; 4 已经提醒(微信模板消息提醒)
    wx.showLoading()
    wx.request({
      url: utils.getUrl('/shopping/coupon.do?m=savePersonalCouponCode&couponcode=' + id),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      success: res => {
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
        // this.getDetailData();
        if(res.data.state=='success'){
          wx.showToast({
            icon:'none',
            title: res.data.success,
          })
          this.setData({
            [`CouponList[${index}].Status`]:3
          })
          console.log(this.data.CouponList[index].Status)
        } else{
          wx.showToast({
            title: '领取失败',
          })
        }
 
      },
      fail: function (errmsg) {
        utils.requestFail(errmsg,'/shopping/coupon.do');
      }
    })
 
 
  },
 
  getPosterQrCode(){
 
    wx.request({
      url: utils.getUrl('/shopping/poster/getQrCodeForPoster.do'),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      data:{
        QrCodeType:30,
        matcode:matcode
      },
      success: res => {
        if(!utils.requestError(res)){
          return false;
        }
        // this.getDetailData();
        console.log(res.data);
        this.setData({
          QrCode:res.data.QrCode
        })
 
 
      },
      fail: function (errmsg) {
        utils.requestFail(errmsg,'/shopping/poster/getQrCodeForPoster.do');
      }
    })
  },
 
  getSetting() {
    // 获取设置
 
    let isPullTelephone1 = false;
    let getSetting = Request.request({
      url: '/shopping/getSettingEntity.do'
    }).then((res) => {
      console.log('设置数据',res)
      isPullTelephone1 = res.isPullTelephoneWhenViewProductDetail
      console.log('isPullTelephone设置', isPullTelephone1)
      this.setData({
        generateOrderProcess: res.generateOrderProcess||0
      })
      this.setData({
        isPullTelephone: isPullTelephone1,
        isShowBuyingButton: res.isShowBuyingButton || false
      })
      console.log('isPullTelephone:', isPullTelephone1);
    });
   
 
  },
 
  getPhoneNumber(e) {
    console.log('getPhoneNumber', e);
 
    if (e.detail.phoneNumber.errMsg == 'getPhoneNumber:ok') {
      Request.request({
        url: '/shopping/account.do',
        data: {
          m: 'telRegByAutoReg',
          // ReferralsCode: this.data.UserId,
          // ReferralsName: this.data.Name,
          ReferralsCode: app.globalData.cardUserData.UserId,
          ReferralsName: app.globalData.cardUserData.Name,
          encryptedData: e.detail.phoneNumber.encryptedData,
          iv: e.detail.phoneNumber.iv,
          // SessionKey: app.globalData.SessionKey
        }
      }).then((res) => {
        console.log('/shopping/account.do', res);
        if (res.cltcode) {
          app.globalData.Cltcode = res.cltcode;
          this.setData({
            isPullTelephone: false,
            cltcode: res.cltcode
          })
        }
      });
    } else{
      console.log('取消授权');
      // wx.switchTab({
      //   url: url
      // });
    }
 
  },
 
  /*查看图片*/
  viewImg: function(e) {
    var src = e.currentTarget.dataset.src;
    // console.log(src)
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: this.data.goodsItem.images // 需要预览的图片http链接列表
    })
  },
 
  // 导航条点击
  navTap: function(e) {
    this.setData({
      num: e.currentTarget.dataset.num
    })
  },
 
  // 隐藏层滑入
  showLayer: function() {
    var that = this;
    utils.showLayer(that, "translateY", 300, 0);
  },
 
  // 隐藏层滑出
  hideLayer: function() {
    var that = this;
    utils.hideLayer(that, "translateY", 500);
    this.setData({
      ['Quantity.quantity']: this.data.Mininum||1,
      isSelectedSku: false
 
    })
  },
 
 
    // downloadFile(){
    //   console.log(app.globalData.cardUserData)
    //   console.log('头像',app.globalData.cardUserData.Avatar)
    //   console.log('logo',app.globalData.logoUrl)
    //   console.log('二维码',this.data.QrCode)
    //   console.log('商品',this.data.goodsItem.PhotoPath)
    //   let avatarUrl = wx.pro.downloadFile({
    //     url: app.globalData.cardUserData.Avatar
    //   }).then((res)=>{
    //     if (res.statusCode === 200) {
    //       imgDownloadSum++;
    //       console.log('......头像',res.tempFilePath)
    //       this.setData({
    //         avatarUrl: res.tempFilePath
    //       })
    //     }
    //   })
    //   let goodsImg = wx.pro.downloadFile({
    //     url: this.data.goodsItem.PhotoPath
    //   }).then((res)=>{
    //     if (res.statusCode === 200) {
    //       imgDownloadSum++;
    //       console.log('......商品',res.tempFilePath)
    //       this.setData({
    //         goodsImg: res.tempFilePath
    //       })
    //     }
    //   })
    //   let qrCodeImg = wx.pro.downloadFile({
    //     url: this.data.QrCode
    //   }).then((res)=>{
    //     if (res.statusCode === 200) {
    //       console.log('......二维码',res.tempFilePath)
    //       imgDownloadSum++;
    //       this.setData({
    //         qrCodeImg: res.tempFilePath
    //       })
    //     }
    //   })
 
    //   Promise.all([avatarUrl,goodsImg,qrCodeImg]).then((res)=>{
 
    //     imgDownloadObj.isComplete = true;
 
    //     // imgDownloadObj.isComplete = true;
    //   }).catch((err)=>{
    //     // this.getPosterQrCode();
    //     console.log('请检查名片头像、公司logo等图片是否已经配置',err)
    //     // \n 点击确定重试,点击取消关闭弹窗。
    //     wx.hideToast();
    //     wx.showModal({
    //       title:'提示',
    //       content:`${err.errMsg}`,
    //       showCancel:false,
    //       success:(res)=>{
    //         // if (res.confirm) {
    //         //   console.log('用户点击确定')
    //         //   wx.showLoading()
    //         //   this.downloadFile()
    //         // } else if (res.cancel) {
    //         //   console.log('用户点击取消')
    //         // }
 
    //       }
    //     })
 
    //   })
 
    // },
 
    // createCanvas(e){
 
    //   wx.showToast({
    //     title: '生成中...',
    //     icon: 'loading',
    //     mask:true,
    //     duration: 10000
    //   });
 
    //   if (imgDownloadObj.isComplete) {
    //     // wx.hideToast()
    //     // let posterCreate =  this.selectComponent('#posterCreate');
    //     // posterCreate.formSubmit(e);
    //     this.sendCommand(e);
    //   } else {
    //     // 下载图片到本地
    //     this.downloadFile();
    //     // utils.watchObj(imgDownloadObj,(prop,val)=>{
    //     //   console.log(JSON.stringify(imgDownloadObj)+prop+'值变化!!!','新值为'+val)
    //     utils.watchObj(imgDownloadObj,'isComplete',(val)=>{
    //       console.log(JSON.stringify(imgDownloadObj)+'isComplete值变化!!!','新值为'+val)
    //       if (imgDownloadObj.isComplete) {
    //         this.sendCommand(e);
    //       }
    //       // wx.hideToast()
    //       // let posterCreate =  this.selectComponent('#posterCreate');
    //       // posterCreate.formSubmit(e);
 
    //     })
 
    //   }
 
    // },
 
    // sendCommand(e){
    //   wx.hideToast()
    //   let posterCreate =  this.selectComponent('#posterCreate');
    //   posterCreate.formSubmit(e);
    // },
 
 
    // // 加载函数
    // loadImage(src) {
    //   return new Promise((resolve,reject) => {
    //     const img = this.data.canvas.createImage();
    //     img.onload = () => {
    //       resolve(img);
    //     };
    //     img.onerror = (e) => {
    //       reject(e);
    //     };
    //     img.src = src;
    //   });
    // },
 
 
 
    //将canvas转换为图片保存到本地,然后将图片路径传给image图片的src
    // createPoster (e) {
    //   let posterCreate =  this.selectComponent('#posterCreate');
    //   let canvas = e.detail.canvas;
    //   console.log(e)
    //   // let context = canvas.getContext('2d');
    //   let context = e.detail.context;
    //   // let context = wx.createCanvasContext('mycanvas');
 
    //   // let path = "../../imgs/gobg.png";
    //   // //不知道是什么原因,手机环境能正常显示
    //   // context.drawImage(path, 0, 0, 375, 183);
    //   let avatarImg = this.data.avatarUrl;
    //   console.log(avatarImg,"avatarImg")
    //   // let path2 = "../../imgs/chengzhong.png";
    //   let goodsImg = this.data.goodsImg;
    //   let qrCodeImg = this.data.qrCodeImg;
    //   // let path5 = "../../imgs/computer.png";
    //   // context.drawImage(path2, 126, 186, 120, 120);
    //   // context.save(); // 保存当前context的状态
    //   console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
    //   // let name = that.data.name;
    //   // //绘制名字
    //   // context.setFontSize(30);
    //   // context.setFillStyle('#333333');
    //   // context.setTextAlign('center');
    //   // context.fillText(name, 185, 160);
    //   // context.stroke();
    //   context.beginPath()
    //   context.fillStyle="#fff";
    //   context.fillRect(0, 0, 375, 667);
    //   context.closePath()
    //   //绘制文字
    //   context.beginPath()
    //   context.setFontSize(16);
    //   context.fillStyle='#333333';
    //   context.textAlign='left';
    //   context.fillText("我看上了这款商品", 140, 50);
    //   context.stroke();
 
    //   context.setFontSize(16);
    //   context.fillStyle='#333333';
    //   context.textAlign='left';
    //   context.fillText("帮我看看咋样啊~~", 140, 85);
    //   context.stroke();
    //   context.closePath();
    //   //绘制商品
    //   context.beginPath();
    //   context.drawImage(goodsImg, 48, 125, 280, 280);
    //   // 商品文字
 
    //   context.setFontSize(16);
    //   context.fillStyle='#333333';
    //   context.textAlign='left';
    //   var result = this.breakLinesForCanvas(context,
    //     this.data.goodsItem.MatName.slice(0,50),
    //     170, '14px 微软雅黑');
    //   var lineHeight = 25;
    //   result.forEach(function(line, index) {
    //       context.fillText(line, 50, lineHeight * index + 435);
    //       // context.fillText("商品描述", 50, 445);
    //   });
 
    //   context.stroke();
    //   context.setFontSize(32);
    //   context.fillStyle='#f23232';
    //   context.textAlign='left';
    //   context.fillText("¥1999.00", 45, 505);
    //   context.stroke();
    //   context.closePath();
 
    //   // 绘制分割线
    //   context.beginPath()
    //   context.strokeStyle='#ddd'
    //   context.moveTo(10, 520)
    //   context.lineTo(365, 520)
    //   context.stroke()
    //   context.closePath();
    //   //绘制code码
    //   // context.setFontSize(40);
    //   // context.setFillStyle('#ffe200');
    //   // context.setTextAlign('center');
    //   // context.fillText(that.data.code, 185, 435);
    //   // context.stroke();
    //   //绘制左下角文字背景图
    //   context.beginPath();
    //   context.drawImage(qrCodeImg, 20, 530, 120, 120);
 
    //   //绘制右下角扫码提示语
    //   // context.drawImage(path5, 248, 578, 90, 25);
    //   context.setFontSize(16);
    //   context.fillStyle='#333';
    //   context.textAlign='left';
    //   context.fillText("长按识别小程序码 即可查看~",150, 600);
    //   context.stroke();
    //   //绘制头像
    //   context.arc(80, 60, 40, 0, 2 * Math.PI) //画出圆
    //   context.strokeStyle = "#ffe200";
    //   context.clip(); //裁剪上面的圆形
    //   context.drawImage(avatarImg, 40, 20, 80, 80); // 在刚刚裁剪的园上画图
    //   context.closePath();
    //   // context.draw();
    //   // let posterCreate =  this.selectComponent('#posterCreate');
    //   //   posterCreate.createPoster();
    //   //   console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
    //   //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
    //   setTimeout( ()=> {
 
 
    //     posterCreate.createPoster(canvas);
    //     console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
    //    }, 500);
    // },
    // authorizeInfo(e){
    //   console.log('authorizeInfo',e)
    // },
    // createNewImg (e) {
    //   console.log('createNewImg',e)
    //   let posterCreate =  this.selectComponent('#posterCreate');
    //   let goodsItem = this.data.goodsItem;
    //   let context = e.detail.context;
    //   // let childComp = e.detail.childComp;
    //   // let context = wx.createCanvasContext('mycanvas');
    //   context.clearRect(0, 0, 375, 667);
    //   context.setFillStyle("#fff");
    //   context.fillRect(0, 0, 375, 667)
    //   // let path = "../../imgs/gobg.png";
    //   // //不知道是什么原因,手机环境能正常显示
    //   // context.drawImage(path, 0, 0, 375, 183);
    //   let avatarImg = this.data.avatarUrl;
    //   console.log(avatarImg,"avatarImg")
    //   // let path2 = "../../imgs/chengzhong.png";
    //   let goodsImg = this.data.goodsImg;
    //   let qrCodeImg = this.data.qrCodeImg;
    //   console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
    //   // let path5 = "../../imgs/computer.png";
    //   // context.drawImage(path2, 126, 186, 120, 120);
    //   // context.save(); // 保存当前context的状态
 
    //   //绘制文字
    //   context.beginPath()
    //   context.setFontSize(16);
    //   context.setFillStyle('#333333');
    //   context.setTextAlign('left');
    //   context.fillText("我看上了这款商品", 140, 50);
    //   context.stroke();
    //   context.setFontSize(16);
    //   context.setFillStyle('#333333');
    //   context.setTextAlign('left');
    //   context.fillText("帮我看看咋样啊~~", 140, 85);
    //   context.stroke();
    //   context.closePath();
    //   //绘制商品
    //   context.drawImage(goodsImg, 48, 125, 280, 280);
    //   // 商品文字
    //   context.beginPath();
    //   context.setFontSize(16);
    //   context.setFillStyle('#333333');
    //   context.setTextAlign('left');
    //   var result = posterCreate.breakLinesForCanvas(context,
    //     goodsItem.MatName.slice(0,40),
    //     220, 14);
    //   var lineHeight = 25;
    //   result.forEach(function(line, index) {
    //       context.fillText(line, 50, lineHeight * index + 435);
    //       // context.fillText("商品描述", 50, 445);
    //   });
 
    //   context.stroke();
    //   context.setFontSize(32);
    //   context.setFillStyle('#f23232');
    //   context.setTextAlign('left');
    //   context.fillText(goodsItem.CurrencySign+goodsItem.Price, 45, 495);
    //   context.stroke();
    //   context.closePath();
 
    //   // 绘制分割线
    //   context.beginPath()
    //   context.strokeStyle='#ddd'
    //   context.moveTo(10, 520)
    //   context.lineTo(365, 520)
    //   context.stroke()
    //   context.closePath();
    //   //绘制code码
    //   // context.setFontSize(40);
    //   // context.setFillStyle('#ffe200');
    //   // context.setTextAlign('center');
    //   // context.fillText(that.data.code, 185, 435);
    //   // context.stroke();
    //   //绘制左下角二维码
    //   context.drawImage(qrCodeImg, 20, 530, 120, 120);
 
    //   //绘制右下角扫码提示语
    //   // context.drawImage(path5, 248, 578, 90, 25);
    //   context.setFontSize(16);
    //   context.setFillStyle('#333');
    //   context.setTextAlign('left');
    //   context.fillText("长按识别小程序码 即可查看~",150, 600);
    //   context.stroke();
    //   //绘制头像
    //   context.arc(80, 60, 40, 0, 2 * Math.PI) //画出圆
    //   context.strokeStyle = "#ffe200";
    //   context.clip(); //裁剪上面的圆形
    //   context.drawImage(avatarImg, 40, 20, 80, 80); // 在刚刚裁剪的园上画图
    //   context.draw();
    //   //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
    //   setTimeout(()=> {
    //     posterCreate.createPoster();
    //     // console.log('将生成好的图片保存到本地',avatarImg,goodsImg,qrCodeImg)
    //   }, 300);
    // },
 
  buyTap: function(event) {
    // 根据按钮不同区分“下一步”触发的事件
    let name = event.target.dataset.name || event.detail.name;
    console.log(event);
    this.setData({
      groupCode:event.detail.groupCode||'',
    });
    if (name === "order") {
      this.setData({
        actionType: 'payOrder'
      })
      // utils.subscribeMessage({
      //   callback:()=>{
      //     if (this.data.isShow) {
      //       this.hideLayer();
      //     } else {
      //       this.showLayer();
      //     }
      //   }
      // })
    } else if (name === "cart") {
      this.setData({
        actionType: 'addCart'
      })
 
    }
    else if (name === "group") {
      this.setData({
        actionType: 'groupBuying'
      })
 
    }
    if (this.data.isShow) {
        this.hideLayer();
      } else {
        this.showLayer();
      }
  },
 
  selectedSku(){
    // console.log(888);
    // if (!this.data.isPanicCanBuy) return;
    this.setData({
      isSelectedSku: true
    })
    if (this.data.isShow) {
      this.hideLayer();
    } else {
      this.showLayer();
    }
  },
 
  handleCurrentGoods(){
  /*
  *
  * 首先拿到当前商品的所有skuid [],同时也是选中的id
  * 处理所有商品的skuid为字符串
  * 用户点击sku[i],拼接为字符串与上面的对比
  * */
    let SkuParameterList = this.data.SkuParameterList;
    let SkuMatCodeList = this.data.SkuMatCodeList;
    let MatCode = this.data.goodsItem.MatCode;
    let selectedSkuId = [];
    let selectedSkuName = [];
    let goodsSkuIdStrings = [];
    let goodsSkuIdList = [];
    let skuIdList = [];
    let skuSetName = [];
    SkuParameterList.forEach((item) => {
      let arr = [];
      item.skuList.forEach((item) => {
        arr.push(item.skuId)
      })
      skuIdList.push(arr);
      skuSetName.push(item.skuSetName);
    })
    SkuMatCodeList.forEach((item,index)=>{
      let skuIdString = '';
      let skuIdArr = [];
      for (let i = 1; i < 11; i++) {
        if (item.MatCode === MatCode && item[`skuId${i}`]){
          selectedSkuId.push(item[`skuId${i}`])
          selectedSkuName.push(item[`skuName${i}`])
        }
        if (item[`skuId${i}`]){
          skuIdString+=item[`skuId${i}`]
          skuIdArr.push(item[`skuId${i}`])
        }
      }
      goodsSkuIdStrings.push(skuIdString)
      goodsSkuIdList.push(skuIdArr)
    })
    this.setData({
      selectedSkuId,
      selectedSkuName,
      selectedSkuNameStr: selectedSkuName.join(' '),
      goodsSkuIdStrings,
      skuIdList,
      goodsSkuIdList,
      skuSetName,
      skuSetNameStr:skuSetName.join(','),
    })
    console.log('selectedSkuId',selectedSkuId);
    console.log('selectedSkuName',selectedSkuName);
    console.log('goodsSkuIdStrings',goodsSkuIdStrings);
    console.log('skuIdList',skuIdList);
    console.log('goodsSkuIdList',goodsSkuIdList);
    console.log('skuSetName',skuSetName);
    this.handleSkuIds();
  },
  async selectGoodsAttr(e){
 
 
    let attrIndex = e.currentTarget.dataset.i;
    let listIndex = e.currentTarget.dataset.index;
    let skuId = e.currentTarget.dataset.skuId;
    let skuName = e.currentTarget.dataset.skuName;
    let isEnabled = e.currentTarget.dataset.isEnabled;
    let selectedSkuId = this.data.selectedSkuId;
    let selectedSkuName = this.data.selectedSkuName;
    let length = selectedSkuId.length;
    console.log(e,selectedSkuId);
    // if (!isEnabled) return;
 
    selectedSkuId[attrIndex] =  skuId;
    selectedSkuName[attrIndex] =  skuName;
    selectedSkuId.forEach((item,index)=>{
      if (index>attrIndex){
        selectedSkuId[index] = ''
        selectedSkuName[index] = ''
      }
    })
    selectedSkuId.forEach((item)=>{
      if (item==="") length--;
    })
    this.setData({
      // [`selectedSkuId[${attrIndex}]`]:skuId,
      selectedSkuId:selectedSkuId,
      // [`selectedskuName[${attrIndex}]`]:skuName,
      // [`selectedskuName[${attrIndex}]`]:skuName,
      selectedSkuNameStr: selectedSkuName.join(' '),
      selectedSkuIdLength: length
    })
    console.log(selectedSkuId,selectedSkuName,this.data.selectedSkuIdLength);
    // console.log(await this.getSkuParameterByMatCode());
    let [errMsg,spRes] = await this.getSkuParameterByMatCode();
    if (errMsg) {
      return;
    }
    console.log(spRes);
    if (length<selectedSkuId.length) {
      this.setData({
        SkuParameterList:spRes.SkuParameterList,
        isSelectedAllSku:false,
      })
    } else {
      this.setData({
        SkuParameterList:spRes.SkuParameterList,
        CouponList:spRes.CouponList,
        goodsItem:spRes.list,
        groupBuyingList:spRes.groupBuyingList,
        isSelectedAllSku:true,
      })
      matcode = spRes.list.MatCode
      this.handleNoticeText(spRes.list);
    }
    if (spRes.list.MatName) {
      wx.setNavigationBarTitle({
        title: spRes.list.MatName,
      })
    }
    // selectedSkuId[attrIndex] =  skuId;
    // let goodsSkuIdStrings = this.data.goodsSkuIdStrings;
    // let hasSkuId = goodsSkuIdStrings.includes(selectedSkuId.join(''));
    // console.log(goodsSkuIdStrings,selectedSkuId.join(''));
    // if (goodsSkuIdStrings.includes(selectedSkuId.join(''))){
    //   this.setData({
    //     [`selectedSkuId[${attrIndex}]`]:skuId
    //   })
    // } else{
    //
    // }
    // this.handleDisabledSkuId();
    /*
    * 遍历第一列,把没有的标记
    * 点击第一列可选的项后,遍历剩下所有列,把没有的标记
    * */
    // let list = this.data.attrList[attrIndex].list;
    // list.forEach((item,index)=>{
    //   item.checked = index === listIndex;
    // })
    // this.setData({
    //   [`attrList[${attrIndex}].list`]:list
    // })
 
  },
  async getSkuParameterByMatCode(){
    this.handleSkuIds();
    let data = this.data.skuIds;
    let [errMsg,res] = await utils.to(
      wx.$http.request({
        url:'/shopping/getSkuParameterByMatCode.do',
        data
      })
    )
    return [errMsg,res];
 
  },
  handleSkuIds(){
    let data = {};
    let selectedSkuId = this.data.selectedSkuId;
    let selectedSkuIdLength = this.data.selectedSkuIdLength;
    for (let i = 1; i < 11; i++) {
      if (selectedSkuId[i-1]){
        data[`skuId${i}`] = selectedSkuId[i-1]
      } else {
        data[`skuId${i}`] = ''
      }
    }
    if (selectedSkuIdLength<selectedSkuId.length) {
      data.matcode = this.data.goodsItem.MatCode;
    }
    console.log(selectedSkuIdLength,selectedSkuId.length);
    console.log(data);
    this.setData({
      skuIds:data
    });
  },
 
  handleDisabledSkuId(){
    let SkuMatCodeList = this.data.SkuMatCodeList;
    let skuIdList = this.data.skuIdList;
    let goodsSkuIdList = this.data.goodsSkuIdList.flat(2);
    // console.log(goodsSkuIdList);
    let disabledSkuId = [];
    let selectedSkuId = this.data.selectedSkuId;
    // SkuMatCodeList.forEach((item,index)=>{
    //   let disabledArr = [];
    //   if (skuIdList[0].includes(item.skuId1)) {
    //     disabledArr.push()
    //   }
    // })
    let disabledArr = [];
    skuIdList.forEach((list,index)=>{
      if (index === 0){
        list.forEach((item,i)=>{
          if (goodsSkuIdList.includes(item)){
            disabledArr.push(true)
          } else{
            disabledArr.push(false)
          }
        })
        disabledSkuId.push(disabledArr);
      }
 
    })
 
 
 
 
  },
 
  quantityEdit(e){
    // console.log(e)
    this.setData({
      ['Quantity.quantity']:parseFloat(e.detail.quantity)
    })
    // console.log(this.data.Quantity)
  },
  groupBuying(e){
    console.log('准备团购');
    if (!this.data.isGroupCanBuy) return;
    if (!this.data.isSelectedAllSku) {
      wx.showToast({
        title: '请选择正确的分类',
        icon:'none'
      })
      return
    };
    let quantity = this.data.Quantity.quantity;
    let matCode = this.data.goodsItem.MatCode;
    let groupCode = this.data.groupCode;
    let goodsItem = this.data.goodsItem;
    let skuIds = this.data.skuIds;
    // let eventChannel = this.getOpenerEventChannel();
    //?quantity=${quantity}&matcode=${matcode}&groupCode=${groupCode}
    wx.navigateTo({
      url: `../order/order`,
      success(res){
        res.eventChannel.emit('getSelectedGoods', {
          quantity,
          matCode,
          groupCode,
          goodsItem,
          skuIds
        });
      }
    })
  },
  // 加入购物车触发事件
  addCart: function(e) {
    if (!this.data.isPanicCanBuy) return;
    if (!this.data.isSelectedAllSku) {
      wx.showToast({
        title: '请选择正确的分类',
        icon:'none'
      })
      return
    };
  
    //获取数量,价格,商品名称,id,封面图
    var num = this.data.Quantity.quantity;
    var price = this.data.goodsItem.Price;
    var id = this.data.goodsItem.MatCode;
    var title = this.data.goodsItem.MatCode;
    var img = this.data.goodsItem.images[0];
    console.log(this.data.Quantity)
    let skuIds = this.data.skuIds;
 
 
    wx.request({
      url: utils.getUrl('/shopping/cart.do?m=add'),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      data: {
        matcode: title,
        quantity: num,
        ...skuIds
      },
      success: function(res) {
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
 
        utils.showTip("添加成功!");
      },
      fail: function(errmsg) {
        utils.requestFail(errmsg,'/shopping/cart.do');
      }
    })
 
 
 
 
    this.hideLayer();
    wx.showLoading({
      title: '加载中',
    })
 
    // setTimeout(function () {
    //   wx.hideLoading();
    //   utils.showTip("添加成功!");
    // }, 1000)
 
  },
  // 立即购买触发事件
  payOrder: function(e) {
    if (!this.data.isPanicCanBuy) return;
    if (!this.data.isSelectedAllSku) {
      wx.showToast({
        title: '请选择正确的分类',
        icon:'none'
      })
      return
    };
    // utils.subscribeMessage({
    //   callback:()=>{
 
    //   }
    // })
    //获取数量,价格,商品名称,id,封面图
    var num = this.data.Quantity.quantity;
    var id = this.data.goodsItem.MatCode;
    console.log(this.data.Quantity)
    wx.showLoading({
      title: '加载中',
    })
    let skuIds = this.data.skuIds;
    wx.request({
      url: utils.getUrl('/shopping/cart.do?m=add&action=goshop'),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      data: {
        matcode: id,
        quantity: num,
        ...skuIds
      },
      success: res=> {
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
       
 
        wx.navigateTo({
          url: '../order/order?selectedCartIds='+res.data.CartId
        })
        // if(isLogin){
        //   wx.navigateTo({
        //     url: '../order/order'
        //   })
        // } else {
        //   wx.navigateTo({
        //     url: '../authorize/authorize?fromPage=cart'
        //   })
        // }
 
        // wx.switchTab({
        //   url: '../cart/cart'
        // });
      },
      fail: function(errmsg) {
        utils.requestFail(errmsg,'/shopping/cart.do');
 
      }
    })
 
 
 
 
    this.hideLayer();
 
  },
 
 
  goCart: function() {
    let tabBarList = app.globalData.tabBarList;
    let goCart = tabBarList.filter((item)=>{
      // console.log(item);
      return item.includes('/cart')
    })
    // console.log(tabBarList,goCart);
    if (goCart.length>0) {
      wx.reLaunch({
        url: '../cart/cart'
      });
    } else {
      wx.reLaunch({
        url: '../classify2/classify2'
      });
    }
   
  },
 
  goIndex: function() {
    wx.switchTab({
      url: '../index/index'
    });
  },
  goCollect: function() {
    wx.showLoading();
    wx.request({
      url: utils.getUrl('/shopping/wishlist.do?m=add&matcode=' + matcode),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      success: res => {
 
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
 
        wx.showToast({
          title: '收藏成功!'
        })
 
      },
      fail: function(errmsg) {
        utils.requestFail(errmsg,'/shopping/wishlist.do');
      }
    })
  },
  // 提交fromid
  formIdSubmit: function (e) {
    // utils.formIdSubmit(e, this);
    wx.navigateTo({
      url: '../message/message',
    })
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // 发送行为信息
    if (app.globalData.FromUserId) {
      utils.userBehavior('ViewProductDetail', {matcode:matcode});
    }
 
    // var that = this;
    // // 显示对方发来的最新消息
    // app.globalData.newMsgCallback = onMessage => {
    //   console.log('购物车页监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data))
    //   utils.msgTimer(that);
    // }
    // // 页面显示时更新未读消息的值
    // utils.refreshUnreadMsgNum(this);
  },
  onUnload(){
    imgDownloadSum=0;
    imgDownloadObj = {
      isComplete:false
    };
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    // if (ops.from === 'button') {
    //   // 来自页面内转发按钮
    //   console.log(ops.target)
    // }
 
    // console.log('title',utils.getShareTitle())
    return {
      // title: '我在' + app.globalData.titleName +'发现' + this.data.title + ',赶快来看看吧',
      title: utils.getShareTitle(),
      path: 'pages/detail/detail?FromUserId=' + app.globalData.FromUserId + '&FromOpenId=' + app.globalData.openID + '&OpenFrom=fromShare&matcode=' + matcode,
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
        // 发送行为信息
        // utils.userBehavior('ForwardMyCard');
        // utils.showModal(res)
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }
  }
 
 
 
 
})