refund-detail.page.js 2.31 KB
/**
 * 退货详情页
 * @author: yyqing<yanqing.yang@yoho.cn>
 * @date: 2016/7/22
 */
var $ = require('yoho-jquery'),
    lazyload = require('yoho-jquery-lazyload'),
    Confirm = require('../plugins/dialog').Confirm;

var $mainWrap = $('.refund-datail-wrap'),
    $submitExpress = $mainWrap.find('.submit-express'),
    $showExpress = $mainWrap.find('.show-content'),
    $editExpress = $mainWrap.find('.edit-content');

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

var id = $mainWrap.data('id'),
    expressList = $editExpress.data();

$('.blk-footer .return-top').remove(); // 移除通用的返回顶部组件

require('yoho-jquery-dotdotdot');

require('../common/header'); // header
require('../common/return-top'); // return-top

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

// dot
$('.goods-item .title').dotdotdot({
    wrap: 'letter'
});

function cancelRefundApply() {
    $.ajax({
        type: 'POST',
        url: '/me/return/cancel',
        data: {
            id: id,
            type: 'refund'
        },
        success: function(data) {
            if (data.code === 200) {
                location.reload();
            }
        }
    });
}

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

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

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

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

    setRefundEepress(companyId, code);
});

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

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

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