// 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));
|
}
|
}
|
}
|
})
|