|
|
import utils from "@/utils/utils.js";
|
|
|
import wxConfig from '@/utils/wxConfig'
|
|
|
|
|
|
export default {
|
|
|
data() {
|
|
|
return {}
|
|
|
},
|
|
|
computed: {
|
|
|
publicImage() {
|
|
|
return this.$store.state.$Gimage || {}
|
|
|
},
|
|
|
storeDetail() {
|
|
|
return this.$store.state.$GstoreDetail || {}
|
|
|
}
|
|
|
},
|
|
|
onLoad() {
|
|
|
if (utils.isInWeChatBrowser()) {
|
|
|
if (uni.getStorageSync("sharePage")) {
|
|
|
this.diySharePage(uni.getStorageSync("sharePage"))
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
// 获取当前登录信息
|
|
|
getUser(key) {
|
|
|
const user_info = uni.getStorageSync('user_info')
|
|
|
return user_info[key] || user_info || {}
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 复制文本到剪贴板
|
|
|
* @param {string} e - 要复制的文本
|
|
|
* @returns {void}
|
|
|
* @vue/component
|
|
|
*/
|
|
|
copy(e) {
|
|
|
uni.setClipboardData({
|
|
|
data: e,
|
|
|
showToast: false,
|
|
|
success: () => {
|
|
|
this.$u.toast('复制成功');
|
|
|
},
|
|
|
fail: () => {
|
|
|
this.$u.toast('复制失败,请检查权限!');
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
|
|
|
// 领取优惠券
|
|
|
async getACoupon({
|
|
|
id
|
|
|
}) {
|
|
|
try {
|
|
|
const res = await this.$api.coupon.getCoupon({
|
|
|
id
|
|
|
});
|
|
|
if (res.code != 0) {
|
|
|
throw new Error(res)
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log({
|
|
|
getACoupon: error
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 成为下线的条件 = 首次点击链接
|
|
|
// 存在推荐人时调用 => 后台去判断成为下线条件
|
|
|
async initDistributor(id = 0) {
|
|
|
if (!id) {
|
|
|
return
|
|
|
}
|
|
|
try {
|
|
|
setTimeout(async () => {
|
|
|
const res = await this.$api.distSales.ApplyForNext({
|
|
|
foke_parent_user: id || uni.getStorageSync('distributor_id') || 0
|
|
|
})
|
|
|
if (res.code === 0) {
|
|
|
console.log("initDistributor调用成功");
|
|
|
}
|
|
|
}, 1000)
|
|
|
} catch (e) {
|
|
|
console.log({
|
|
|
initDistributorError: e
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 访问记录
|
|
|
async initLog({
|
|
|
mch_id = 0
|
|
|
} = {}) {
|
|
|
try {
|
|
|
if (uni.getStorageSync("token")) {
|
|
|
setTimeout(async () => {
|
|
|
const res = await this.$api.user.log({
|
|
|
mch_id
|
|
|
})
|
|
|
if (res.code === 0) {
|
|
|
console.log("iinitLog调用成功");
|
|
|
}
|
|
|
}, 1000)
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.log({
|
|
|
initLogError: e
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
|
|
|
diySharePage(data = {}) {
|
|
|
uni.removeStorageSync('sharePage');
|
|
|
let base_url = window.location.href;
|
|
|
const that = this
|
|
|
|
|
|
// 获取用户ID
|
|
|
const userId = this.getUser("id");
|
|
|
|
|
|
// 构建基本的查询字符串
|
|
|
let queryString = `distributor_id=${userId}`;
|
|
|
|
|
|
// 检查是否已经存在参数
|
|
|
if (base_url.includes('?')) {
|
|
|
// 如果已经存在参数,在原有参数的基础上添加新参数
|
|
|
queryString = `${base_url}&${queryString}`;
|
|
|
} else {
|
|
|
// 如果不存在参数,直接添加新参数
|
|
|
queryString = `${base_url}?${queryString}`;
|
|
|
}
|
|
|
|
|
|
wxConfig.init(['updateAppMessageShareData', 'updateTimelineShareData']).then(wx => {
|
|
|
wx.updateAppMessageShareData({
|
|
|
title: data.name || data.title || that.storeDetail.name, // 分享标题
|
|
|
desc: data.desc || '', // 分享描述
|
|
|
link: queryString, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
|
imgUrl: data.imageUrl ? this.httpToHttps(data.imageUrl) : this.httpToHttps(that
|
|
|
.storeDetail.logo_url), // 分享图标
|
|
|
success: function() {
|
|
|
// 设置成功
|
|
|
}
|
|
|
})
|
|
|
|
|
|
wx.updateTimelineShareData({
|
|
|
title: data.name || data.title || that.storeDetail.name, // 分享标题
|
|
|
desc: data.desc || '', // 分享描述
|
|
|
link: queryString, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
|
imgUrl: data.imageUrl ? this.httpToHttps(data.imageUrl) : this.httpToHttps(that
|
|
|
.storeDetail.logo_url), // 分享图标
|
|
|
success: function() {
|
|
|
// 设置成功
|
|
|
}
|
|
|
})
|
|
|
|
|
|
})
|
|
|
},
|
|
|
|
|
|
httpToHttps: utils.httpToHttps,
|
|
|
toUrl: utils.toUrl,
|
|
|
kmUnit: utils.kmUnit,
|
|
|
}
|
|
|
}; |