Files
AGuestSaas/pages/card/index.js
2020-12-27 09:54:49 +08:00

309 lines
8.8 KiB
JavaScript

/**
* Web唐明明
* 匆匆数载恍如梦,岁月迢迢华发增。
* 碌碌无为枉半生,一朝惊醒万事空。
*/
Page({
/**
* 页面的初始数据
*/
data: {
loding : true, //名片加载状态
cardNull : true, //是否找到了名片
isLogin : false, //登录状态
cardBase : {}, //名片基础信息
cardInfo : {}, //名片模版信息
models : [], //名片模块
cardId : "", //名片id
isOwner : false, //是否为当前管理员
isFavorite : false, //收藏状态
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(e){
this.setData({
cardId : e.cardid || ""
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 检查登录状态
wx.getStorage({
key : "token",
success : () =>{
this.setData({
isLogin: true
})
},
fail : ()=>{
this.setData({
isLogin: false
})
}
})
this.cardInfo()
},
/**
* 获取名片信息
*/
cardInfo(){
wx.$api.card.card({
cardId: this.data.cardId
}).then(res=>{
this.setData({
loding : false,
cardInfo : {
name : res.base.name,
mobileNo: res.base.mobile,
job : res.base.job,
email : res.base.email,
address : res.base.address
},
cardBase : res.base,
models : res.models,
isOwner : res.is_owner,
isFavorite : res.is_favorite
})
this.cutCard()
}).catch(err=>{
if(err.message == "暂未查到名片信息"){
this.setData({
loding : false,
cardNull: false
})
}
})
},
/**
* 名片二维码
*/
codeNav(){
wx.navigateTo({
url: "./code/code?cardid=" + this.data.cardBase.card_personal_id
})
},
/**
* 名片操作
*/
cardScroolNav(e) {
let bindType = e.currentTarget.dataset.type,
infoData = e.currentTarget.dataset.info
switch (bindType) {
case "phone":
wx.makePhoneCall({
phoneNumber: infoData,
fail : ()=>{}
})
break;
case "wechat":
wx.setClipboardData({
data : infoData
})
break;
case "email":
wx.setClipboardData({
data : infoData
})
break;
case "address":
wx.showLoading({
title: '加载中',
})
wx.$qqMap.search({
keyword: infoData,
success: res=>{
if(res.status == 0){
wx.openLocation({
latitude : res.data[0].location.lat,
longitude : res.data[0].location.lng,
name : res.data[0].title,
address : res.data[0].address
})
wx.hideLoading()
}else{
wx.showToast({
title: res.message,
icon : "none"
})
}
},
fail : ()=>{
wx.hideLoading()
}
})
break;
}
},
/**
* 收藏名片夹
*/
cardLike(){
if(!this.data.isLogin){
wx.navigateTo({
url: "/pages/login/login"
})
return
}
if(!this.data.isFavorite){
wx.$api.card.cardlike(
this.data.cardBase.card_personal_id
).then(res=>{
if(res == "操作成功"){
wx.showModal({
title : "提示",
content : "收藏成功,名片已加入您的电子名片夹,可在个人中心我的名片夹查看",
showCancel : false,
confirmText : "我知道了",
confirmColor: "#0b0041",
success : res=>{
if(res.confirm){
this.setData({
isFavorite: true
})
}
}
})
}
})
}
},
/**
* 名片设置
*/
cardSte(){
let itemLists = ["模块设置", "编辑名片", "产品管理"]
// 当前用户是否为企业管理员
if(this.data.cardBase.is_company_manage) itemLists.push("编辑企业")
wx.showActionSheet({
itemList: itemLists,
success : res=>{
let tapIndex = res.tapIndex
switch (tapIndex) {
case 0:
wx.navigateTo({
url: "./module/module"
})
break;
case 1:
wx.navigateTo({
url: "./editor/editor"
})
break;
case 2:
wx.navigateTo({
url: "./product/product"
})
break;
case 3:
this.data.models.find(val => {
if(val.name == "enterprise"){
wx.navigateTo({
url: "./company/company?id=" + val.data.id
})
return
}
})
break;
}
}
})
},
/**
* 分享名片
*/
onShareAppMessage(){
return{
title : "您好我是" + this.data.cardBase.company + "的" + this.data.cardBase.name + ",这是我的电子名片~",
path : "/pages/card/index?cardid=" + this.data.cardBase.card_personal_id,
imageUrl: this.data.cardBase.cover.showpath
}
},
/**
* 商品详情
*/
changeGood(e){
let goodsId = e.detail.goods_id
wx.showLoading({
title: "打开中...",
})
wx.navigateToMiniProgram({
appId : getApp().globalData.navAppInfo.appId,
envVersion : getApp().globalData.navAppInfo.envVersion,
path : getApp().globalData.navAppInfo.goodUrl + goodsId,
success : ()=>{
wx.hideLoading()
},
fail : err=>{
wx.showToast({
title: err.errMsg,
icon : "none"
})
}
})
},
/**
* 点击同事名片
*/
changeCard(e){
let cardId = this.data.cardBase.card_personal_id,
onCardId = e.detail.card_id
if(onCardId != cardId){
this.setData({
loding : true,
cardNull : true,
cardId : onCardId
})
this.cardInfo()
}
},
/**
* 点击动态
*/
changedynamics(e){
if(e.detail.dynamic_id){
wx.navigateTo({
url: "./dynamics/dynamics?id=" + e.detail.dynamic_id,
})
}else{
wx.showToast({
title: "系统错误,缺少参数:dynamic_id",
icon : "none"
})
}
},
/**
* 存入通讯录
*/
addPhoneBook(){
let cardInfo = this.data.cardBase
wx.addPhoneContact({
firstName : cardInfo.name || "",
mobilePhoneNumber : cardInfo.mobile || "",
weChatNumber : cardInfo.wechat || "",
organization : cardInfo.company || "",
title : cardInfo.job || "",
email : cardInfo.email || "",
remark : "通过数促会小程序智能名片添加"
})
}
})