returns-apply.js 2.1 KB
/**
 * 退换货申请
 * @author: yyqing<yanqing.yang@yoho.cn>
 * @date: 2016/2/29
 */
var $ = require('yoho.jquery'),
    Addr = require('./common-address');

var $goosTable = $('#goods-table'),
    $reasons = $goosTable.find('.return-reason'),
    $file = $goosTable.find('input[type=file]');

var $exchange = $('.exchange-detail'),
    defaultArea = $exchange.find('input[name="hide-area"]').val();

require('../../plugin/jquery.upload');

defaultArea = defaultArea ? defaultArea : '';
Addr.loadAllData(defaultArea, {
    areaDomId: 'area'
});

$reasons.change(function() {
    var $par = $(this).parent().parent(),
        type = $(this).val() * 1;

    if (type === 4 || type === 6 || type === 8) {
        $par.next().show();
    } else {
        $par.next().hide();
    }
});

$goosTable.find('.up-image-list li').on('click', '.btn-del', function() {
    $(this).parent().empty();
});

$file.each(function(e) {
    $('#upload-img-' + e).upload({
        auto: true,
        buttonClass: 'upload-img-btn',
        fileType: 'image/*',
        uploadScript: '/home/suggestimgUpload',
        fileObjName: 'fileData',
        fileSizeLimit: 5000,
        buttonText: '上传图片',
        height: 34,
        width: 116,
        multi: false,
        onUploadComplete: function(file, data) {
            var $par = $(this).closest('.problem-description'),
                $imgList = $par.find('li'),
                isShow = false,
                img, _html;

            img = JSON.parse(data).imgList[0];
            _html = '<span class="btn-del" title="删除"></span>' +
                '<img src="' + img.imgUrl + '" width="126" height="126">';
            $imgList.each(function() {
                if (!isShow && !$(this).find('img').length) {
                    isShow = true;
                    $(this).html(_html);
                }
            });
        },
        onError: function(info, fileType, data) {
            var msg = '图片上传失败!';

            if (info === 'FILE_SIZE_LIMIT_EXCEEDED') {
                msg = '图片大小超出限制!';
            }
            alert(msg);
        }
    });
});