index.vue 16.2 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
<template>
    <top-nav v-if="isApp" :title="entity.productName" :img="firstImage | resize 300 300"></top-nav>
    <show-box :is-first="true">
        <image-carousel :goods="entity.goodsList"></image-carousel>
        <div class="title-box">
            <h1 class="line-clamp-2">{{entity.productName}}</h1>
            <i class="price" v-if="entity.marketPrice > entity.salesPrice"
               :class="{'strike-through': entity.salesPrice > 0}">{{entity.formatMarketPrice}}</i>

            <i v-if="entity.salesPrice > 0"
               :class="{price: true, highlight: entity.marketPrice > entity.salesPrice}">
                {{entity.formatSalesPrice !== '0' ? entity.formatSalesPrice : entity.formatMarketPrice}}
            </i>
        </div>
    </show-box>

    <show-box class="brand" v-if="brand">
        <img :src="brand.brandIco | resize 110 68"/>

        <h2>{{brand.brandName}}</h2>
        <div class="brand-go">
            <span>进入店铺</span>
            <span class="icon icon-right"></span>
        </div>
        <a :href="brand.brandDomain | brandUrl"></a>
    </show-box>

    <show-box v-if="intro.productDescBo">
        <h2>商品信息</h2>
        <i>DESCRIPTION</i>
        <hr>

        <ul class="description">
            <li>
                <span class="desc-caption">编号:</span>
                <span>{{intro.productDescBo.erpProductId}}</span>
            </li>
            <li>
                <span class="desc-caption">颜色:</span>
                <span>{{intro.productDescBo.colorName}}</span>
            </li>
            <li>
                <span class="desc-caption">性别:</span>
                <span>{{intro.productDescBo.gender | clothingGenderIdentity}}</span>
            </li>
            <li v-for="item in intro.productDescBo.standardBos">
                <span class="desc-caption">{{item.standardName}}:</span> <span>{{item.standardVal}}</span>
            </li>
        </ul>
    </show-box>


    <show-box v-if="intro.sizeInfoBo">
        <h2>尺码信息</h2>
        <i>SIZE INFO</i>
        <hr>
        <div class="horizon-wrapper">
            <table class="table">
                <thead>
                <th>吊牌尺码</th>
                <th v-for="header in intro.sizeInfoBo.sizeAttributeBos">{{header.attributeName}}</th>
                </thead>
                <tbody>

                <tr v-for="size in intro.sizeInfoBo.sizeBoList">
                    <td>{{size.sizeName}}</td>
                    <td v-for="item in size.sortAttributes">{{item.sizeValue}}</td>
                </tr>
                </tbody>
            </table>
        </div>

        <i class="info">提示:左滑查看完整表格信息</i>
    </show-box>

    <show-box v-if="intro.sizeImage">
        <h2>测量方式</h2>
        <i>MEASUREMENT METHOD</i>
        <hr>
        <img v-if="intro.sizeImage" :src="intro.sizeImage"/>
    </show-box>

    <show-box v-if="intro.modelBos && intro.modelBos.length > 0">
        <h2>模特试穿</h2>
        <i>REFERENCE</i>
        <hr>
        <div class="horizon-wrapper">
            <table class="table">
                <thead>
                <tr>
                    <th>模特</th>
                    <th>身高</th>
                    <th>体重</th>
                    <th>三围</th>
                    <th>吊牌尺码</th>
                    <th>试穿描述</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="item in intro.modelBos">
                    <td>
                        <img class="model-avatar" :src="item.avatar"/>
                        <span class="model-name">{{item.modelName}}</span>
                    </td>
                    <td>{{item.height}}</td>
                    <td>{{item.weight}}</td>
                    <td>{{item.vitalStatistics}}</td>
                    <td>{{item.fitModelBo.fit_size}}</td>
                    <td>{{item.fitModelBo.feel}}</td>
                </tr>
                </tbody>
            </table>
        </div>
        <i class="info">提示:左滑查看完整表格信息</i>
    </show-box>

    <show-box>
        <div v-if="intro.productMaterialList && intro.productMaterialList.length > 0">
            <h2>商品材质</h2>
            <i>MATERIALS</i>
            <hr>
        </div>

        <div v-if="intro.productMaterialList">
            <ul v-for="item in intro.productMaterialList">
                <div>
                    <div class="image-box">
                        <img :src="item.imageUrl" width="86" height="35"/>
                    </div>
                    <div class="text-box">
                        <div>{{item.caption}}</div>
                        <div>{{item.encaption}}</div>
                    </div>
                    <div class="clear-fix"></div>
                </div>
                <p>
                    {{item.remark}}
                </p>

                <hr/>
            </ul>
        </div>

        <ul class="wash-condition">
            <li class="wash-condition-item" v-for="item in intro.washTipsBoList">
                <img :src="item.img" width="25" height="25"/>
                <div>{{item.caption}}</div>
            </li>
        </ul>
    </show-box>

    <show-box class="product-detail-desc" :is-last="true">
        <h2>商品详情</h2>
        <i>DETAILS</i>

        <p v-if="brand && brand.brandIntro" v-lazy-html="brand.brandIntro">
        </p>

        <p v-if="brand && intro.productIntroBo" v-lazy-html="intro.productIntroBo.productIntro">
        </p>

    </show-box>

    <div class="control-box" v-if="isApp && isReady">
        <button class="button control-button">
            <span @click="yoho.goShopingCart()" style="position: relative;">
                <i class="icon icon-bag"></i>
                <span v-if="isApp && cartCount > 0" class="badge badge-tr">{{cartCount >= 100 ? '99+': cartCount}}</span>
            </span>
        </button>
        <button class="button control-button" @click="toggleFavorite()">
            <span v-if="entity.isCollect === 'Y' " class="icon icon-focused"></span>
            <span v-else class="icon icon-focus"></span>
        </button>
        <button class="button button-solid add-to-cart"
                @click="showAddToCart()"
                :disabled="isSoldOut">
            <span v-if="isSoldOut">
                已售完
            </span>
            <span v-else="">
                加入购物袋
            </span>
        </button>
    </div>

    <div v-if="!isApp">
        <share-bottom></share-bottom>
    </div>

    <feature-selector :is-visible="showFeatureSelector" :entity="entity"
                      :on-add-to-cart="onAddToCart"></feature-selector>
</template>
<style>
    .product-page {
        background: #f6f6f6;
    }

    .show-box.brand {
        overflow: hidden;
        $lh: 68px;

        img {
            height: 68px;
            width: auto;
            max-width: 110px;
            float: left;
        }

        h2 {
            display: inline-block;
            font-size: 28px;
            margin-left: 30px;
            width: 50%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            line-height: $lh;
        }

        .brand-go {
            float: right;
            font-size: 28px;
            line-height: $lh;
            color: #b0b0b0;
        }

        .icon-right {
            margin-left: 30px;
        }

        a {
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
        }
    }

    .product-detail-desc {
        /* 覆盖 img width,height 属性 */
        img {
            width: 100% !important;
            height: auto !important;
        }

        table {
            width: 100%;
        }
    }

    i.info {
        font-style: normal;
        color: #b0b0b0;
        margin-top: 24px;
        display: block;
        font-size: 18px;
    }

    .image-box {
        background: #fff;
    }

    .title-box {
        text-align: center;
        margin-bottom: 50px;
        max-height: 195px;

        h1 {
            text-align: center;
            font-size: 30px;
            line-height: 48px;
            font-weight: normal;
            max-width: 580px;
            margin: 30px auto;
        }

        i.price {
            color: #b0b0b0;
            font-size: 32px;
            font-style: normal;

            &.strike-through {
                text-decoration: line-through;
            }

            &.highlight {
                color: #d0021b;
            }
        }
    }

    .control-box {
        position: fixed;
        width: 750px;
        height: 99px;
        bottom: 0;

        .control-button {
            min-width: 100px;
            border: none;
            border-top: 1px solid #eee;
            width: 187.5px;
            float: left;
            display: block;

            .icon {
                font-size: 40px;
            }
        }

        .control-button:first-child {
            border-right: 1px solid #eee;
        }

        .button-solid {
            font-size: 26px;
        }

        .add-to-cart {
            width: 375px;
            font-size: 28px;
        }
    }

    .horizon-wrapper {
        overflow-x: scroll;
    }

    .table {
        border-collapse: collapse;

        th {
            background: #f6f6f6;
        }

        th,
        td {
            border: 1px solid #eee;
            min-width: 170px;
            line-height: 66px;
            text-align: center;
        }
    }

    .wash-condition {
        display: flex;
        justify-content: space-around;
    }

    .wash-condition-item {
        flex: 1;
        text-align: center;
    }

    .description {
        font-size: 0;

        li {
            font-size: 24px;
            width: 325px;
            line-height: 40px;
            display: inline-block;
        }

        .desc-caption {
            color: #c7c7c7;
            min-width: 100px;
        }
    }

    .model-avatar {
        vertical-align: middle;
        border-radius: 100%;
    }

    .model-name {
        width: 100px;
        display: inline-block;
    }

    .badge-tr {
        margin-top: -28px;
        margin-left: 6px;
        width: 32px;
        height: 32px;
        line-height: 32px;
        font-size: 18px;
        padding: 0;
    }
</style>
<script>
    /**
     * 商品详情页
     *
     * @author: Aiden Xu<aiden.xu@yoho.cn>
     * @date: 2016/07/19
     */
    const $ = require('jquery');
    const app = $('#app');
    const tip = require('common/tip');
    const yoho = require('yoho');
    const share = require('common/share');
    const bus = require('common/vue-bus');

    require('vue-swipe/dist/vue-swipe.css');

    module.exports = {
        data() {
            return {
                yoho: yoho,
                intro: {},
                firstImage: '',
                brand: null,
                entity: {
                    productPriceBo: {
                        formatMarketPrice: ''
                    }
                },
                showFeatureSelector: false,
                cartCount: 0,

                /**
                 * 加入购物车回调
                 *
                 * @param result
                 */
                onAddToCart: (selection, selector)=> {
                    $.post('/product/cart.json', {
                        productSku: selection.size.value,
                        buyNumber: 1
                    }).then((result)=> {
                        if (yoho.goShopingKey && result.data && result.data.shopping_key) {
                            yoho.goShopingKey({shoppingKey: result.data.shopping_key});
                        }

                        // TODO: 库存不足 后台暂未实现
                        // TODO: 商品已下架 后台暂未实现
                        if (result.code === 200) {
                            this.cartCount = result.data.goods_count;

                            selector.playAnimation();
                        } else {
                            result.message = '添加购物车失败 >_<';
                        }

                        this.showFeatureSelector = false;
                        tip(result.message);
                    });
                },

                //state
                isApp: yoho.isApp,
                isSoldOut: false,
                isReady: false
            };
        },
        computed: {
        },
        components: {
            imageCarousel: require('./image-carousel.vue'),
            featureSelector: require('component/product/feature-selector.vue'),
            showBox: require('./show-box.vue'),
            topNav: require('./top-nav.vue'),
            shareBottom: require('component/tool/share-bottom.vue'),
        },
        methods: {
            /**
             * 添加到购物车
             */
            showAddToCart: function() {
                this.showFeatureSelector = true;
            },

            /**
             * 添加收藏
             */
            toggleFavorite: function() {
                $.post('/product/favorite.json', {
                    operation: this.entity.isCollect === 'Y' ? 'remove' : 'add',
                    id: this.entity.productId
                }).then((result)=> {
                    if (result.code === 200) {
                        tip(this.entity.isCollect === 'Y' ? '取消收藏成功' : '收藏成功');
                        this.entity.isCollect = this.entity.isCollect === 'Y' ? 'N' : 'Y';
                        yoho.store.set('productReload', true);
                    } else if (result.code === 403) {
                        // 未登录
                        yoho.goLogin('', () => {
                            this.toggleFavorite();
                        });
                    }
                });
            },

            /*
                刷新购物车
             */
            refreshCart: function() {
                $.get('/product/cart-count.json').then(result=> {
                    if (result.code === 200) {
                        this.cartCount = result.data.cart_goods_count;
                    }
                });
            }
        },
        created() {
            const self = this;
            const pid = app.data('pid');

            // 显示商品特征选择组件
            this.$on('feature.close', function() {
                self.showFeatureSelector = false;
            });

            // 读取基础数据
            $.get(`/product/product_${pid}.json`).then((result) => {
                if (!result.data) {
                    return;
                }
                this.entity = result.data;
                this.brand = result.data.brandInfo;

                if (this.entity.storage === 0 || this.entity.status === 0) {
                    this.isSoldOut = true;
                }

                const goodsList = this.entity.goodsList || [];

                goodsList.forEach((goods)=> {
                    if (!this.firstImage && goods.colorImage) {
                        this.firstImage = goods.colorImage;
                    }
                });

                share({
                    title: this.entity.productName,
                    link: location.href,
                    desc: '我在BLK发现了一个不错的商品,快来看看吧!',
                    imgUrl: this.firstImage.replace(/(\{width}|\{height}|\{mode})/g, function($0) {
                        const dict = {
                            '{width}': 300,
                            '{height}': 300,
                            '{mode}': 2
                        };

                        return dict[$0];
                    })
                });

                return result.data;
            }).then((data)=> {
                if (data) {
                    // 读取商品详情
                    $.get(`/product/product/intro_${pid}.json`, {skn: data.productSkn}).then(intro => {
                        this.intro = intro;
                    });
                }
            })
            .always(() => {
                this.isReady = true;
            });

            // 读取购物车数量
            if (this.isApp) {
                this.refreshCart();
                bus.$on('app.shoppingcart.refresh', this.refreshCart);
            }
        }
    };
</script>