Upload.js 3.46 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'));


function batchExport1(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", response);
            if (loadModal) {
                loadModal.close();
            }
            if (response.code == 200) {
                var failFileReason = response.data['failFileReason'];
                var repeatFileReason = response.data['repeatFileReason'];

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

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

common.edit.ajaxfileupload('#sort-file1', batchExport1('#sort-file1', 'refundExchangeModify'));