exchange-detail.page.js 2.23 KB
var $ = require('yoho-jquery'),
    Confirm = require('../plugins/dialog').Confirm,
    lazyLoad = require('yoho-jquery-lazyload');

var id = $('.exchange-detail-page').data('id');

var $mainWrap = $('.exchange-detail-page'),
    $submitExpress = $mainWrap.find('.submit-express'),
    $showExpress = $mainWrap.find('.show-content'),
    $editExpress = $mainWrap.find('.edit-content');

var $expressCompany = $('.express-company'),
    $expressCode = $('.express-code');

var expressList = $editExpress.data(),
    remark = $('.reason-info').find('span').text().length;

lazyLoad($('.banner-img'));

function cancelExchangeApply() {
    $.ajax({
        type: 'POST',
        url: '/me/return/cancel',
        data: {
            id: id,
            type: 'exchange'
        },
        success: function(data) {
            if (data.code === 200) {
                location.reload();
                $('.exchange-detail').html('<p class="state">您已取消成功</p>');
            }
        }
    });
}

$('.cancel-btn').click(function() {
    new Confirm({
        content: '<h1>取消申请</h1><p>您确定要取消申请么?</p>',
        cb: cancelExchangeApply
    }).show();
});

function setExchangeEepress(eid, num) {
    $.ajax({
        type: 'POST',
        url: '/me/return/setEepress',
        data: {
            id: id,
            type: 'exchange',
            companyId: eid,
            companyName: expressList[eid],
            number: num
        },
        success: function(data) {
            //            console.log(data);
            if (data.code === 200) {
                location.reload();
            }
        }
    });
}

$submitExpress.click(function() {
    var companyId = $expressCompany.val(),
        code = parseInt($expressCode.val(), 10);

    if (!companyId || !code) {
        $submitExpress.siblings('.error-tip').removeClass('hide');
        return;
    }

    setExchangeEepress(companyId, code);
});

$showExpress.on('click', '.reset-express', function() {
    var expressId = $showExpress.data('id');

    $expressCompany.val(expressId);
    $showExpress.addClass('hide');
    $editExpress.removeClass('hide');
});

// console.log($('.reason-info').find('span').text().length);

if (remark <= 5) {
    $('.reason-info').hide();
}