|
|
@@ -109,6 +109,7 @@ import productMins from "@/mixins/cgProduct";
|
|
|
import { mapGetters } from "vuex";
|
|
|
import { getDetail } from "@/api/goods";
|
|
|
import { getHdInfo } from "@/api/hd";
|
|
|
+import { getInfo } from "@/api/shop";
|
|
|
import RichMediaViewer from "@/components/RichMediaViewer/index.vue";
|
|
|
export default {
|
|
|
name: "detail",
|
|
|
@@ -137,6 +138,8 @@ export default {
|
|
|
common_title: "",
|
|
|
common_previewContent: [],
|
|
|
shopInfo: {},
|
|
|
+ /** 分享 path 追加 inviterCustomId 用,不改变原有 id/account 参数 */
|
|
|
+ myCustomId: 0,
|
|
|
/** 秒杀活动信息:来自首页秒杀专区/更多列表跳转带过来的 query,仅用于展示与购物车标记;
|
|
|
* 实际下单价格由后端独立核对 Redis 秒杀配置,避免前端数据被篡改 */
|
|
|
activityType: '',
|
|
|
@@ -160,6 +163,17 @@ export default {
|
|
|
beforeDestroy() {
|
|
|
this.clearSeckillTimer();
|
|
|
},
|
|
|
+ onShareAppMessage() {
|
|
|
+ const path = this.buildGoodsSharePath()
|
|
|
+ const sharePrice = this.data && this.data.priceType == 1
|
|
|
+ ? (this.data.price ? parseFloat(this.data.price).toFixed(2) : 0)
|
|
|
+ : '面议'
|
|
|
+ return {
|
|
|
+ title: ((this.data && this.data.name) || '') + ' ¥' + sharePrice,
|
|
|
+ path,
|
|
|
+ imageUrl: (this.data && (this.data.cover || this.data.smallCover)) || ''
|
|
|
+ }
|
|
|
+ },
|
|
|
onPageScroll(e) {
|
|
|
// console.log('Scroll position:', parseInt(e.scrollTop))
|
|
|
// 通过 ref 调用子组件的方法
|
|
|
@@ -252,6 +266,7 @@ export default {
|
|
|
if (res.code == 1 && res.data.hd && res.data.hd.id) {
|
|
|
this.hdId = res.data.hd.id;
|
|
|
}
|
|
|
+ this.syncMyCustomId();
|
|
|
this.loadGoodsDetail();
|
|
|
});
|
|
|
return;
|
|
|
@@ -259,6 +274,65 @@ export default {
|
|
|
this.loadGoodsDetail();
|
|
|
},
|
|
|
|
|
|
+ /** 拉取当前用户 custom.id,仅用于分享追加 inviterCustomId */
|
|
|
+ syncMyCustomId() {
|
|
|
+ const hdId = Number(this.hdId) || Number(this.option.hdId) || Number(uni.getStorageSync('hdId')) || 0
|
|
|
+ if (!hdId) {
|
|
|
+ return Promise.resolve()
|
|
|
+ }
|
|
|
+ return getInfo({ hdId }).then((res) => {
|
|
|
+ if (res.code === 1 && res.data.custom && res.data.custom.id) {
|
|
|
+ this.myCustomId = Number(res.data.custom.id)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /** 在分享 path 后追加 inviterCustomId */
|
|
|
+ appendInviterCustomId(path) {
|
|
|
+ if (this.myCustomId <= 0) {
|
|
|
+ return path
|
|
|
+ }
|
|
|
+ const sep = path.indexOf('?') >= 0 ? '&' : '?'
|
|
|
+ return path + sep + 'inviterCustomId=' + this.myCustomId
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 分享 path:与进入详情页时的 query 一致(this.option),排除 hdId,再追加 inviterCustomId
|
|
|
+ */
|
|
|
+ buildGoodsSharePath() {
|
|
|
+ const opt = this.option || {}
|
|
|
+ const skipKeys = {
|
|
|
+ hdId: true,
|
|
|
+ token: true,
|
|
|
+ inviterCustomId: true,
|
|
|
+ inviterId: true,
|
|
|
+ scene: true
|
|
|
+ }
|
|
|
+ const pairs = []
|
|
|
+ Object.keys(opt).forEach((key) => {
|
|
|
+ if (skipKeys[key]) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const val = opt[key]
|
|
|
+ if (val === undefined || val === null || val === '') {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(String(val)))
|
|
|
+ })
|
|
|
+ if (!opt.id && this.data && this.data.id) {
|
|
|
+ pairs.push('id=' + encodeURIComponent(String(this.data.id)))
|
|
|
+ }
|
|
|
+ if (!opt.account && !opt.shopId) {
|
|
|
+ const acc = uni.getStorageSync('account')
|
|
|
+ if (acc) {
|
|
|
+ pairs.push('account=' + encodeURIComponent(String(acc)))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let path = 'pages/goods/detail'
|
|
|
+ if (pairs.length) {
|
|
|
+ path += '?' + pairs.join('&')
|
|
|
+ }
|
|
|
+ return this.appendInviterCustomId(path)
|
|
|
+ },
|
|
|
+
|
|
|
initializeOption(option) {
|
|
|
this.shopInfo = {
|
|
|
...this.shopInfo,
|
|
|
@@ -401,15 +475,18 @@ export default {
|
|
|
const sharePrice = res.data.priceType == 1
|
|
|
? (res.data.price ? parseFloat(res.data.price).toFixed(2) : 0)
|
|
|
: '面议';
|
|
|
- const shareParams = {
|
|
|
- title: (res.data.name || '') + ' ¥' + sharePrice,
|
|
|
- desc: sharePrice,
|
|
|
- imgUrl: res.data.cover || res.data.smallCover || '',
|
|
|
- pagePath: `pages/goods/detail?id=${id}&account=${account}`
|
|
|
+ const applyShare = () => {
|
|
|
+ const shareParams = {
|
|
|
+ title: (res.data.name || '') + ' ¥' + sharePrice,
|
|
|
+ desc: sharePrice,
|
|
|
+ imgUrl: res.data.cover || res.data.smallCover || '',
|
|
|
+ pagePath: this.buildGoodsSharePath()
|
|
|
+ };
|
|
|
+ if (typeof this.jweixinFn === 'function') {
|
|
|
+ this.jweixinFn(shareParams);
|
|
|
+ }
|
|
|
};
|
|
|
- if (typeof this.jweixinFn === 'function') {
|
|
|
- this.jweixinFn(shareParams);
|
|
|
- }
|
|
|
+ this.syncMyCustomId().finally(applyShare);
|
|
|
});
|
|
|
},
|
|
|
// 更换数量
|