erpMachinAcceptance.js 2.7 KB
Newer Older
doc_wei's avatar
doc_wei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

layui.config({
	base: basePath, 
	version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'jquery', 'winui'], function (exports) {
	winui.renderColor();
	layui.use(['form'], function (form) {
		var index = parent.layer.getFrameIndex(window.name);
	    var $ = layui.$,
		    form = layui.form;
		    
		var selOption = getFileContent('tpl/template/select-option.tpl');
	    
		// 提交类型,1.工序验收;2.生成验收单
		var subType = 1;
		
		subType = parent.subType;
		
		if(subType == 1){
			$("#depotIdBox").remove();
		}else{
			erpOrderUtil.getDepotList(function (json){
				// 加载仓库数据
				$("#depotId").html(getDataUseHandlebars(selOption, json));
				form.render('select');
			});
		}
		
		var needNum = parent.needNum;
		$("#needNum").val(needNum);
		$("#acceptNum").val(needNum);
		
		$("body").on("input", "#acceptNum", function() {
			calcNum(1);
		});
		$("body").on("change", "#acceptNum", function() {
			calcNum(1);
		});
		
		$("body").on("input", "#belowNum", function() {
			calcNum(2);
		});
		$("body").on("change", "#belowNum", function() {
			calcNum(2);
		});
		
		function calcNum(type){
			var changeNum = 0;
			if(type == 1){
				changeNum = parseInt(isNull($("#acceptNum").val()) ? "0" : $("#acceptNum").val());
				$("#belowNum").val(needNum - changeNum);
			}else{
				changeNum = parseInt(isNull($("#belowNum").val()) ? "0" : $("#belowNum").val());
				$("#acceptNum").val(needNum - changeNum);
			}
		}
		
		matchingLanguage();
	    form.render();
	    form.on('submit(formAddBean)', function (data) {
	        if (winui.verifyForm(data.elem)) {
	        	if(parseInt(isNull($("#acceptNum").val()) ? "0" : $("#acceptNum").val()) < 0){
doc_wei's avatar
doc_wei 已提交
65
	        		winui.window.msg('合格数量不能小于0.', {icon: 2, time: 2000});
doc_wei's avatar
doc_wei 已提交
66 67 68
	        		return false;
	        	}
	        	if(parseInt(isNull($("#belowNum").val()) ? "0" : $("#belowNum").val()) < 0){
doc_wei's avatar
doc_wei 已提交
69
	        		winui.window.msg('不合格数量不能小于0.', {icon: 2, time: 2000});
doc_wei's avatar
doc_wei 已提交
70 71 72 73 74 75 76 77 78
	        		return false;
	        	}
	        	
				var params = {
			    	childId: parent.childId,
			    	acceptNum: $("#acceptNum").val(),
			    	belowNum: $("#belowNum").val(),
			    	depotId: (subType == 1) ? "" : $("#depotId").val()
			    };
doc_wei's avatar
doc_wei 已提交
79
	        	AjaxPostUtil.request({url:flowableBasePath + "erpmachin012", params: params, type: 'json', callback: function(json){
doc_wei's avatar
doc_wei 已提交
80
	 	   			if (json.returnCode == 0) {
doc_wei's avatar
doc_wei 已提交
81 82 83
		 	   			parent.layer.close(index);
		 	        	parent.refreshCode = '0';
	 	   			}else{
doc_wei's avatar
doc_wei 已提交
84
	 	   				winui.window.msg(json.returnMessage, {icon: 2, time: 2000});
doc_wei's avatar
doc_wei 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97
	 	   			}
	 	   		}});
	        }
	        return false;
	    });
	    
	    //取消
	    $("body").on("click", "#cancle", function(){
	    	parent.layer.close(index);
	    });
	});
	    
});