detail.js
2.28 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
73
74
75
76
77
78
79
80
81
const app = $('#app');
const tip = require('common/tip');
require('vue-swipe/dist/vue-swipe.css');
module.exports = {
data() {
return {
intro: {},
entity: {
brand: {
brandName: '',
brandIco: ''
},
productPriceBo: {
formatMarketPrice: ''
}
},
showFeatureSelector: false,
cartCount: 0,
/**
* 加入购物车回调
*
* @param result
*/
onAddToCart: (result)=> {
// TODO: 库存不足
// TODO: 商品已下架
if (result.code === 200) {
this.cartCount = result.data.goods_count;
this.showFeatureSelector = false;
} else {
this.showFeatureSelector = false;
tip('系统异常,请稍后重试');
}
}
};
},
computed: {
isSoldOut: function() {
return this.entity.storage === 0;
}
},
components: {
imageCarousel: require('../image-carousel.vue'),
featureSelector: require('component/product/feature-selector.vue'),
showBox: require('../show-box.vue')
},
methods: {
showAddToCart: function() {
this.showFeatureSelector = true;
}
},
created() {
const self = this;
// 显示商品特征选择组件
this.$on('featureselector.close', function() {
self.showFeatureSelector = false;
});
// 读取基础数据
$.get(`/product/product_${app.data('pid')}_${app.data('goodsId')}.json`).then(result=> {
this.entity = result;
return result;
}).then((result)=> {
// 读取商品详情
return $.get('/product/product/intro.json', {skn: result.productPriceBo.productSkn});
}).then(result => {
this.intro = result;
});
// 读取购物车数量
$.get('/product/cart-count.json', {}).then(result=> {
if (result.code === 200) {
this.cartCount = result.data.cart_goods_count;
}
});
}
};