detail.vue
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<template>
<layout-body :auto-hide-header="true" class="page-detail">
<header-box slot="header" :auto-hide="true"></header-box>
<product-swipe :goods="detail.goods_list" ref="imageSwiper"></product-swipe>
<div class="detail-box border-bottom">
<shop-fav :entity="detail" class="border-bottom"></shop-fav>
<price-title :entity="detail" class="border-bottom"></price-title>
<services :support-refund-exchange="detail.supportRefundExchange"></services>
<product-add-cart v-if="yoho.env.isApp" class="add-cart" :value="detail" @add-cart="addCart"></product-add-cart>
<product-intro :pid="detail.product_id" :skn="detail.product_skn"></product-intro>
</div>
<product-prefer :skn="detail.product_skn" :shop-id="detail.shop_id" title="You Might Also Like"></product-prefer>
<shopping-bag></shopping-bag>
</layout-body>
</template>
<script>
import {FETCH_PRODUCT_DETAIL, FETCH_CART_COUNT, PRODUCT_ADD_CART} from 'store/product/types';
import * as components from './components';
import {mapState} from 'vuex';
export default {
name: 'ProductDetail',
computed: {
...mapState(['yoho']),
...mapState(['product']),
detail() {
let productId = this.$route.params.pid;
return this.product.items[productId];
}
},
title() {
return '商品详情页';
},
mounted() {
this.$store.dispatch(FETCH_CART_COUNT);
},
asyncData({store, router}) {
let product_id = router.params.pid;
return store.dispatch(FETCH_PRODUCT_DETAIL, {product_id});
},
methods: {
addCart(sku) {
this.$store.dispatch(PRODUCT_ADD_CART, {productSku: sku.sku, buyNumber: 1}).then(() => {
this.$message.success('添加成功');
});
}
},
components: {...components}
};
</script>
<style lang="scss">
.page-detail {
background: #f6f6f6;
.detail-box {
padding-left: 30px;
padding-right: 30px;
background-color: #fff;
}
.border-top {
border-top: 1px solid #eee;
}
.border-bottom {
border-bottom: 1px solid #eee;
}
}
</style>