|
|
@@ -95,6 +95,7 @@ import SelPopup from "./components/sel-popup.vue";
|
|
|
import { share } from "@/mixins";
|
|
|
import { mapGetters } from "vuex";
|
|
|
import { getDetail } from "@/api/goods";
|
|
|
+import { getHdInfo } from "@/api/hd";
|
|
|
import RichMediaViewer from "@/components/RichMediaViewer/index.vue";
|
|
|
export default {
|
|
|
name: "detail",
|
|
|
@@ -122,36 +123,15 @@ export default {
|
|
|
shopInfo: {},
|
|
|
};
|
|
|
},
|
|
|
- onLoad(option) {
|
|
|
- // 兼容旧版本通过 options 传递参数
|
|
|
- if (Object.keys(option).length > 0) {
|
|
|
- this.initializeOption(option);
|
|
|
- // 如果是普通路由跳转,直接获取商品信息
|
|
|
- this.getGoodsInfo();
|
|
|
- this.hdId = this.option.hdId || 0;
|
|
|
- this.account = this.option.account || 0;
|
|
|
- }
|
|
|
-
|
|
|
+ onLoad() {
|
|
|
const eventChannel = this.getOpenerEventChannel();
|
|
|
eventChannel.on('acceptDataFromChatPage', (data) => {
|
|
|
- console.log("---------- detail data: ", data);
|
|
|
- // 兼容
|
|
|
- if (Object.keys(option).length == 0) {
|
|
|
- this.option = {...data};
|
|
|
- this.hdId = this.option.hdId || 0;
|
|
|
- this.account = this.option.account || 0;
|
|
|
+ if (!this.option || Object.keys(this.option).length === 0) {
|
|
|
+ this.option = { ...data };
|
|
|
}
|
|
|
this.initializeChatPage(data);
|
|
|
- // eventChannel 执行完成后,获取商品信息
|
|
|
- this.getGoodsInfo();
|
|
|
+ this.loadGoodsDetail();
|
|
|
});
|
|
|
-
|
|
|
- // this.hdId = this.option.hdId ? this.option.hdId : 0;
|
|
|
- // this.account = this.option.account ? this.option.account : 0;
|
|
|
- // if (option.shopId || option.goodsId) {
|
|
|
- // console.log("---------- option: ", option);
|
|
|
- // this.shopInfo = option;
|
|
|
- // }
|
|
|
},
|
|
|
onPageScroll(e) {
|
|
|
// console.log('Scroll position:', parseInt(e.scrollTop))
|
|
|
@@ -172,6 +152,25 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
init() {
|
|
|
+ if (!this.option || !this.option.id) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.initializeOption(this.option);
|
|
|
+ this.hdId = this.option.hdId || 0;
|
|
|
+ this.account = this.option.account || 0;
|
|
|
+ const id = Number(this.option.id) || 0;
|
|
|
+ const account = Number(this.option.account) || 0;
|
|
|
+ if (id > 0 && account > 0) {
|
|
|
+ uni.setStorageSync('account', account);
|
|
|
+ getHdInfo().then((res) => {
|
|
|
+ if (res.code == 1 && res.data.hd && res.data.hd.id) {
|
|
|
+ this.hdId = res.data.hd.id;
|
|
|
+ }
|
|
|
+ this.loadGoodsDetail();
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.loadGoodsDetail();
|
|
|
},
|
|
|
|
|
|
initializeOption(option) {
|
|
|
@@ -216,8 +215,7 @@ export default {
|
|
|
{ key: 'hdId', type: 'positiveNumber' },
|
|
|
{ key: 'account', type: 'positiveNumber' },
|
|
|
{ key: 'shopId', type: 'positiveNumber' },
|
|
|
- { key: 'id', type: 'positiveNumber' }, // 商品id
|
|
|
- { key: 'categoryId', type: 'positiveNumber' },
|
|
|
+ { key: 'id', type: 'positiveNumber' },
|
|
|
{ key: 'name', type: 'nonEmpty' },
|
|
|
{ key: 'avatar', type: null }
|
|
|
];
|
|
|
@@ -266,25 +264,22 @@ export default {
|
|
|
);
|
|
|
}
|
|
|
},
|
|
|
- getGoodsInfo() {
|
|
|
- console.log("---------- this.option: ", this.option);
|
|
|
+ loadGoodsDetail() {
|
|
|
const id = parseInt(this.option.id);
|
|
|
if (isNaN(id) || id <= 0) {
|
|
|
this.$msg("商品id数据异常");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const categoryId = parseInt(this.option.categoryId);
|
|
|
- if (isNaN(categoryId) || categoryId <= 0) {
|
|
|
- this.$msg("商品分类数据异常");
|
|
|
- return;
|
|
|
- }
|
|
|
+ const categoryId = parseInt(this.option.categoryId) || 0;
|
|
|
+ const account = this.option.account || uni.getStorageSync('account') || 0;
|
|
|
+ const hdId = this.hdId || this.option.hdId || 0;
|
|
|
|
|
|
getDetail({
|
|
|
id: id,
|
|
|
categoryId: categoryId,
|
|
|
- account: this.option.account,
|
|
|
- hdId: this.option.hdId,
|
|
|
+ account: account,
|
|
|
+ hdId: hdId,
|
|
|
}).then((res) => {
|
|
|
// console.log('商品数据加载成功:', res.data)
|
|
|
if (this.$util.isEmpty(res.data)) {
|
|
|
@@ -315,6 +310,19 @@ export default {
|
|
|
content = (res.data.picText && res.data.picText.content) || "[]";
|
|
|
this.common_previewContent =
|
|
|
typeof content === "string" ? JSON.parse(content) : content || [];
|
|
|
+
|
|
|
+ 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}`
|
|
|
+ };
|
|
|
+ if (typeof this.jweixinFn === 'function') {
|
|
|
+ this.jweixinFn(shareParams);
|
|
|
+ }
|
|
|
});
|
|
|
},
|
|
|
// 更换数量
|