order-detail.page.js 2.02 KB
var cancelOrder = require('./order/cancel-order');
var confirmReceive = require('./order/confirm-receive');
var editOrder = require('./order/edit-order');
var countDown = require('./order/countdown');

var Confirm = require('../plugins/dialog').Confirm;

var lazyLoad = require('yoho-jquery-lazyload');

// 个人中心共用代码加载
require('./me');

lazyLoad($('img.lazy'));

function reload() {
    location.reload();
}

$('.order .cancel-btn').on('click', function() {
    var $this = $(this);
    var code = $this.closest('.order').data('code');

    cancelOrder.start(code, reload);
});

$('.order .edit-btn').on('click', function() {
    var $this = $(this);
    var $userInfo = $('.user-info.info-box');
    var code = $this.closest('.order').data('codem');

    var areaCode = $userInfo.data('area');
    var userName = $userInfo.find('.user-name-sel').data('name');
    var address = $userInfo.find('.user-addr-sel').data('address');
    var mobile = $userInfo.find('.user-mo-sel').data('mobile');
    var phone = $userInfo.find('.user-ph-sel').data('phone');

    editOrder.start({
        data: {
            orderCode: code,
            userName: userName,
            address: address,
            mobile: mobile,
            phone: phone,
            areaCode: areaCode
        }
    }, reload);
});

$('.complete-btn').on('click', function() {
    var code = $(this).closest('.order').data('code');

    new Confirm({
        content: '<h1 class="title">确认收货</h1><p>您确定要确认收货么?</p>',
        cb: function() {
            confirmReceive.done(code);
        }
    }).show();
});

if ($('.left-time').length) {
    countDown.intervalValue = 1000;
    countDown.showSec = true;
    countDown.start();
}

$('body').on('click', function(e) {

    if ($(e.target).hasClass('show-package')) {
        return false;
    }

    if (!$('.package-list').hasClass('hide')) {
        $('.package-list').addClass('hide');
    }
});

$('.show-package').on('click', function() {
    $(this).next('.package-list').toggleClass('hide');
});