Sanakey
2020-11-06 65c4a68484a8d6fee25d3bb94bb7a24da6dfc147
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
// pages/idcard/idcard.js
 
var utils = require("../../utils/util.js");
var app = getApp();
 
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    isShow: false,  //是否展开名片
    isAuthorize: false,
    Name: "客服",
    Position:"佛山公司",
    Mobile:"", //电话
    WeiXinUserCode:"123", //微信号
    CompanyName: "巴士软件",
    Address: "佛山市禅城区",
    Avatar: app.globalData.reqBase+"/shopping/weixinby3rd/setting/image/defaultavatar.png",
    cardStyle: 0,
    audioTime:0
 
  },
 
 
  // 全部名片
  moreInfoTap(){
    this.setData({
      isShow:!this.data.isShow
    })
  },
 
  //打电话
  phoneTap(e){
    let mobile = e.currentTarget.dataset.mobile;
    wx.makePhoneCall({
      phoneNumber: mobile,
    })
    // 发送行为信息
    utils.userBehavior('CallMe');
  },
 
  //复制
  copyTap(e){
    // console.log(e)
    wx.setClipboardData({
      data: e.currentTarget.dataset.data ,
    })
  },
  preventMove: function () {
    // 利用catchtouchmove阻止背景滚动 不用添加任何代码
    // 只适合模态层不需要滚动的场景
  },
// 分享
// shareTap(){
//   wx.showShareMenu({
//     withShareTicket: true
//   })
// },
  /**
  * 用户点击右上角分享(index.js)
  */
 
 
  // 加入手机通讯录
  newLinkman(){
    wx.addPhoneContact({
      firstName: this.data.Name,
      organization: this.data.CompanyName,
      title: this.data.Position,
      mobilePhoneNumber: this.data.Mobile,
      weChatNumber: this.data.WeiXinUserCode,
      success: ()=>{
        utils.userBehavior('SaveMePhone');
      }
    })
  },
 
  // 前往名片夹
  idCardFolder(){
    // console.log(123)
    wx.reLaunch({
      url: '../idCardFolder/idCardFolder',
    })
  },
  goQrCode(){
    // console.log(123)
    wx.navigateTo({
      url: '../shareQrcode/shareQrcode',
    })
  },
  viewAvatar(e){
    wx.previewImage({
      urls: [e.currentTarget.dataset.avatar]
    })
  },
 
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    if (!app.globalData.openID || !app.globalData.FromUserId) {
      app.globalData.idcardCallback = (res) => {
        this.getCardInfo();
        console.log('名片页cardStyle。。。', app.globalData.cardStyle)
        this.setData({
          cardStyle: app.globalData.cardStyle || 0,
          ProductListStyle:app.globalData.ProductListStyle
        })
      }
    } else{
      console.log('名片页cardStyle', app.globalData.cardStyle)
      this.getCardInfo();
      this.setData({
        cardStyle: app.globalData.cardStyle || 0,
        ProductListStyle:app.globalData.ProductListStyle
      })
    }
    // this.setData({
    //   cardStyle: app.globalData.cardStyle || 0
    // })
    // app.globalData.getCardCallback = (res) => {
    //   this.getCardInfo();
    //   // this.getGoodsList();
    //   // this.getAboutData(infordoc);
    // }
  },
  // addCart(e){
  //   let quantity = e.currentTarget.dataset.mininum||1;
  //   var matcode = e.currentTarget.dataset.matcode;
  //   wx.request({
  //     url: utils.getUrl('/shopping/cart.do?m=add'),
  //     header: {
  //       "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
  //     },
  //     data: {
  //       matcode,
  //       quantity,
  //     },
  //     success: function(res) {
  //       wx.hideLoading();
  //       if(!utils.requestError(res)){
  //         return false;
  //       }
  //       wx.setTabBarBadge({
  //         index: app.globalData.cartIndex,
  //         text: res.data['cart-num'].toString()
  //       })
  //       utils.showTip("添加成功!");
  //     },
  //     fail: function(errmsg) {
  //       utils.requestFail(errmsg,'/shopping/cart.do');
  //     }
  //   })
  // },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
// 点击授权
  getUserInfo: function (e) {
    utils.authorize(e, this)
  },
  // 提交fromid
  formIdSubmit: function (e) {
    // utils.formIdSubmit(e, this);
    wx.navigateTo({
      url: '../message/message',
    })
  },
  // btnFormIdSubmit: function (e) {
  //   utils.formIdSubmit(e, this);
  // },
  // authorizeSubmit: function (e) {
  //   utils.formIdSubmit(e, this);
  // },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 判断临时变量tempFromUserId与原FromUserId是否相等
    // 不相等说明用户切换了客服,需要重获名片数据并重连websocket,相等则不处理
    // tempFromUserId最初与FromUserId相等,会在选择名片夹时与切后台后显示时更新
    if (app.globalData.tempFromUserId !== app.globalData.FromUserId) {
      app.globalData.FromUserId = app.globalData.tempFromUserId;
      if (app.globalData.SocketTask) {
        app.globalData.SocketTask.close({
          success: (res) => {
            console.log('主动关闭 WebSocket 连接。', res)
          }
        });
        // 把上个联系人的消息清空并重连
        app.globalData.allContentList = [];
        app.globalData.unreadMsgNum = 0;
        app.socketReconnect();
      }
      
      this.getCardInfo();
      // this.getGoodsList();
      // this.getAboutData();
      
    } 
    // else{
    //   this.getCardInfo();
    //   this.getGoodsList();
    //   this.getAboutData();
    // }
    
 
    utils.cartNum();
    // utils.isAuthorize(this);
 
    // 发送行为信息
    if(app.globalData.FromUserId){
      utils.userBehavior('ViewMyCard');
    }
 
    var that = this;
    // 显示对方发来的最新消息
    app.globalData.newMsgCallback = onMessage => {
      console.log('名片页监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data))
      utils.msgTimer(that);
    }
 
    // 页面显示时更新未读消息的值
    utils.refreshUnreadMsgNum(this);
 
    // console.log('kkkkkkkkkkk', utils.getUrl('/wx/getCardUserInfo.do?FromOpenId=' + app.globalData.FromOpenId))
 
 
 
 
      // app.globalData.getCardCallback = (res) => {
      //   this.getCardInfo();
      //   this.getGoodsList();
      //   this.getAboutData();
      // }
 
 
  },
 
  getCardInfo(){
    wx.showLoading();
    console.log('/wx/getCardUserInfo.do?FromUserId=',app.globalData.FromUserId)
    // 获取名片信息
    wx.request({
      url: utils.getUrl('/wx/getCardUserInfo.do?FromUserId=' + app.globalData.FromUserId),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      success: res => {
        if(!utils.requestError(res)){
          return false;
        }
        // console.log('kkkkkkkkkkk888');
        // app.globalData.FromUserId = res.data.UserId;
        this.setData({
          ...res.data
        })
        // this.setData({
        //   Name: res.data.Name,
        //   CompanyName: res.data.CompanyName,
        //   Address: res.data.Address,
        //   Mobile: res.data.Mobile,
        //   WeiXinUserCode: res.data.WeiXinUserCode,
        //   Position: res.data.Position,
        //   Avatar: res.data.Avatar,
        //   CardImage: res.data.CardImage,
        //   Longitude: Number(res.data.Longitude),
        //   Latitude: Number(res.data.Latitude),
        //   CompanyPhoto:res.data.CompanyPhoto,
        //   EMail:res.data.EMail,
        //   IndustryTypeName:res.data.IndustryTypeName,
        //   description: res.data.Description
        //   // CompanyPhoto:res.data.CompanyPhoto,
        // })
        if (res.data.MyVoice) {
          this.handleAudio(res.data.MyVoice);
        }
        if (res.data.AboutUs) {
          this.getAboutData(res.data.AboutUs);
        }
        
        app.globalData.cardUserData = res.data;
 
      },
      fail: function (errmsg) {
        utils.requestFail(errmsg,'/wx/getCardUserInfo.do');
      },
      complete:()=>{
        wx.hideLoading();
      }
    })
  },
 
  getGoodsList(){
    wx.request({
      url: utils.getUrl('/shopping/getMatCodeList.do?fromdata=11'),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      method: "GET",
      success: (res)=> {
        console.log('推荐商品请求完成。。',utils.getUrl('/shopping/getMatCodeList.do?fromdata=11'),res)
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
        this.setData({
          goodsList: res.data.list,
        })
      },
      fail: function(errmsg) {
        utils.requestFail(errmsg, '/shopping/getMatCodeList.do');
      },
      complete: function() {
        // requestTimes++;
        // if (requestTimes == requestSum) {
        //   wx.hideLoading();
        // }
      }
 
 
    });
  },
 
  // 商品点击
  goodsItemTap: function(e) {
    
    var goodsId = e.target.dataset.goodsId;
    var externalUrl = e.target.dataset.externalUrl;
 
    // if (str ==='btnTap'){
    //   var goodsId = e.detail.target.dataset.goodsId;
    //   var externalUrl = e.detail.target.dataset.externalUrl;
    // }
 
    if (externalUrl) {
      wx.navigateTo({
        // 此时?后面的id为其他页面接收时参数后的变量名
        // url: "../webView/webView?externalUrl=" + encodeURIComponent(utils.getUrl('/shopping/mobile/product/OpenExternalUrl.jsp?matcode=' + goodsId))
        url: "../webView/webView?externalUrl=" + encodeURIComponent(externalUrl)
      })
      utils.userBehavior('ViewProductDetail',{matcode:goodsId});
    } else{
      wx.navigateTo({
        // 此时?后面的id为其他页面接收时参数后的变量名
        url: "../detail/detail?matcode=" + goodsId
      })
    }
 
    console.log(goodsId)
  },
 
  getAboutData(infordoc){
    wx.request({
      url: utils.getUrl('/shopping/information.do?m=get&OutFormat=json'),
      data:{
        infordoc:infordoc
      },
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      method: "GET",
      success: res => {
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
        this.setData({
          aboutDescription:res.data.description
          //num: 0,
          // price: goodsItem.Price
        })
      },
      fail: function (errmsg) {
        utils.requestFail(errmsg, '/shopping/getMatCodeList.do');
      }
 
    });
  },
  /*查看图片*/
  viewMyPhoto: function(e) {
    let src = e.currentTarget.dataset.src;
    let MyPhotoList = this.data.MyPhotoList.map((item)=>{
      return item.url
    })
    // console.log(src)
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: MyPhotoList // 需要预览的图片http链接列表
    })
  },
  openWxMap(e){
    // console.log(this.data.Latitude,this.data.Longitude);
    let Latitude = parseFloat(e.currentTarget.dataset.latitude);
    let Longitude = parseFloat(e.currentTarget.dataset.longitude);
    let Address = e.currentTarget.dataset.address;
    let Mobile = e.currentTarget.dataset.mobile;
    wx.openLocation({ // 打开微信内置地图,实现导航功能(在内置地图里面打开地图软件)
      latitude: Latitude,
      longitude: Longitude,
      name: Address + Mobile,
      success: function (res) {
        console.log(res);
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
 
  videoErrorCallback(e) {
    console.log('视频错误信息:')
    console.log(e.detail.errMsg)
  },
  
  handleAudio(src){
    const innerAudioContext = wx.createInnerAudioContext()
    // innerAudioContext.autoplay = true
    innerAudioContext.src = src;
    this.setData({
      innerAudioContext,
    })
    
    innerAudioContext.onPlay(() => {
      console.log('开始播放音频')
    })
    innerAudioContext.onCanplay(() => {
      console.log('可以播放')
      innerAudioContext.duration;
      setTimeout(()=>{
        this.setData({
          audioTime: Math.round(innerAudioContext.duration)
        })
      },2000)
    })
    innerAudioContext.onEnded(() => {
      console.log('停止播放')
      this.setData({
        isPlayAudio: false
      })
    })
    innerAudioContext.onError((res) => {
      console.log(res.errMsg)
      console.log(res.errCode)
    })
  },
  contrlAudio(){
    let isPlaying = this.data.isPlayAudio;
    this.setData({
      isPlayAudio: !isPlaying
    })
    if (!isPlaying) {
      this.data.innerAudioContext.play()
    }
    if (isPlaying) {
      this.data.innerAudioContext.stop()
      // this.data.innerAudioContext.onEnded(()=>{
      //   this.setData({
      //     isPlayAudio: !isPlaying
      //   })
      // })
    }
 
  },
 
  // 点赞API接口ActionType值范围:LikeMyCard:点赞我的名片 , LikeWebsite: 点赞公司官网, LikeProductDetail :点赞商品 , 
  // LikeInformation:点赞信息咨询,LikeMyVoice:点赞我的语音,LikeMyVideo:点赞我的视频,
  // LikeMyPhoto:点赞我的图片,LikeMyTag:点赞我的标签
  async saveLikeAction(params){
    // let obj = {
    //   ActionType: '',
    //   ActionName: '',
    //   ac: 'add'
    // }
 
    // Object.assign(obj,params);
    if (Object.prototype.toString.call(params) !== '[object Object]') {
      throw '参数必须是对象'
    }
    let [err,res] = await utils.to(
      wx.$http.request({
        url:'/wx/saveLikeAction.do',
        data:params
      })
    )
    return [err,res]
 
 
  },
 
  async sendLikeCard(){
    
    let [err,res] = await this.saveLikeAction({
      ActionType: 'LikeMyCard',
      ac: 'add'
    })
    if (err) {
      return;
    }
    console.log(res)
    this.setData({
      isLikeMyCardForMe:res.isLikeActionForMe,
      LikeMyCardTimes:res.likeActionTimes,
    })
  },
 
  async cancleLikeCard(){
    
    let [err,res] = await this.saveLikeAction({
      ActionType: 'LikeMyCard',
      ac: 'delete'
    })
    if (err) {
      return;
    }
    console.log(res)
    this.setData({
      isLikeMyCardForMe:res.isLikeActionForMe,
      LikeMyCardTimes:res.likeActionTimes,
    })
  },
 
  handleSendLikeCard(e){
    // let ActionName = e.currentTarget.dataset.name;
    if (!this.data.isLikeMyCardForMe) {
      this.sendLikeCard()
    } else{
      this.cancleLikeCard()
    }
  },
 
  handleSendLikeTag(e){
    let index = e.currentTarget.dataset.index;
    let isLikeMyTagForMe = this.data.MyTagList[index].isLikeMyTagForMe;
    if (!isLikeMyTagForMe) {
      this.sendLikeTag(e)
    } else{
      this.cancleLikeTag(e)
    }
  },
 
  async sendLikeTag(e){
    let ActionName = e.currentTarget.dataset.name;
    let index = e.currentTarget.dataset.index;
    let [err,res] = await this.saveLikeAction({
      ActionType: 'LikeMyTag',
      ActionName,
      ac: 'add'
    })
    if (err) {
      return;
    }
    console.log(res);
    this.setData({
      ['MyTagList['+ index +'].isLikeMyTagForMe']:res.isLikeActionForMe,
      ['MyTagList['+ index +'].LikeMyTagTimes']:res.likeActionTimes
    })
    // this.setData({
    //   isLikeCard:false
    // })
  },
 
  async cancleLikeTag(e){
    let ActionName = e.currentTarget.dataset.name;
    let index = e.currentTarget.dataset.index;
    let [err,res] = await this.saveLikeAction({
      ActionType: 'LikeMyTag',
      ActionName,
      ac: 'delete'
    })
    if (err) {
      return;
    }
    console.log(res);
    this.setData({
      ['MyTagList['+ index +'].isLikeMyTagForMe']:res.isLikeActionForMe,
      ['MyTagList['+ index +'].LikeMyTagTimes']:res.likeActionTimes
    })
    // this.setData({
    //   isLikeCard:false
    // })
  },
 
  handleIsHometown(e){
    let isHometown = this.data.IsHometown;
    if (isHometown) {
      this.cancleIsHometown()
    }
    else{
      this.sendIsHometown(e)
    }
  },
 
  async saveHometown(params){
    if (Object.prototype.toString.call(params) !== '[object Object]') {
      throw '参数必须是对象'
    }
    let [err,res] = await utils.to(
      wx.$http.request({
        url:'/wx/saveHometown.do',
        data:params
      })
    )
    return [err,res];
  },
 
  async sendIsHometown(e){
    this.setData({
      isShowDialog:true,
      GreetingsImage:e.currentTarget.dataset.src,
      Greetings:e.currentTarget.dataset.greetings
    })
    let [err,res] = await this.saveHometown({
      ac: 'add'
    })
    if (err) {
      return;
    }
    console.log(res);
    this.setData({
      IsHometown:true
    })
  },
  async cancleIsHometown(){
    let [err,res] = await this.saveHometown({
      ac: 'delete'
    })
    if (err) {
      return;
    }
    console.log(res)
    this.setData({
      IsHometown:false
    })
  },
 
  handleIsSchoolfellow(e){
    let index = e.currentTarget.dataset.index;
    let IsSchoolfellow = this.data.EducationList[index].IsSchoolfellow;
    if (IsSchoolfellow) {
      this.cancleIsSchoolfellow(e)
    }
    else{
      this.sendIsSchoolfellow(e)
    }
  },
 
  async sendIsSchoolfellow(e){
    this.setData({
      isShowDialog:true,
      GreetingsImage:e.currentTarget.dataset.src,
      Greetings:e.currentTarget.dataset.greetings,
    })
    let index = e.currentTarget.dataset.index;
    let doccode = e.currentTarget.dataset.doccode;
    let rowid = e.currentTarget.dataset.rowid;
    let [err,res] = await utils.requestSync('/wx/saveSchoolfellow.do',{
      rowid,
      doccode,
      ac: 'add'
    })
    if (err) {
      return;
    }
    console.log(res)
    this.setData({
      ['EducationList['+ index +'].IsSchoolfellow']:true
    })
  },
  async cancleIsSchoolfellow(e){
    let index = e.currentTarget.dataset.index;
    let doccode = e.currentTarget.dataset.doccode;
    let rowid = e.currentTarget.dataset.rowid;
    let [err,res] = await utils.requestSync('/wx/saveSchoolfellow.do',{
      rowid,
      doccode,
      ac: 'delete'
    })
    if (err) {
      return;
    }
    console.log(res);
    this.setData({
      ['EducationList['+ index +'].IsSchoolfellow']:false
    })
  },
  onDialogClose(){
    this.setData({
      isShowDialog:false
    })
  },
  goChat(e){
    let contactComp =  this.selectComponent('#contactComp');
    utils.isAuthorize(this);
    if(!this.data.isAuthorize){
      if (!utils.authorize(e, this)){
          e.detail.isAuthorize = false;
          contactComp.getAuthorize(e);
          return;
      }
    }
    e.detail.isAuthorize = true;
    contactComp.getAuthorize(e);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    // if (ops.from === 'button') {
    //   // 来自页面内转发按钮
    //   console.log(ops.target)
    // }
    return {
      // title: '你好,我是' + this.data.CompanyName + '的' + this.data.Name + '。这是我的名片,请惠存' ,
      title: utils.getShareTitle() || '你好,我是' + this.data.CompanyName + '的' + this.data.Name + '。这是我的名片,请惠存' ,
      path: 'pages/idCard/idCard?FromUserId=' + app.globalData.FromUserId + '&FromOpenId=' + app.globalData.openID,
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
        // 发送行为信息
        utils.userBehavior('ForwardMyCard');
        // utils.showModal(res)
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }
  }
})