Batch.js 2.84 KB
'use strict';
var $ = require('jquery'),
    common = require('../../../common/common');

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

/*这里不能再再丢*/
var loadModal = null;

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

            $("#message").html('');
            if(type == "changeSize"){
                if (loadModal) {
                    loadModal.close();
                }
                common.util.__tip(response.message, 'success');
                return;
            }
            if (response.code == 200&&response.data.taskId) {

                __ajaxCheckTask(response.data.taskId);
                return;
            }
            if(response.data&&response.data.failFileReason&&response.data.failFileReason.length){
                $("#message").html(response.data.failFileReason.join('<br/>'));
                if (loadModal) {
                    loadModal.close();
                }
                common.util.__tip('处理失败!具体报错见页面下方!', 'warning');
                return false;
            }
            if (loadModal) {
                loadModal.close();
            }

            if(response.code==400){
                 $("#message").html(response.message);
                return false;
            }
            common.util.__tip(response.message, 'success');

        }
    }
}

common.edit.ajaxfileupload('#sort-file', batchExport('#sort-file', 'searchSort'));
common.edit.ajaxfileupload('#brand-file', batchExport('#brand-file', 'brandProperty'));
common.edit.ajaxfileupload('#offShelve-file', batchExport('#offShelve-file', 'offShelveSkn'));
common.edit.ajaxfileupload('#onShelve-file', batchExport('#onShelve-file', 'onShelveSkn'));
common.edit.ajaxfileupload('#phrase-file', batchExport('#phrase-file', 'productPhrase'));
common.edit.ajaxfileupload('#change-size', batchExport('#change-size', 'changeSize'));

function __ajaxCheckTask(unquid){
    var params={param:unquid};

    common.util.__ajax({
        url:'/product/queryBatchImportResultOfOnShelveSkn',
        data:params
    },function(res){
        if(res.data.length){
            
            //成功操作
            if (loadModal) {
                loadModal.close();
            }
             common.util.__tip(res.message, 'success');

        }else{
           setTimeout(function(){
             __ajaxExeclById.call(null,unquid);
           },1000);
        }
        $("#message").html(res.message);
    },true);
    
}