Batch.js 2.13 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) {

    return {
        params: {
            type: type,
            linkType:common.util.__input("linkType"),
            __type: "batch-import"
        },
        onStart: function(params) {
            params.linkType=common.util.__input("linkType");
            console.log("params",params);
            loadModal = common.dialog.load();
           $("#message").html('');
        },
        onComplete: function(response) {
            console.log("批量接口返回数据",response);
            $("#message").html('');

            if (response.code == 200&&response.data.successList!=null) {
                common.util.__tip(response.message, 'success');
                var urlType = $("input[name='urlType']:checked").val();
                window.open("/ajax/down?queryConf="+urlType+"_" + (response.data.successList) + "&type=linkBatchExport");
            }
            if (loadModal) {
                loadModal.close();
            }
            if(response.data&&response.data.failFileReason.length){
                $("#message").html(response.data.failFileReason.join('<br/>'));
                return false;
            }
            common.util.__tip(response.message, 'warning');
        }
    }
}
/*批量生成链接导入*/
//$("#bathcLinkSkn").prop("disabled",true);
common.edit.ajaxfileupload('#batchLinkSkn', batchExport('#sort-file', 'batchSknLink'));

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

    common.util.__ajax({
        url:'/product/queryBatchImportResult',
        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);
            },5000);
        }
        $("#message").html(res.message);
    },true);
}