cod-upload.js 1.66 KB
/**
 * Created by wangqianjun on 16/4/13.
 */
'use strict';
var $ = require('jquery'),
    common = require('../common/common');

$('input[type="file"]').after('<div class="file-name btn btn-default">请选择文件</div>');

function batchExport(el, type) {
    var loadModal = null;

    return {
        params: {
            type: type,
            __type: "batch-import"
        },
        onStart: function() {
            loadModal = common.dialog.load();

            $(el).parents('td').find('.file-name').text($(el).val().replace("C:\\fakepath\\", ""));
        },
        onComplete: function(response) {
            console.log(response);

            if (loadModal) {
                loadModal.close();
            }
            if (response.code == 200) {
                var failFileReason = response.data['failFileReason'];

                // 有数据导入失败
                if(failFileReason.length) {
                    var htmlStr = "";
                    //for(var item in failFileReason) {
                    for(var i = 0; i < failFileReason.length; i++){
                        htmlStr += '<p style="color:red;">"'+failFileReason[i]+'"</p>';
                    }
                    htmlStr += '<h2 style="color:red;">请修改后重新上传</h2>';
                    $('.result').html(htmlStr);

                } else {
                    $('.result').html("");
                    common.util.__tip(response.message, 'success');
                }
            } else {
                common.util.__tip(response.message, 'warning');
            }
        }
    }
}

common.edit.ajaxfileupload('#sort-file', batchExport('#sort-file', 'payDeliveryModify'));