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

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

    <show-box v-if="entity.brand">
        <div class="brand">
            <img :src="entity.brand.brandIco | resize 110 68" width="55" height="34"/>

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

    <div class="separator"><span>继续拖动,查看商品信息</span>
        <hr/>
    </div>

    <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 :is-last="true">
        <h2>商品详情</h2>
        <i>DETAILS</i>

        <p v-if="entity.brand && entity.brand.brandIntro">
            {{{entity.brand.brandIntro}}}
        </p>

        <p v-if="entity.brand && intro.productIntroBo">
            {{{intro.productIntroBo.productIntro}}}
        </p>

    </show-box>

    <div class="control-box">
        <button class="button control-button" style="flex: 1">
            <a href="javascript:void(0);" @click="yoho.goShopingCart()" style="position: relative;">
                <i class="icon icon-bag"></i>
                <span v-if="cartCount > 0" class="badge badge-tr">{{cartCount}}</span>
            </a>
        </button>
        <button class="button control-button" style="flex: 1" @click="toggleFavorite()">
            <span v-if="entity.isCollect === 'Y' " class="icon icon-love-solid"></span>
            <span v-else class="icon icon-love"></span>
        </button>
        <button class="button button-solid" style="flex: 2"
                @click="showAddToCart()"
                :disabled="isSoldOut">
            <span v-if="isSoldOut">
                已售完
            </span>
            <span v-else="">
                加入购物袋
            </span>
        </button>
    </div>

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

    .show-box .brand {
        max-height: 108px;
        line-height: 48px;
        overflow: hidden;

        img {
            vertical-align: middle;
        }

        h2 {
            font-size: 28px;
            vertical-align: middle;
            margin-left: 30px;
        }

        a {
            float: right;
            margin-top: 12px;
            font-size: 28px;
            color: #b0b0b0;
        }
    }

    .separator {
        text-align: center;
        color: #c4c4c4;
        height: 110px;
        line-height: 110px;
        margin-bottom: -20px;

        span {
            background: #f6f6f6;
            padding: 0 15px;
        }

        hr {
            max-width: 512px;
            margin-top: -55px;
            border: none;
            border-top: 1px solid #eee;
        }

    }

    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-weight: lighter;
            font-style: normal;

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

            &.highlight {
                color: #d0021b;
            }

        }
    }

    .control-box {
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        align-items: stretch;
        position: fixed;
        width: 100%;
        height: 99px;
        bottom: 0;

        .control-button {
            min-width: 100px;
            border: none;
            border-top: 1px solid #ccc;

            .icon {
                font-size: 40px;
            }

        }

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

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

    }

    .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: -10px;
    }
</style>
<script>
    /**
     * 商品详情页
     *
     * @author: Aiden Xu<aiden.xu@yoho.cn>
     * @date: 2016/07/19
     */
    const $ = require('yoho-jquery');
    const app = $('#app');
    const tip = require('common/tip');
    const yoho = require('yoho');

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

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

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

                        // 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'),
            topNav: require('./top-nav.vue'),
        },
        methods: {
            /**
             * 添加到购物车
             */
            showAddToCart: function() {
                this.showFeatureSelector = true;
            },

            /**
             * 添加收藏
             */
            toggleFavorite: function() {
                if (this.entity.isCollect === 'Y') {
                    $.post('/product/favorite.json', {
                        operation: 'remove',
                        id: this.entity.productPriceBo.productId
                    }).then((result)=> {
                        if (result.code === 200) {
                            tip('取消收藏成功');
                            this.entity.isCollect = 'N';
                        } else if (result.code === 403) {
                            // 未登陆
                            yoho.goLogin();
                        }
                    });
                } else {
                    $.post('/product/favorite.json', {
                        operation: 'add',
                        id: this.entity.productPriceBo.productId
                    }).then((result)=> {
                        if (result.code === 200) {
                            tip('收藏成功');
                            this.entity.isCollect = 'Y';
                        }
                    });
                }
            }
        },
        created() {
            const self = this;
            const pid = app.data('pid');
            let loadIntroDeferred;

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

            // 读取基础数据
            $.get(`/product/product_${pid}.json`).then((result) => {
                // TODO: 异常处理
                this.entity = result;
                return result;
            }).then((result)=> {
                loadIntroDeferred = () => {
                    // 读取商品详情
                    $.get(`/product/product/intro_${pid}.json`, {skn: result.productPriceBo.productSkn}).then(intro => {
                        this.intro = intro;
                    });
                };
            });

            $(window).on('scroll', ()=> {
                if ($(window).scrollTop() > 200 && loadIntroDeferred) {
                    loadIntroDeferred();
                    loadIntroDeferred = null;
                }
            });

            // 读取购物车数量
            $.get('/product/cart-count.json').then(result=> {
                if (result.code === 200) {
                    this.cartCount = result.data.cart_goods_count;
                }
            });
        }
    };
</script>