order-detail.vue 12.3 KB
<template>
    <template v-if="show">
        <div class="order-status">
            <p v-if="order.isCancel === 'Y'">交易已取消</p>
            <p v-else>{{order.status | convertOrderState}}</p>
            <p v-if="order.isCancel !== 'Y' && order.status == 0 && order.payLefttime != 0">剩余: <span v-count-down v-bind:left-time="order.payLefttime"></span>,订单将被取消</p>
        </div>
        <div class="order-address">
            <p><span>{{order.userName}}</span><span>{{order.mobile}}</span></p>
            <p>{{order.area}} <br>{{order.address}}</p>
        </div>
        <div class="order-code">
            <p>订单号: {{order.orderCode}}</p>
            <p>下单时间: {{order.createTime | convertTime}}</p>
        </div>
        <div class="order-goods">
            <ul>
                <li class="goods-info" v-for="product in order.orderGoods">
                    <a :href="product | goodsUrl 'collection'">
                        <div class="img-box">
                            <img v-bind:src="product.goodsImage | resize 49 65">
                            <label v-if="product.goodsType === 'gift'">赠品</label>
                            <label class="price-gift" v-if="product.goodsType === 'price_gift'">加价购</label>
                        </div>
                        <div class="goods-detail">
                            <p class="name">{{product.productName}}</p>
                            <p class="size">
                                <span>颜色:{{product.colorName}}</span>
                                <span>尺码:{{product.sizeName}}</span>
                            </p>
                        </div>
                        <div class="goods-price">
                            <p>&yen;{{product.goodsPrice}}</p>
                            <p>×{{product.buyNumber}}</p>
                            <p v-if="product.goodsStatus"><span class="goods-status">{{product.goodsStatus}}</span></p>
                        </div>
                    </a>
                </li>
            </ul>
        </div>
        <div class="order-amount">
            <ul>
                <li v-for="promotion in order.promotionFormulas">
                    <label>{{promotion.promotion}}:</label><span>{{promotion.promotionAmount}}</span>
                </li>
                <li class="sum"><label>总计:</label><span>{{order.amount}}</span></li>
            </ul>
        </div>
        <div class="order-button" v-show="order.status != 1 && order.status != 2 && order.status != 3">
            <button v-if="order.isCancel === 'Y'" @click="deleteOrder(order.orderCode)" class="normal">删除订单</button>
            <template v-else>
                <button v-if="order.status == 0" @click="cancelOrder(order.orderCode)">取消订单</button>
                <button v-if="order.status == 0 " class="countdown" @click="goBuy(order)">去支付 <span v-count-down v-bind:left-time="order.payLefttime" v-bind:callback="autoCancel(order.orderCode)"></span></button>
                <a v-if="order.status == 4 || order.status == 5 || order.status == 6" href="/me/logistic?order_code={{order.orderCode}}">查看物流</a>
                <button v-if="order.status == 4 || order.status == 5 " class="black" @click="confirmGoods(order.orderCode)">确认收货</button>
                <button v-if="order.isSupportRefund == 'Y' || order.isSupportExchange == 'Y'" class="normal" @click="applyRefund()">申请售后</button>
            </template>
        </div>
        <select id="cancel-reason" class="cancel-reason" v-on:blur="reasonChange" v-on:change="reasonChange" v-model="selected">
            <option v-for="option in options" v-bind:value="{id:option.id,reason:option.reason}">{{option.reason}}</option>
        </select>
    </template>
</template>
<script>
    'use strict';

    const $ = require('jquery');
    const tip = require('common/tip');
    const Modal = require('common/modal');
    const yohoAPI = require('yoho');
    const interceptClick = require('common/intercept-click');
    const genderSelect = require('common/select');

    module.exports = {
        data() {
            return {
                show: false,
                order: {},
                options: [],
                selected: {},
                genderSel: {},
                cancelbusy: false
            };
        },
        created() {
            this.updateNavBar();
            this.getOrderData();

            yohoAPI.addNativeMethod('goToService', () => {
                interceptClick.intercept('/me/service');
                return false;
            });

            document.addEventListener('visibilitychange', () => {
                if (!document.hidden) {
                    this.reload();
                }
            });
        },
        methods: {
            updateNavBar() {
                const header = $.extend({}, interceptClick.defaultTitleMap[2]);

                header.title.des = '订单详情';
                setTimeout(() => {
                    yohoAPI.updateNavigationBar({
                        header: header
                    });
                }, 200);
            },
            reload() {
                this.show = false;
                this.order = {};
                this.selected = {};
                this.cancelbusy = false;

                this.getOrderData();
            },
            getOrderData() {
                $.ajax({
                    url: '/me/get-order',
                    data: {
                        orderCode: this.$parent.$data.orderCode
                    }
                }).then(result => {
                    if (result.code === 200) {
                        this.show = true;
                        this.$set('order', result.data);
                        this.genderSel = genderSelect([{
                            key: this.order.isSupportRefund,
                            val: this.order.isSupportRefund === 'Y' ? '申请退货' : '申请退货(已过期限)',
                            url: '/me/return/refund?orderCode=' + this.order.orderCode,
                            disabled: this.order.isSupportRefund !== 'Y'
                        }, {
                            key: this.order.isSupportExchange,
                            val: this.order.isSupportExchange === 'Y' ? '申请换货' : '申请换货(已过期限)',
                            url: '/me/return/exchange?orderCode=' + this.order.orderCode,
                            disabled: this.order.isSupportExchange !== 'Y'
                        }, {
                            key: 'onlineService',
                            val: '在线客服',
                            url: '/me/service'
                        }
                        ]);
                        if (Number(this.order.status) === 0) {
                            this.getCancelReason();
                        }
                    } else if (result.code !== 500) {
                        tip(result.message);
                    } else {
                        tip('数据获取失败');
                    }
                }).fail(() => {
                    tip('网络错误');
                });
            },
            reasonChange() {
                if (this.cancelbusy) {
                    return false;
                }

                this.cancelbusy = true;
                this.orderDetail().cancel({
                    orderCode: this.order.orderCode,
                    reasonId: this.selected.id || this.options[0].id,
                    reason: this.selected.reason || this.options[0].reason
                }, (result) => {
                    if (result.code === 200) {
                        tip('取消成功');
                        yohoAPI.storage.orderReload = true;
                        setTimeout(() => {
                            this.reload();
                        }, 1000);
                    } else if (result.code !== 500) {
                        tip(result.message);
                    }
                    this.cancelbusy = false;
                }, () => {
                    tip('操作失败');
                });
            },
            getCancelReason() {
                $.ajax({
                    url: '/me/getCancelOrderReason',
                }).then(result => {
                    if (result.data.length > 0) {
                        this.options = result.data;
                    }
                }).fail(() => {
                    tip('操作失败');
                });
            },
            orderDetail() {
                return {
                    cancel(param, success, fail) {
                        $.ajax({
                            url: '/me/cancelOrder',
                            type: 'post',
                            data: param
                        }).then(success).fail(fail);
                    }
                };
            },
            autoCancel(code) {
                return () => {
                    this.orderDetail().cancel({
                        orderCode: code,
                        reasonId: this.options.length ? this.options[0].id : null,
                        reason: this.options.length ? this.options[0].reason : null
                    }, (result) => {
                        if (result.code === 200) {
                            yohoAPI.storage.orderReload = true;
                            this.reload();
                        }
                    });
                };
            },
            cancelOrder() {
                let _that = this;

                Modal.confirm('', '取消后不能恢复,确认取消吗?', function() {
                    this.hide();
                    _that.dropDown('cancel-reason');
                });
            },
            deleteOrder(code) {
                Modal.confirm('', '确认删除订单?', function() {
                    this.hide();
                    $.ajax({
                        url: '/me/deleteOrder',
                        type: 'post',
                        data: {
                            orderCode: code
                        }
                    }).then(result => {
                        if (result.code === 200) {
                            yohoAPI.storage.orderReload = true;
                            yohoAPI.goBack();
                            return false;
                        } else if (result.code !== 500) {
                            tip(result.message);
                        }
                    }).fail(() => {
                        tip('操作失败');
                    });
                });
            },
            confirmGoods(code) {
                let _this = this;

                Modal.confirm('', '确认收货吗?', function() {
                    this.hide();
                    $.ajax({
                        url: '/me/confirmReceive',
                        type: 'post',
                        data: {
                            orderCode: code
                        }
                    }).then(result => {
                        if (result.code === 200) {
                            yohoAPI.storage.orderReload = true;
                            _this.reload();
                        } else if (result.code !== 500) {
                            tip(result.message);
                        }
                    }).fail(() => {
                        tip('操作失败');
                    });
                });
            },
            goBuy(order) {
                yohoAPI.goPay({
                    orderid: order.orderCode,
                    amount: order.amount
                });
            },
            applyRefund() {
                this.genderSel.show(item => {
                    if (item.url) {
                        interceptClick.intercept(item.url);
                    }
                    return false;
                });
            },
            dropDown(elementId) {
                let dropdown = document.getElementById(elementId);

                this.showDropdown(dropdown);
                return false;
            },
            showDropdown(element) {
                let event = document.createEvent('MouseEvents');

                event.initMouseEvent('mousedown', true, true, window);
                element.dispatchEvent(event);
            }
        }
    };
</script>
<style>
    @import "../../scss/me/_order-detail.css";
</style>