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

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();

var Confirm = dialog.Confirm,
    Alert = dialog.Alert;

$('.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();
            } else {
                new Alert(data.message || '取消申请失败').show();
            }
        }
    });
}

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) {
            if (data.code === 200) {
                location.reload();
            } else {
                new Alert(data.message || '保存失败').show();
            }
        }
    });
}

$('.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');

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

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