product-detail.vue
19.1 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
<template>
<div class="layout">
<LayoutHeader class="layout-header" :show-back="true" :title="'\u200E'"></LayoutHeader>
<div class="layout-context fixscroll">
<div class="cube-scroll-wrapper" ref="pageScroll">
<div class="slide">
<cube-slide ref="slide" :data="imageList">
<cube-slide-item v-for="(item, index) in imageList" :key="index">
<a click="javascript:void 0" class="square-img-container">
<square-img :src="item.image_url" :width="300" :height="300" />
</a>
</cube-slide-item>
<template slot="dots" slot-scope="props">
<div class="dot-wrap">
<span class="cube-dot" :class="{active: props.current === index}" v-for="(item, index) in props.dots">•</span>
</div>
</template>
</cube-slide>
<div class="qiugou" v-if="isQiugouEnabled" @click="qiugou"></div>
</div>
<div class="info-basic">
<div class="info-price">
<template v-if="productDetail.least_price == null">{{'\u200E'}}</template>
<template v-else><i>¥</i>{{productDetail.least_price}}</template>
</div>
<div class="info-name"><div>{{productDetail.product_name}}</div></div>
</div>
<a class="banner" v-if="resource" @click.prevent="gotoNewPage(resource.url)">
<img-size ref="resourceImg" :src="sizeImg(resource.src)"/>
</a>
<div class="info">
<transition-group name="info-list" tag="div" class="info-list">
<div class="info-list-item" transtion="fade" v-if="activity && activity.length !== 0" @click="showActivity" key="促销">
<div class="info-list-name">促销</div>
<div class="info-list-value info-promote">
<span>{{activity[0].promotionTypeStr}}</span>
<i class="cubeic-arrow"></i>
</div>
</div>
<div class="info-list-item" v-for="desc in productDec" :key="desc.text">
<div class="info-list-name">{{desc.text}}</div>
<div class="info-list-value">{{desc.value}}</div>
</div>
</transition-group>
<top-list v-if="topList && topList.length !== 0" :list="topList" @itemClick="gotoProduct" @allClick="gotoBrand" />
<img class="ref-img" v-lazy="prdDetailTip"/>
</div>
<img class="ref-img" v-lazy="prdDetailImage" />
<div class="recommend" v-if="recommend"><h2>相关推荐</h2>
<product-list ref="recommendList" :list="recommend" priceKey="price" :yas-params="recommendYasParams"/>
</div>
</div>
<div class="footer">
<div class="fav">
<div class="icon-fav" @click="_toggleFav">
<i class="iconfont" :class="[isFav ? 'icon-star-fill': 'icon-star-outline']" />
</div>
收藏
</div>
<cube-button class="sell" @click="sell">出售</cube-button>
<cube-button class="buy active" @click="buy">购买</cube-button>
</div>
<buy-sheet v-if="showBidSheet" @hide="onBidSheetHide" :productId="productId"/>
<size-request-sheet v-if="showSizeRequestSheet" @hide="onSizeRequestHide" :productId="productId"/>
</div>
<activity-list-sheet v-if="showActivitySheet" :list="activity" @hide="onActivitySheetHide"/>
<size-select-sheet v-if="showSizeSelectSheet"
:list="sizeList"
:product="productDetail"
:image-list="imageList"
:config="selectSizeConfig"
@hide="onSizeSelectSheetHide"
@select="onSelectTradeProduct"
@add="onRequestSize"/>
</div>
</template>
<script>
import { Button, Slide, Popup } from 'cube-ui';
import { get } from 'lodash';
import { createNamespacedHelpers, mapGetters } from 'vuex';
import ImgSize from '../../components/img-size';
import { getImgUrl } from '../../common/utils';
import ProductList from '../list/components/productList';
import ActivityListSheet from './components/activity-list-sheet';
import prdDetailTip from '../../statics/image/product/prdDetailTip.png';
import prdDetailImage from '../../statics/image/product/prdDetailImage.png';
import SizeSelectSheet from './components/size-select-sheet';
import SizeRequestSheet from './components/size-request-sheet';
import BuySheet from './components/buy-sheet';
import TopList from './components/top-list';
import SquareImg from './components/square-img';
import stateShortCutsMixins from './mixins';
const { mapActions, mapState } = createNamespacedHelpers('product');
export default {
name: 'ProductDetail',
mixins: [stateShortCutsMixins],
components: {
SizeSelectSheet,
ActivityListSheet,
SizeRequestSheet,
BuySheet,
ImgSize,
ProductList,
TopList,
SquareImg,
'cube-button': Button,
'cube-slide': Slide,
'cube-slide-item': Slide.Item,
'cube-popup': Popup,
},
props: {
productId: {
required: true,
},
},
data() {
return {
prdDetailTip,
prdDetailImage,
showActivitySheet: false,
showBidSheet: false,
showSizeSelectSheet: false,
showSizeRequestSheet: false,
selectSizeConfig: {},
/**
* 商品详情页-推荐商品曝光时
* XY_UFO_SHOW_EVENT
* 1.P_NAME:页面名称,UFOProductDetail_LIST;
* 2.P_PARAM:页面参数;
* 3.I_INDEX:曝光顺序;
* 4.PRD_SKN:商品id;
*/
recommendYasParams: {
P_NAME: 'UFOProductDetail_LIST',
},
};
},
computed: {
...mapGetters(['isQiugouEnabled']),
...mapState(['resourceContentCode']),
productDec() {
const goods = get(this.productDetail, 'goods_list[0]', {});
return [
{
text: '颜色',
value: goods.goods_name || '',
}, {
text: '品牌',
value: this.productDetail.brand_name
}, {
text: '系列',
value: this.productDetail.series_name
}, {
text: '发售时间',
value: this.productDetail.sale_time
}, {
text: '发售价格',
value: this.productDetail.offer_price
}, {
text: '货号',
value: this.productDetail.product_code
}
];
},
sizeList() {
return get(this.productDetail, 'goods_list[0].size_list', null);
},
title() {
return get(this.productDetail, 'product_name', '商品详情');
},
},
mounted() {
// if (this.isQiugouEnabled === null) {
this.$store.dispatch('getSysConfigQiugou');
// }
// 在action-sheet显示控制与对应关闭方法
this.actionSheetCloseMap = {
showActivitySheet: 'onActivitySheetHide',
showBidSheet: 'onBidSheetHide',
showSizeSelectSheet: 'onSizeSelectSheetHide',
showSizeRequestSheet: 'onSizeRequestHide',
};
},
asyncData({store, router}) {
const productId = parseInt(router.params.productId, 10);
if (isNaN(productId)) {
throw new Error('无效的商品ID');
}
return store.dispatch('product/fetchProductInfo', {productId});
},
activated() {
if (this.$refs.pageScroll) {
this.$refs.pageScroll.scrollTop = 0;
}
this.loadData(this.productId);
this.refresh();
if (this._resourceImgWatcher) {
this._resourceImgWatcher();
}
if (this.resource && this.resource.url) {
this.yasResourceVisible();
} else {
this._resourceImgWatcher = this.$watch(() => {
return this.resource && this.resource.url;
}, (url) => {
if (url) {
this._resourceImgWatcher && this._resourceImgWatcher();
this.yasResourceVisible();
}
}, {
immediate: true,
});
}
},
deactivated() {
if (this._resourceImgWatcher) {
this._resourceImgWatcher();
this._resourceImgWatcher = null;
}
},
beforeRouteUpdate(to, from ,next) {
if (this.historyBackGuard() === false) {
return next(false);
}
next();
},
beforeRouteLeave(to, from, next) {
if (this.historyBackGuard() === false) {
return next(false);
}
next();
},
methods: {
...mapActions(['fetchProductInfo', 'fetchBrandTop', 'fetchFav', 'toggleFav', 'updateTradeInfo', 'getSelectedTradeProduct', 'payment', 'resetSelectedSize']),
historyBackGuard() {
for (let key of Object.keys(this.actionSheetCloseMap)) {
if (this[key]) {
this[this.actionSheetCloseMap[key]]();
return false;
}
}
return true;
},
refresh() {
this.$refs.slide && this.$refs.slide.refresh && this.$refs.slide.refresh();
},
yasResourceVisible() {
/**
* 商品详情页中的资源位曝光
* XY_UFO_SHOW_EVENT
* 1.P_NAME:当前页面名称,XY_UFOProductDetail;
* 2.P_PARAM:当前页面资源位code;
* 3.PRD_ID:商品ID;
* 4.ACTION_URL:资源位跳转URL;
*/
this.$store.dispatch('reportYas', {
params: {
appop: 'XY_UFO_SHOW_EVENT',
param: {
P_NAME: 'XY_UFOProductDetail',
P_PARAM: this.resourceContentCode,
PRD_ID: this.productId,
ACTION_URL: this.resource.url,
},
}
});
if (this._resourceImgWatcher) {
this._resourceImgWatcher();
this._resourceImgWatcher = null;
}
},
sizeImg(src, width = 360, height = 72) {
if (src) {
return getImgUrl(src, width, height);
}
},
// 加载商品详情数据
loadData(productId = this.productId) {
this.fetchBrandTop({productId});
this.fetchFav({productId});
},
/**
* 登录|认证
* needCert: 需要实名认证
*/
async auth(needCert = false) {
if (needCert) {
const authInfo = await this.$yoho.authRealName();
if (authInfo && authInfo.code === 403) { // 此时已经异步登录,当前页面取消业务处理
return;
}
return authInfo;
}
return this.$yoho.auth();
},
// toggle收藏
async _toggleFav() {
const userInfo = await this.auth();
if (!userInfo) {
return;
}
const isFav = !this.isFav;
this.toggleFav({productId: this.productId, isFav}).then(() => {
const txt = isFav ? '收藏成功' : '取消收藏成功';
this.$createToast({
txt,
type: 'txt',
}).show();
});
},
// 进入商品详情
gotoProduct(product) {
this.$router.push({
name: this.$route.name,
params: {
productId: product.id,
},
});
},
// 打开产品品牌或系列TOP
gotoBrand() {
this.$router.push({
name: 'BrandProductList',
params: {
productId: this.productId,
},
});
},
// 显示活动列表
showActivity() {
this.showActivitySheet = true;
},
// 关闭活动列表
onActivitySheetHide() {
this.showActivitySheet = false;
},
// 选择尺寸
onSizeSelectSheetHide() {
this.showSizeSelectSheet = false;
},
// 购买
buy() {
this.resetSelectedSize();
this.selectSizeConfig = {
dest: 'OrderBuyConfirm',
type: 'buy',
title: '购买',
};
this.showSizeSelectSheet = true;
},
// 出售
async sell() {
// 出售需要实名认证
const userInfo = await this.auth(true);
if (!userInfo) {
return;
}
this.resetSelectedSize();
this.selectSizeConfig = {
dest: 'OrderSellConfirm',
type: 'sell',
title: '出售',
};
this.showSizeSelectSheet = true;
},
// 选择出售或购买
async onSelectTradeProduct(tradeProduct) {
/**
* 数据埋点
* 商品详情页点击出售/购买/求购按钮
* event: XY_UFO_PRD_DT_SALE_C
* params: 1.TAB_ID:1-出售,2-购买,3-求购;
* 2.PRD_ID:商品ID;
*/
this.$store.dispatch('reportYas', {
params: {
appop: 'XY_UFO_PRD_DT_BUY_SEL_C',
param: {
TAB_ID: this.selectSizeConfig.type === 'buy' ? 2 : 1,
PRD_ID: tradeProduct.productId
},
}
});
if (this.selectSizeConfig.type === 'buy') {
try {
const info = await this.payment({
skup: tradeProduct.skup,
});
/**
* {
* "message": "您有未支付的订单,支付或取消后可提交新的订单",
* "code": 512
* }
*/
if (info.code === 512) {
return this.$createDialog({
type: 'confirm',
content: info.message,
confirmBtn: {
text: '查看订单',
active: true,
disabled: false,
href: 'javascript:;'
},
cancelBtn: {
text: '取消',
active: false,
disabled: false,
href: 'javascript:;'
},
onConfirm: () => {
this.showSizeSelectSheet = false;
this.$router.push({
name: 'OrderList',
params: {
owner: this.selectSizeConfig.type,
},
});
},
}).show();
}
} catch (e) {
// e
}
}
this.showSizeSelectSheet = false;
this.$router.push({
name: this.selectSizeConfig.dest,
query: tradeProduct
});
},
// 添加尺寸
onRequestSize() {
this.showSizeSelectSheet = false;
this.showSizeRequestSheet = true;
},
// 添加尺寸关闭
onSizeRequestHide() {
this.showSizeRequestSheet = false;
},
// 打开求购列表
qiugou() {
this.showBidSheet = true;
this.$store.dispatch('reportYas', {
params: {
appop: 'XY_UFO_PRD_DT_SALE_C',
param: {
TAB_ID: 3,
PRD_ID: this.productId,
},
}
});
},
// 购买
onBidSheetHide() {
this.showBidSheet = false;
},
// 资源位
gotoNewPage(url) {
/**
* 商品详情页中的资源位点击
* XY_UFO_GDS_DT_BANNER_C
* 1.PRD_ID:商品ID
* 2.ACTION_URL:跳转的URL
*/
this.$store.dispatch('reportYas', {
params: {
appop: 'XY_UFO_GDS_DT_BANNER_C',
param: {
PRD_ID: this.productId,
ACTION_URL: url,
},
}
});
this.$xianyu.goXianyuNewPage({url});
},
},
};
</script>
<style lang="scss" scoped>
@import "./product-detail";
.cube-btn {
border-radius: 0;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
.fade-enter-active, .fade-leave-active {
transition: opacity 300ms linear;
}
.icon-fav {
box-shadow: none;
background: none;
}
.slide {
height: 520px;
.square-img-container {
display: block;
width: 520px;
height: 520px;
margin: 0 auto;
}
/deep/ .cube-slide-dots {
margin-bottom: -2px;
}
.dot-wrap {
padding-bottom: 10px;
}
.cube-dot {
display: inline-block;
width: 6px;
height: 6px;
margin: 0 10px;
background: rgba(0, 0, 0, 0.15);
border-radius: 50%;
&.active {
transform-origin: 50% 50%;
transform: scale(1.3333);
background: rgba(0, 0, 0, 1);
}
}
.qiugou {
position: absolute;
top: 0;
right: 58px;
width: 58px;
height: 48px;
background: top left url("~statics/image/product/qiugou@3x.png") no-repeat;
background-size: 100% 100%;
}
}
.cube-slide-item {
img {
margin: 0 auto;
}
}
.banner {
display: block;
img {
width: 100%;
height: 132px;
}
}
.banner-title {
/* font-family: PingFang-SC-Light; */
border: 1px solid #000;
font-size: 30px;
line-height: 100px;
text-align: center;
}
.info-promote {
display: flex;
align-items: center;
justify-content: right;
span {
display: inline-block;
border: 1px solid #feabac;
color: #d0021b;
line-height: 1.8;
margin-right: 15px;
font-size: 0.8em;
padding: 0 1.2em;
}
i {
color: #999;
}
}
.info-basic {
padding: 46px 40px 32px;
.info-price {
color: #d0021b;
font-size: 48px;
@include num;
font-weight: bold;
line-height: 56px;
height: 56px;
text-align: center;
letter-spacing: 0;
i {
font-style: normal;
font-size: 36px;
vertical-align: text-bottom;
}
}
.info-name {
margin-top: 14px;
color: #999;
text-align: center;
height: 64px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
overflow: Hide;
div {
font-size: 28px;
line-height: 32px;
max-height: 64px;
white-space: normal;
word-break: break-all;
}
}
}
.info {
padding: 0 40px;
&-list {
line-height: 104px; // PM: 60 -> 52
white-space: nowrap;
&-item {
display: flex;
justify-content: space-between;
border-bottom: 1px solid #eee;
font-size: 28px;
box-sizing: border-box;
}
&-name {
/* font-family: PingFang-SC-Regular; */
color: #999;
}
&-value {
/* font-family: SFProText-Medium; */
color: #000;
letter-spacing: 0;
font-weight: bold;
}
}
.ref-img {
margin-top: 40px;
width: 670px;
height: 100px;
}
}
.ref-img {
display: block;
width: 750px;
height: 628px;
}
.recommend {
padding-top: 20px;
background-color: #f2f2f2;
background-image: linear-gradient(180deg, #fefefe 0%, #f2f2f2 320px);
h2 {
font-size: 36px;
font-weight: bold;
line-height: 50px;
padding: 20px 0 0;
margin: 0 40px;
}
}
.layout-context {
display: flex;
flex-direction: column;
}
.cube-scroll-wrapper {
flex: 1 0 0;
overflow: scroll;
-webkit-overflow-scrolling: touch;
}
.footer {
display: flex;
text-align: center;
padding: 16px 30px;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.08);
@include cube-ufo-btn;
.fav {
margin-right: auto;
text-align: center;
width: 3em;
color: #888;
font-size: 22px;
line-height: 32px;
.icon-star-fill,
.icon-star-outline {
font-size: 48px;
}
.icon-star-outline {
color: #b2b2b2;
}
.icon-star-fill {
color: #002b47;
}
}
.sell,
.buy {
flex: 0 0 6em;
}
}
.info-list-item {
transition: all 0.1s;
}
.info-list-enter,
.info-list-leave-to {
opacity: 0;
transform: translateX(-30%);
}
.info-list-leave-active {
position: absolute;
}
</style>