web/buyer/src/pages/GoodsDetail.vue

234 lines
6.6 KiB
Vue
Raw Normal View History

2021-05-13 10:56:04 +08:00
<template>
2022-05-27 10:28:37 +08:00
<div style="background: #fff">
2021-05-13 10:56:04 +08:00
<BaseHeader></BaseHeader>
<Search></Search>
<drawer></drawer>
2021-05-28 17:25:07 +08:00
<ShopHeader :detail="storeMsg"></ShopHeader>
2021-05-13 10:56:04 +08:00
<div class="shop-item-path">
<div class="shop-nav-container">
<Breadcrumb>
<BreadcrumbItem to="/">首页</BreadcrumbItem>
2022-12-28 11:23:46 +08:00
<BreadcrumbItem v-for="(item, index) in categoryBar" :to="goGoodsList(index)" target="_blank" :key="index">
2021-08-11 22:53:47 +08:00
{{ item.name }}
</BreadcrumbItem>
2021-05-13 10:56:04 +08:00
</Breadcrumb>
<div class="store-collect" v-if="!takeDownSale">
2021-12-20 16:48:08 +08:00
<span class="mr_10" v-if="goodsMsg.data">
2022-05-27 10:28:37 +08:00
<router-link :to="'Merchant?id=' + goodsMsg.data.storeId">{{
2023-01-10 18:44:39 +08:00
goodsMsg.data.storeName
}}</router-link>
2021-12-20 16:48:08 +08:00
</span>
<span @click="collect">
2022-12-28 11:23:46 +08:00
<Icon type="ios-heart" :color="storeCollected ? '#ed3f14' : '#666'" />
2023-01-10 18:44:39 +08:00
{{ storeCollected? "已收藏店铺": "收藏店铺" }}
2021-12-20 16:48:08 +08:00
</span>
2023-06-01 10:10:51 +08:00
<span class="ml_10" @click="IMService(goodsMsg.data.storeId,goodsMsg.data.goodsId,goodsMsg.data.id)">联系客服</span>
2021-05-13 10:56:04 +08:00
</div>
</div>
</div>
2022-05-27 10:28:37 +08:00
2021-05-13 10:56:04 +08:00
<!-- 商品信息展示 -->
2022-12-28 11:23:46 +08:00
<ShowGoods @handleClickSku="targetClickSku" v-if="goodsMsg.data" :detail="goodsMsg"></ShowGoods>
2021-05-13 10:56:04 +08:00
<!-- 商品详细展示 -->
<ShowGoodsDetail v-if="goodsMsg.data" :detail="goodsMsg"></ShowGoodsDetail>
<empty _Title='当前商品已下架' v-if="takeDownSale">
<div class="sale-btn">
<Button size="small" class="mr_10" @click="target('/')">返回首页</Button>
<Button size="small" @click="target('goodsList')">返回商品列表</Button>
</div>
</empty>
2021-05-13 10:56:04 +08:00
<Spin size="large" fix v-if="isLoading"></Spin>
<BaseFooter></BaseFooter>
</div>
</template>
<script>
2021-12-20 16:48:08 +08:00
import Search from "@/components/Search";
import ShopHeader from "@/components/header/ShopHeader";
import ShowGoods from "@/components/goodsDetail/ShowGoods";
import empty from "@/components/empty/Main";
2021-12-20 16:48:08 +08:00
import ShowGoodsDetail from "@/components/goodsDetail/ShowGoodsDetail";
import { goodsSkuDetail } from "@/api/goods";
import {
2023-03-09 18:16:10 +08:00
cancelStoreCollect,
collectStore,
isStoreCollection,
2021-12-20 16:48:08 +08:00
getGoodsDistribution,
} from "@/api/member";
import { getDetailById } from "@/api/shopentry";
import imTalk from '@/components/mixes/talkIm'
2021-05-13 10:56:04 +08:00
export default {
2021-12-20 16:48:08 +08:00
name: "GoodsDetail",
2022-12-28 11:23:46 +08:00
beforeRouteEnter (to, from, next) {
2021-05-13 10:56:04 +08:00
window.scrollTo(0, 0);
next();
},
2022-12-28 11:23:46 +08:00
created () {
2021-05-13 10:56:04 +08:00
this.getGoodsDetail();
},
mixins: [imTalk],
2022-12-28 11:23:46 +08:00
data () {
2021-05-13 10:56:04 +08:00
return {
2021-05-13 11:35:57 +08:00
goodsMsg: {}, // 商品信息
isLoading: false, // 加载状态
categoryBar: [], // 分类
2021-05-28 17:25:07 +08:00
storeCollected: false, // 商品收藏
2021-12-20 16:48:08 +08:00
storeMsg: {}, // 店铺信息
takeDownSale:false, // 是否下架
2021-05-13 10:56:04 +08:00
};
},
methods: {
// 跳转首页或商品页面
target(url){
this.$router.push({path: url})
},
2022-05-27 10:28:37 +08:00
// 点击规格
2022-12-28 11:23:46 +08:00
targetClickSku (val) {
2022-05-27 10:28:37 +08:00
this.getGoodsDetail(val);
},
2021-07-31 09:49:17 +08:00
// 获取商品详情
2022-12-28 11:23:46 +08:00
getGoodsDetail (val) {
2021-05-13 10:56:04 +08:00
this.isLoading = true;
2022-05-27 10:28:37 +08:00
const params = val || this.$route.query;
2021-08-11 22:53:47 +08:00
// 分销员id
2021-12-20 16:48:08 +08:00
let distributionId =
params && params.distributionId
? params.distributionId
: this.Cookies.getItem("distributionId");
2021-08-11 22:53:47 +08:00
// 如果有分销信息
if (distributionId) {
2021-12-20 16:48:08 +08:00
console.log(distributionId);
2021-08-11 22:53:47 +08:00
// 先存储
2021-12-20 16:48:08 +08:00
this.Cookies.setItem("distributionId", params.distributionId);
2021-08-11 22:53:47 +08:00
let _this = this;
// 绑定关系
2021-12-20 16:48:08 +08:00
getGoodsDistribution(params.distributionId).then((res) => {
2021-08-11 22:53:47 +08:00
// 绑定成功,则清除关系
if (res.success) {
2021-12-20 16:48:08 +08:00
_this.Cookies.removeItem("distributionId");
2021-08-11 22:53:47 +08:00
}
2021-12-20 16:48:08 +08:00
});
2021-08-11 22:53:47 +08:00
}
2021-12-20 16:48:08 +08:00
goodsSkuDetail(params)
.then((res) => {
this.isLoading = false;
if (res.success) {
2021-12-20 16:48:08 +08:00
const result = res.result;
const cateName = res.result.categoryName;
const cateId = result.data.categoryPath.split(",");
const cateArr = [];
cateId.forEach((e, index) => {
// 插入分类id和name
cateArr.push({
id: e,
name: cateName ? cateName[index] : "",
2021-12-20 16:48:08 +08:00
});
2021-05-13 10:56:04 +08:00
});
2021-12-20 16:48:08 +08:00
this.categoryBar = cateArr;
2022-05-27 10:28:37 +08:00
this.$set(this, "goodsMsg", res.result);
2021-12-20 16:48:08 +08:00
// 判断是否收藏
if (this.Cookies.getItem("userInfo")) {
2023-03-09 18:16:10 +08:00
isStoreCollection("STORE", this.goodsMsg.data.storeId).then((res) => {
2021-12-20 16:48:08 +08:00
if (res.success && res.result) {
this.storeCollected = true;
}
});
}
2022-05-27 10:28:37 +08:00
if (!this.storeMsg) {
// 获取店铺信息
getDetailById(this.goodsMsg.data.storeId).then((res) => {
if (res.success) {
this.storeMsg = res.result;
2022-05-27 10:28:37 +08:00
}
});
}
2021-12-20 16:48:08 +08:00
} else {
this.$Message.error(res.message);
this.isLoading = false
2021-05-28 17:25:07 +08:00
}
2021-12-20 16:48:08 +08:00
})
2022-05-27 10:28:37 +08:00
.catch((e) => {
this.isLoading = false
if(e.code === 11001){
this.takeDownSale = true
}
2021-12-20 16:48:08 +08:00
});
2021-05-13 10:56:04 +08:00
},
2022-12-28 11:23:46 +08:00
goGoodsList (currIndex) {
2021-12-20 16:48:08 +08:00
// 跳转商品列表
const arr = [];
2021-05-13 10:56:04 +08:00
this.categoryBar.forEach((e, index) => {
if (index <= currIndex) {
2021-12-20 16:48:08 +08:00
arr.push(e.id);
2021-05-13 10:56:04 +08:00
}
2021-12-20 16:48:08 +08:00
});
return location.origin + "/goodsList?categoryId=" + arr.toString();
2021-05-13 10:56:04 +08:00
},
2022-12-28 11:23:46 +08:00
async collect () {
2021-12-20 16:48:08 +08:00
// 收藏店铺
2021-05-13 10:56:04 +08:00
if (this.storeCollected) {
2023-03-09 18:16:10 +08:00
let cancel = await cancelStoreCollect("STORE", this.goodsMsg.data.storeId);
2021-05-13 10:56:04 +08:00
if (cancel.success) {
2021-12-20 16:48:08 +08:00
this.$Message.success("已取消收藏");
2021-05-13 10:56:04 +08:00
this.storeCollected = false;
}
} else {
2023-03-09 18:16:10 +08:00
let collect = await collectStore("STORE", this.goodsMsg.data.storeId);
2021-05-13 10:56:04 +08:00
if (collect.code === 200) {
this.storeCollected = true;
2021-12-20 16:48:08 +08:00
this.$Message.success("收藏店铺成功,可以前往个人中心我的收藏查看");
2021-05-13 10:56:04 +08:00
}
}
2021-12-20 16:48:08 +08:00
},
2021-05-13 10:56:04 +08:00
},
2022-05-27 10:28:37 +08:00
watch: {},
2021-05-13 10:56:04 +08:00
components: {
Search,
ShopHeader,
ShowGoods,
2021-12-20 16:48:08 +08:00
ShowGoodsDetail,
empty
2021-12-20 16:48:08 +08:00
},
2021-05-13 10:56:04 +08:00
};
</script>
<style scoped lang="scss">
.shop-item-path {
height: 38px;
@include background_color($light_background_color);
line-height: 38px;
color: #2c2c2c;
}
.shop-nav-container {
width: 1200px;
margin: 0 auto;
position: relative;
2021-08-11 22:53:47 +08:00
2021-05-13 10:56:04 +08:00
.store-collect {
position: absolute;
right: 20px;
top: 0;
color: #999;
2021-08-11 22:53:47 +08:00
span {
&:hover {
2021-05-13 10:56:04 +08:00
cursor: pointer;
color: $theme_color;
}
}
}
}
.sale-btn{
margin:10px 0
}
2021-05-13 10:56:04 +08:00
</style>