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

new common.dropDown({el:"#brandId",ajax:"brand",params:function(){
        return {status:1}
    }});

new common.dropDown({el:"#shopId",ajax:"sortbybrand",params:function(){
    return {brandId:$("#brandId").val()}
}});

new common.dropDown({el:"#supplierId",ajax:"getjitSup",params:function(){
    return  {brandId:$("#brandId").val()}
}});


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

var loadModal = null;

function batchExport(el, type) {

    return {
        params: {
            type: type,
            brandId:common.util.__input("brandId"),
            shopId:common.util.__input("shopId"),
            supplierId:common.util.__input("supplierId"),
            __type: "batch-import"
        },
        onStart: function(params) {
            params.brandId=common.util.__input("brandId");
            params.shopsId=common.util.__input("shopId");
            params.supplierId=common.util.__input("supplierId");
            
            params.brandName=params.brandId?$("#brandId").find("option[value="+$("#brandId").val()+"]").text():"";
            params.shopsName=params.shopsId?$("#shopId").find("option[value="+$("#shopId").val()+"]").text():"";
            params.supplierName=params.supplierId?$("#supplierId").find("option[value="+$("#supplierId").val()+"]").text():"";

            console.log("params",params);
            loadModal = common.dialog.load();
            $("#message").html('');

            //$(el).parents('td').find('.file-name').text($(el).val().replace("C:\\fakepath\\", ""));
        },
        onComplete: function(response) {
            console.log("批量接口返回数据",response);
            $("#message").html('');
            if (response.code == 200&&response.data.taskId) {
                __ajaxExeclById(response.data.taskId);
                // common.util.__tip(response.message, 'success');
                return;
            }
            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');
        }
    }
}
/*奥莱*/
common.edit.ajaxfileupload('#outletModify', batchExport('#sort-file', 'outletModify'));
/*补货*/
common.edit.ajaxfileupload('#supplyModify', batchExport('#brand-file', 'supplyModify'));
/*基础商品导入*/
$("#baseProduct").prop("disabled",true);
common.edit.ajaxfileupload('#baseProduct', batchExport('#sort-file', 'baseProduct'));
$(document).on("change","#brandId",function(){
    if($(this).val()>0){
        $("#baseProduct").prop("disabled",false);
    }else{
        $("#baseProduct").prop("disabled",true);
    }
});


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

    common.util.__ajax({
        url:'/ajax/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);
}
// __ajaxExeclById("batchBasePrd1459835824928");