Sanakey
2020-11-06 65c4a68484a8d6fee25d3bb94bb7a24da6dfc147
提交 | 用户 | age
d98d05 1 // pages/idcard/idcard.js
S 2
3 var utils = require("../../utils/util.js");
4 var app = getApp();
5
6 Page({
7
8   /**
9    * 页面的初始数据
10    */
11   data: {
12     isShow: false,  //是否展开名片
13     isAuthorize: false,
14     Name: "客服",
15     Position:"佛山公司",
16     Mobile:"", //电话
17     WeiXinUserCode:"123", //微信号
18     CompanyName: "巴士软件",
19     Address: "佛山市禅城区",
20     Avatar: app.globalData.reqBase+"/shopping/weixinby3rd/setting/image/defaultavatar.png",
21     cardStyle: 0,
22     audioTime:0
23
24   },
25
26
27   // 全部名片
28   moreInfoTap(){
29     this.setData({
30       isShow:!this.data.isShow
31     })
32   },
33
34   //打电话
35   phoneTap(e){
36     let mobile = e.currentTarget.dataset.mobile;
37     wx.makePhoneCall({
38       phoneNumber: mobile,
39     })
40     // 发送行为信息
41     utils.userBehavior('CallMe');
42   },
43
44   //复制
45   copyTap(e){
46     // console.log(e)
47     wx.setClipboardData({
48       data: e.currentTarget.dataset.data ,
49     })
50   },
51   preventMove: function () {
52     // 利用catchtouchmove阻止背景滚动 不用添加任何代码
53     // 只适合模态层不需要滚动的场景
54   },
55 // 分享
56 // shareTap(){
57 //   wx.showShareMenu({
58 //     withShareTicket: true
59 //   })
60 // },
61   /**
62   * 用户点击右上角分享(index.js)
63   */
64
65
66   // 加入手机通讯录
67   newLinkman(){
68     wx.addPhoneContact({
69       firstName: this.data.Name,
70       organization: this.data.CompanyName,
71       title: this.data.Position,
72       mobilePhoneNumber: this.data.Mobile,
73       weChatNumber: this.data.WeiXinUserCode,
74       success: ()=>{
75         utils.userBehavior('SaveMePhone');
76       }
77     })
78   },
79
80   // 前往名片夹
81   idCardFolder(){
82     // console.log(123)
83     wx.reLaunch({
84       url: '../idCardFolder/idCardFolder',
85     })
86   },
87   goQrCode(){
88     // console.log(123)
89     wx.navigateTo({
90       url: '../shareQrcode/shareQrcode',
91     })
92   },
93   viewAvatar(e){
94     wx.previewImage({
95       urls: [e.currentTarget.dataset.avatar]
96     })
97   },
98
99
100   /**
101    * 生命周期函数--监听页面加载
102    */
103   onLoad: function (options) {
104     
105     if (!app.globalData.openID || !app.globalData.FromUserId) {
106       app.globalData.idcardCallback = (res) => {
107         this.getCardInfo();
108         console.log('名片页cardStyle。。。', app.globalData.cardStyle)
109         this.setData({
110           cardStyle: app.globalData.cardStyle || 0,
111           ProductListStyle:app.globalData.ProductListStyle
112         })
113       }
114     } else{
115       console.log('名片页cardStyle', app.globalData.cardStyle)
116       this.getCardInfo();
117       this.setData({
118         cardStyle: app.globalData.cardStyle || 0,
119         ProductListStyle:app.globalData.ProductListStyle
120       })
121     }
122     // this.setData({
123     //   cardStyle: app.globalData.cardStyle || 0
124     // })
125     // app.globalData.getCardCallback = (res) => {
126     //   this.getCardInfo();
127     //   // this.getGoodsList();
128     //   // this.getAboutData(infordoc);
129     // }
130   },
131   // addCart(e){
132   //   let quantity = e.currentTarget.dataset.mininum||1;
133   //   var matcode = e.currentTarget.dataset.matcode;
134   //   wx.request({
135   //     url: utils.getUrl('/shopping/cart.do?m=add'),
136   //     header: {
137   //       "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
138   //     },
139   //     data: {
140   //       matcode,
141   //       quantity,
142   //     },
143   //     success: function(res) {
144   //       wx.hideLoading();
145   //       if(!utils.requestError(res)){
146   //         return false;
147   //       }
148   //       wx.setTabBarBadge({
149   //         index: app.globalData.cartIndex,
150   //         text: res.data['cart-num'].toString()
151   //       })
152   //       utils.showTip("添加成功!");
153   //     },
154   //     fail: function(errmsg) {
155   //       utils.requestFail(errmsg,'/shopping/cart.do');
156   //     }
157   //   })
158   // },
159   /**
160    * 生命周期函数--监听页面初次渲染完成
161    */
162   onReady: function () {
163
164   },
165 // 点击授权
166   getUserInfo: function (e) {
167     utils.authorize(e, this)
168   },
169   // 提交fromid
170   formIdSubmit: function (e) {
171     // utils.formIdSubmit(e, this);
172     wx.navigateTo({
173       url: '../message/message',
174     })
175   },
176   // btnFormIdSubmit: function (e) {
177   //   utils.formIdSubmit(e, this);
178   // },
179   // authorizeSubmit: function (e) {
180   //   utils.formIdSubmit(e, this);
181   // },
182
183   /**
184    * 生命周期函数--监听页面显示
185    */
186   onShow: function () {
187     // 判断临时变量tempFromUserId与原FromUserId是否相等
188     // 不相等说明用户切换了客服,需要重获名片数据并重连websocket,相等则不处理
189     // tempFromUserId最初与FromUserId相等,会在选择名片夹时与切后台后显示时更新
190     if (app.globalData.tempFromUserId !== app.globalData.FromUserId) {
191       app.globalData.FromUserId = app.globalData.tempFromUserId;
192       if (app.globalData.SocketTask) {
193         app.globalData.SocketTask.close({
194           success: (res) => {
195             console.log('主动关闭 WebSocket 连接。', res)
196           }
197         });
198         // 把上个联系人的消息清空并重连
199         app.globalData.allContentList = [];
200         app.globalData.unreadMsgNum = 0;
201         app.socketReconnect();
202       }
203       
204       this.getCardInfo();
205       // this.getGoodsList();
206       // this.getAboutData();
207       
208     } 
209     // else{
210     //   this.getCardInfo();
211     //   this.getGoodsList();
212     //   this.getAboutData();
213     // }
214     
215
216     utils.cartNum();
217     // utils.isAuthorize(this);
218
219     // 发送行为信息
220     if(app.globalData.FromUserId){
221       utils.userBehavior('ViewMyCard');
222     }
223
224     var that = this;
225     // 显示对方发来的最新消息
226     app.globalData.newMsgCallback = onMessage => {
227       console.log('名片页监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data))
228       utils.msgTimer(that);
229     }
230
231     // 页面显示时更新未读消息的值
232     utils.refreshUnreadMsgNum(this);
233
234     // console.log('kkkkkkkkkkk', utils.getUrl('/wx/getCardUserInfo.do?FromOpenId=' + app.globalData.FromOpenId))
235
236
237
238
239       // app.globalData.getCardCallback = (res) => {
240       //   this.getCardInfo();
241       //   this.getGoodsList();
242       //   this.getAboutData();
243       // }
244
245
246   },
247
248   getCardInfo(){
249     wx.showLoading();
250     console.log('/wx/getCardUserInfo.do?FromUserId=',app.globalData.FromUserId)
251     // 获取名片信息
252     wx.request({
253       url: utils.getUrl('/wx/getCardUserInfo.do?FromUserId=' + app.globalData.FromUserId),
254       header: {
255         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
256       },
257       success: res => {
258         if(!utils.requestError(res)){
259           return false;
260         }
261         // console.log('kkkkkkkkkkk888');
262         // app.globalData.FromUserId = res.data.UserId;
263         this.setData({
264           ...res.data
265         })
266         // this.setData({
267         //   Name: res.data.Name,
268         //   CompanyName: res.data.CompanyName,
269         //   Address: res.data.Address,
270         //   Mobile: res.data.Mobile,
271         //   WeiXinUserCode: res.data.WeiXinUserCode,
272         //   Position: res.data.Position,
273         //   Avatar: res.data.Avatar,
274         //   CardImage: res.data.CardImage,
275         //   Longitude: Number(res.data.Longitude),
276         //   Latitude: Number(res.data.Latitude),
277         //   CompanyPhoto:res.data.CompanyPhoto,
278         //   EMail:res.data.EMail,
279         //   IndustryTypeName:res.data.IndustryTypeName,
280         //   description: res.data.Description
281         //   // CompanyPhoto:res.data.CompanyPhoto,
282         // })
283         if (res.data.MyVoice) {
284           this.handleAudio(res.data.MyVoice);
285         }
286         if (res.data.AboutUs) {
287           this.getAboutData(res.data.AboutUs);
288         }
289         
290         app.globalData.cardUserData = res.data;
291
292       },
293       fail: function (errmsg) {
294         utils.requestFail(errmsg,'/wx/getCardUserInfo.do');
295       },
296       complete:()=>{
297         wx.hideLoading();
298       }
299     })
300   },
301
302   getGoodsList(){
303     wx.request({
304       url: utils.getUrl('/shopping/getMatCodeList.do?fromdata=11'),
305       header: {
306         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
307       },
308       method: "GET",
309       success: (res)=> {
310         console.log('推荐商品请求完成。。',utils.getUrl('/shopping/getMatCodeList.do?fromdata=11'),res)
311         wx.hideLoading();
312         if(!utils.requestError(res)){
313           return false;
314         }
315         this.setData({
316           goodsList: res.data.list,
317         })
318       },
319       fail: function(errmsg) {
320         utils.requestFail(errmsg, '/shopping/getMatCodeList.do');
321       },
322       complete: function() {
323         // requestTimes++;
324         // if (requestTimes == requestSum) {
325         //   wx.hideLoading();
326         // }
327       }
328
329
330     });
331   },
332
333   // 商品点击
334   goodsItemTap: function(e) {
335     
336     var goodsId = e.target.dataset.goodsId;
337     var externalUrl = e.target.dataset.externalUrl;
338
339     // if (str ==='btnTap'){
340     //   var goodsId = e.detail.target.dataset.goodsId;
341     //   var externalUrl = e.detail.target.dataset.externalUrl;
342     // }
343
344     if (externalUrl) {
345       wx.navigateTo({
346         // 此时?后面的id为其他页面接收时参数后的变量名
347         // url: "../webView/webView?externalUrl=" + encodeURIComponent(utils.getUrl('/shopping/mobile/product/OpenExternalUrl.jsp?matcode=' + goodsId))
348         url: "../webView/webView?externalUrl=" + encodeURIComponent(externalUrl)
349       })
350       utils.userBehavior('ViewProductDetail',{matcode:goodsId});
351     } else{
352       wx.navigateTo({
353         // 此时?后面的id为其他页面接收时参数后的变量名
354         url: "../detail/detail?matcode=" + goodsId
355       })
356     }
357
358     console.log(goodsId)
359   },
360
361   getAboutData(infordoc){
362     wx.request({
363       url: utils.getUrl('/shopping/information.do?m=get&OutFormat=json'),
364       data:{
365         infordoc:infordoc
366       },
367       header: {
368         "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
369       },
370       method: "GET",
371       success: res => {
372         wx.hideLoading();
373         if(!utils.requestError(res)){
374           return false;
375         }
376         this.setData({
377           aboutDescription:res.data.description
378           //num: 0,
379           // price: goodsItem.Price
380         })
381       },
382       fail: function (errmsg) {
383         utils.requestFail(errmsg, '/shopping/getMatCodeList.do');
384       }
385
386     });
387   },
388   /*查看图片*/
389   viewMyPhoto: function(e) {
390     let src = e.currentTarget.dataset.src;
391     let MyPhotoList = this.data.MyPhotoList.map((item)=>{
392       return item.url
393     })
394     // console.log(src)
395     wx.previewImage({
396       current: src, // 当前显示图片的http链接
397       urls: MyPhotoList // 需要预览的图片http链接列表
398     })
399   },
400   openWxMap(e){
401     // console.log(this.data.Latitude,this.data.Longitude);
402     let Latitude = parseFloat(e.currentTarget.dataset.latitude);
403     let Longitude = parseFloat(e.currentTarget.dataset.longitude);
404     let Address = e.currentTarget.dataset.address;
405     let Mobile = e.currentTarget.dataset.mobile;
406     wx.openLocation({ // 打开微信内置地图,实现导航功能(在内置地图里面打开地图软件)
407       latitude: Latitude,
408       longitude: Longitude,
409       name: Address + Mobile,
410       success: function (res) {
411         console.log(res);
412       },
413       fail: function (res) {
414         console.log(res);
415       }
416     });
417   },
418
419   videoErrorCallback(e) {
420     console.log('视频错误信息:')
421     console.log(e.detail.errMsg)
422   },
423   
424   handleAudio(src){
425     const innerAudioContext = wx.createInnerAudioContext()
426     // innerAudioContext.autoplay = true
427     innerAudioContext.src = src;
428     this.setData({
429       innerAudioContext,
430     })
431     
432     innerAudioContext.onPlay(() => {
433       console.log('开始播放音频')
434     })
435     innerAudioContext.onCanplay(() => {
436       console.log('可以播放')
437       innerAudioContext.duration;
438       setTimeout(()=>{
439         this.setData({
440           audioTime: Math.round(innerAudioContext.duration)
441         })
442       },2000)
443     })
444     innerAudioContext.onEnded(() => {
445       console.log('停止播放')
446       this.setData({
447         isPlayAudio: false
448       })
449     })
450     innerAudioContext.onError((res) => {
451       console.log(res.errMsg)
452       console.log(res.errCode)
453     })
454   },
455   contrlAudio(){
456     let isPlaying = this.data.isPlayAudio;
457     this.setData({
458       isPlayAudio: !isPlaying
459     })
460     if (!isPlaying) {
461       this.data.innerAudioContext.play()
462     }
463     if (isPlaying) {
464       this.data.innerAudioContext.stop()
465       // this.data.innerAudioContext.onEnded(()=>{
466       //   this.setData({
467       //     isPlayAudio: !isPlaying
468       //   })
469       // })
470     }
471
472   },
473
474   // 点赞API接口ActionType值范围:LikeMyCard:点赞我的名片 , LikeWebsite: 点赞公司官网, LikeProductDetail :点赞商品 , 
475   // LikeInformation:点赞信息咨询,LikeMyVoice:点赞我的语音,LikeMyVideo:点赞我的视频,
476   // LikeMyPhoto:点赞我的图片,LikeMyTag:点赞我的标签
477   async saveLikeAction(params){
478     // let obj = {
479     //   ActionType: '',
480     //   ActionName: '',
481     //   ac: 'add'
482     // }
483
484     // Object.assign(obj,params);
485     if (Object.prototype.toString.call(params) !== '[object Object]') {
486       throw '参数必须是对象'
487     }
488     let [err,res] = await utils.to(
489       wx.$http.request({
490         url:'/wx/saveLikeAction.do',
491         data:params
492       })
493     )
494     return [err,res]
495
496
497   },
498
499   async sendLikeCard(){
500     
501     let [err,res] = await this.saveLikeAction({
502       ActionType: 'LikeMyCard',
503       ac: 'add'
504     })
505     if (err) {
506       return;
507     }
508     console.log(res)
509     this.setData({
510       isLikeMyCardForMe:res.isLikeActionForMe,
511       LikeMyCardTimes:res.likeActionTimes,
512     })
513   },
514
515   async cancleLikeCard(){
516     
517     let [err,res] = await this.saveLikeAction({
518       ActionType: 'LikeMyCard',
519       ac: 'delete'
520     })
521     if (err) {
522       return;
523     }
524     console.log(res)
525     this.setData({
526       isLikeMyCardForMe:res.isLikeActionForMe,
527       LikeMyCardTimes:res.likeActionTimes,
528     })
529   },
530
531   handleSendLikeCard(e){
532     // let ActionName = e.currentTarget.dataset.name;
533     if (!this.data.isLikeMyCardForMe) {
534       this.sendLikeCard()
535     } else{
536       this.cancleLikeCard()
537     }
538   },
539
540   handleSendLikeTag(e){
541     let index = e.currentTarget.dataset.index;
542     let isLikeMyTagForMe = this.data.MyTagList[index].isLikeMyTagForMe;
543     if (!isLikeMyTagForMe) {
544       this.sendLikeTag(e)
545     } else{
546       this.cancleLikeTag(e)
547     }
548   },
549
550   async sendLikeTag(e){
551     let ActionName = e.currentTarget.dataset.name;
552     let index = e.currentTarget.dataset.index;
553     let [err,res] = await this.saveLikeAction({
554       ActionType: 'LikeMyTag',
555       ActionName,
556       ac: 'add'
557     })
558     if (err) {
559       return;
560     }
561     console.log(res);
562     this.setData({
563       ['MyTagList['+ index +'].isLikeMyTagForMe']:res.isLikeActionForMe,
564       ['MyTagList['+ index +'].LikeMyTagTimes']:res.likeActionTimes
565     })
566     // this.setData({
567     //   isLikeCard:false
568     // })
569   },
570
571   async cancleLikeTag(e){
572     let ActionName = e.currentTarget.dataset.name;
573     let index = e.currentTarget.dataset.index;
574     let [err,res] = await this.saveLikeAction({
575       ActionType: 'LikeMyTag',
576       ActionName,
577       ac: 'delete'
578     })
579     if (err) {
580       return;
581     }
582     console.log(res);
583     this.setData({
584       ['MyTagList['+ index +'].isLikeMyTagForMe']:res.isLikeActionForMe,
585       ['MyTagList['+ index +'].LikeMyTagTimes']:res.likeActionTimes
586     })
587     // this.setData({
588     //   isLikeCard:false
589     // })
590   },
591
592   handleIsHometown(e){
593     let isHometown = this.data.IsHometown;
594     if (isHometown) {
595       this.cancleIsHometown()
596     }
597     else{
598       this.sendIsHometown(e)
599     }
600   },
601
602   async saveHometown(params){
603     if (Object.prototype.toString.call(params) !== '[object Object]') {
604       throw '参数必须是对象'
605     }
606     let [err,res] = await utils.to(
607       wx.$http.request({
608         url:'/wx/saveHometown.do',
609         data:params
610       })
611     )
612     return [err,res];
613   },
614
615   async sendIsHometown(e){
616     this.setData({
617       isShowDialog:true,
618       GreetingsImage:e.currentTarget.dataset.src,
619       Greetings:e.currentTarget.dataset.greetings
620     })
621     let [err,res] = await this.saveHometown({
622       ac: 'add'
623     })
624     if (err) {
625       return;
626     }
627     console.log(res);
628     this.setData({
629       IsHometown:true
630     })
631   },
632   async cancleIsHometown(){
633     let [err,res] = await this.saveHometown({
634       ac: 'delete'
635     })
636     if (err) {
637       return;
638     }
639     console.log(res)
640     this.setData({
641       IsHometown:false
642     })
643   },
644
645   handleIsSchoolfellow(e){
646     let index = e.currentTarget.dataset.index;
647     let IsSchoolfellow = this.data.EducationList[index].IsSchoolfellow;
648     if (IsSchoolfellow) {
649       this.cancleIsSchoolfellow(e)
650     }
651     else{
652       this.sendIsSchoolfellow(e)
653     }
654   },
655
656   async sendIsSchoolfellow(e){
657     this.setData({
658       isShowDialog:true,
659       GreetingsImage:e.currentTarget.dataset.src,
660       Greetings:e.currentTarget.dataset.greetings,
661     })
662     let index = e.currentTarget.dataset.index;
663     let doccode = e.currentTarget.dataset.doccode;
664     let rowid = e.currentTarget.dataset.rowid;
665     let [err,res] = await utils.requestSync('/wx/saveSchoolfellow.do',{
666       rowid,
667       doccode,
668       ac: 'add'
669     })
670     if (err) {
671       return;
672     }
673     console.log(res)
674     this.setData({
675       ['EducationList['+ index +'].IsSchoolfellow']:true
676     })
677   },
678   async cancleIsSchoolfellow(e){
679     let index = e.currentTarget.dataset.index;
680     let doccode = e.currentTarget.dataset.doccode;
681     let rowid = e.currentTarget.dataset.rowid;
682     let [err,res] = await utils.requestSync('/wx/saveSchoolfellow.do',{
683       rowid,
684       doccode,
685       ac: 'delete'
686     })
687     if (err) {
688       return;
689     }
690     console.log(res);
691     this.setData({
692       ['EducationList['+ index +'].IsSchoolfellow']:false
693     })
694   },
695   onDialogClose(){
696     this.setData({
697       isShowDialog:false
698     })
699   },
700   goChat(e){
701     let contactComp =  this.selectComponent('#contactComp');
702     utils.isAuthorize(this);
703     if(!this.data.isAuthorize){
704       if (!utils.authorize(e, this)){
705           e.detail.isAuthorize = false;
706           contactComp.getAuthorize(e);
707           return;
708       }
709     }
710     e.detail.isAuthorize = true;
711     contactComp.getAuthorize(e);
712   },
713   /**
714    * 生命周期函数--监听页面隐藏
715    */
716   onHide: function () {
717
718   },
719
720   /**
721    * 生命周期函数--监听页面卸载
722    */
723   onUnload: function () {
724
725   },
726
727   /**
728    * 页面相关事件处理函数--监听用户下拉动作
729    */
730   onPullDownRefresh: function () {
731
732   },
733
734   /**
735    * 页面上拉触底事件的处理函数
736    */
737   onReachBottom: function () {
738
739   },
740
741   /**
742    * 用户点击右上角分享
743    */
744   onShareAppMessage: function () {
745     // if (ops.from === 'button') {
746     //   // 来自页面内转发按钮
747     //   console.log(ops.target)
748     // }
749     return {
750       // title: '你好,我是' + this.data.CompanyName + '的' + this.data.Name + '。这是我的名片,请惠存' ,
751       title: utils.getShareTitle() || '你好,我是' + this.data.CompanyName + '的' + this.data.Name + '。这是我的名片,请惠存' ,
752       path: 'pages/idCard/idCard?FromUserId=' + app.globalData.FromUserId + '&FromOpenId=' + app.globalData.openID,
753       success: function (res) {
754         // 转发成功
755         console.log("转发成功:" + JSON.stringify(res));
756         // 发送行为信息
757         utils.userBehavior('ForwardMyCard');
758         // utils.showModal(res)
759       },
760       fail: function (res) {
761         // 转发失败
762         console.log("转发失败:" + JSON.stringify(res));
763       }
764     }
765   }
766 })