goods.basegoods.Batch.js 7.24 KB
webpackJsonp([32],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

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

	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(),shopId:$("#shopId").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.sellType=common.util.__input("sellType");
	            params.brandName=params.brandId?encodeURIComponent($("#brandId").find("option[value="+$("#brandId").val()+"]").text()):"";
	            params.shopsName=params.shopsId?encodeURIComponent($("#shopId").find("option[value="+$("#shopId").val()+"]").text()):"";
	            params.supplierName=params.supplierId?encodeURIComponent($("#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/>'));
	                common.util.__tip('处理失败!具体报错见页面下方!', 'warning');
	                return false;
	            }
	            common.util.__tip(response.message, 'warning');
	        }
	    }
	}
	/*展示平台*/
	common.edit.ajaxfileupload('#appTypeModify', batchExport('#sort-file', 'appTypeModify'));

	/*奥莱*/
	common.edit.ajaxfileupload('#outletModify', batchExport('#sort-file', 'outletModify'));
	/*补货*/
	common.edit.ajaxfileupload('#supplyModify', batchExport('#brand-file', 'supplyModify'));
	/*修改条码*/
	common.edit.ajaxfileupload('#factoryCodeModify', batchExport('#brand-file', 'skuFactoryCodeModify'));
	/*基础商品导入*/
	$("#baseProduct").prop("disabled",true);
	common.edit.ajaxfileupload('#baseProduct', batchExport('#sort-file', 'baseProduct'));
	/*定金预售*/
	common.edit.ajaxfileupload('#depositAdvanceModify', _advanceImport('depositAdvance'));
	/*普通预售*/
	common.edit.ajaxfileupload('#advanceModify', _advanceImport('advancePrdImport'));
	/*定金预售支付尾款时间*/
	common.edit.ajaxfileupload('#AdvanceTimeModify', _advanceImport('depositAdvanceTime'));

	/*款型编码*/
	common.edit.ajaxfileupload('#skcFactoryCode', batchExport('#brand-file', 'skcFactoryCode'));

	common.edit.ajaxfileupload('#skuUpmCode', batchExport('#brand-file', 'skuUpmCode'));

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

	common.edit.ajaxfileupload('#nationalCodeModify', batchExport('#nationalCodeProperty', 'nationalCodeImportService'));

	common.edit.ajaxfileupload('#sknCouponRelate', batchExport('#sknCouponProperty', 'sknCouponRelateImportService'));

	var isbrandId=false,isshops=false,issellType=false;

	function jiekai(){
	    if(isbrandId&&isshops&&issellType){
	        $("#baseProduct").prop("disabled",false);
	    }else{
	        $("#baseProduct").prop("disabled",true);
	    }
	}
	$(document).on("change","#brandId",function(){
	    if($(this).val()>0){
	        isbrandId=true;
	    }else{
	        isbrandId=false;
	    }
	    jiekai();
	    $("#shopId").val(-1).trigger("change");
	    $("#supplierId").val(-1).trigger("change");
	});
	$(document).on("change","#shopId",function(){
	    if($(this).val()>0){
	        isshops=true;
	    }else{
	        isshops=false;
	    }
	    jiekai();
	    $("#supplierId").val(-1).trigger("change");
	})
	$(document).on("change","#supplierId",function(){         // 不维护供应商,则不带出经销选项
	    if($(this).val() > 0){
	        $("#sellType option[value=1], #sellType option[value=2], #sellType option[value=3], #sellType option[value=4], #sellType option[value=5]").remove();
	        common.util.__ajax({
	            url:'/product/getSellTypeFromBeiJin',
	            async:false,
	            data:{
	                supplierId: $(this).val(),
	                brandId:$("#brandId").val()
	            }
	        },function(res){
	            console.log(res);
	            if(res.code == 200){
	                //从北京获取经营类型
	                for(var i=0;i<res.data.length;i++){
	                    $("#sellType").append("<option value='"+ res.data[i].sellType +"'>"+ res.data[i].sellTypeName +"</option>");
	                }
	            }
	        },true);
	    }else{
	        $("#sellType option[value=1], #sellType option[value=2], #sellType option[value=3]").remove();
	        $("#sellType").append("<option value='1'>经销</option>");
	    }
	    $("#sellType").val(-1).trigger("change");
	})
	$(document).on("change","#sellType",function(){         // 不维护供应商,则不带出经销选项
	    if($(this).val() > 0){
	       issellType = true;
	    }else{
	        issellType = false;
	    }
	    jiekai();
	})


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

	function _advanceImport(type){
	    return {
	        params: {
	            type: type,
	            __type: "batch-import"
	        },
	        onStart: function(params) {
	            $("#message").html('');
	        },
	        onComplete: function(response) {
	            if (response.status && response.code == 200) {
	                common.util.__tip(response.message, 'success');
	            }
	            else {
	                common.util.__tip(response.message, 'warning');
	            }
	        }
	    }
	}

/***/ }
]);