position.js 3.98 KB
/**
 * 持仓列表
 */
var Position = function($) {

	return {
		init : function() {
			var pickType = $(':radio[name="pickType"]:checked').val();
			Position.initPickNum(pickType)
			$('input[type=radio][name=pickType]').change(function() {
				Position.initPickNum(this.value)
		        
		    });
			/** 普通提货 */
			$('#btnNormalPick').click(function() {
				var pickType = $(':radio[name="pickType"]:checked').val();
				if (pickType == null) {
					$.alert('请选择提货方式');
					return;
				}
				Position.pick();
			});
			
			/** 封装提货 */
			$('#btnPackPick').click(function() {
				var packageId = $('#hidPackageId').val();
				var pickType = $(':radio[name="pickType"]:checked').val();
				
				if (pickType == null) {
					$.alert('请选择提货方式');
					return;
				}
				if (packageId == '') {
					$.alert('请选择包装方式');
					return;
				}
				Position.pick();
			});
			
			/** 网点提货 */
			$('#btnWarehousePick').click(function() {
				Position.pick(3);
			});

			//选择封装方式
			$("#positionGiftMethod").find("li").each(function() {
				var li = this;
				$(li).click(function() {
					$(li).addClass("selected").siblings().removeClass("selected");
					$('#hidPackageId').val($(li).val());
				});
			});

			$('.pickPacks').change(function() {
				$(this).parent().next().find('span').text($(this).find('option:selected').val());
			});
		},

		initPickNum:function(pickType){
			var occurAmounts = $('#pickTable').find('input[name="occurAmount"]');
			if(pickType==6){
				for (var i = 0; i < occurAmounts.length; i++) {
					var enableAmount = $(occurAmounts[i]).next('span').text();
					$(occurAmounts[i]).val(parseInt(enableAmount))
					$(occurAmounts[i]).attr("disabled",'disabled')
				}
				$("#aaetip1").css('display','block')
				$("#aaetip2").css('display','block')
				$("#btnNormalPick").val("确认提货")
			}else{
				for (var i = 0; i < occurAmounts.length; i++) {
					//$(occurAmounts[i]).val('')
					//$(occurAmounts[i]).removeAttr("disabled")
				}
				$("#aaetip1").css('display','none')
				$("#aaetip2").css('display','none')
				$("#btnNormalPick").val("下一步")
			}
			
		},
		/** 确认提货 */
		pick : function(pickType) {
			var submitUrl;
			var picks = new Array();
			var occurAmounts = $('#pickTable').find('input[name="occurAmount"]');
			var pickPacks = $('.pickPacks');

			for (var i = 0; i < occurAmounts.length; i++) {
				var occurAmount = $(occurAmounts[i]).val();
				var rows = $('#pickTable').find('tr');
				var tds = $(rows[i + 1]).find('td');
				var pick = {};
				var enableAmount = $(occurAmounts[i]).next('span').text();
				var usefulAmount = $(occurAmounts[i]).next('span').next('span').text();
				var pickPack = $(pickPacks.get(i)).find('option:selected');

				if (occurAmount == '') {
					continue;
				}
				if (isNaN(occurAmount)) {
					$.alert('藏品[' + $(tds[0]).text() + ']提货数量应为数字');
					return;
				}
				if (occurAmount.indexOf('.') > 0) {
					$.alert('藏品[' + $(tds[0]).text() + ']提货数量应为整数');
					return;
				}
				if (parseInt(occurAmount) <= 0) {
					$.alert('藏品[' + $(tds[0]).text() + ']提货数量应大于0');
					return;
				}
				if (parseInt(occurAmount) > parseInt(enableAmount)) {
					$.alert('藏品[' + $(tds[0]).text() + ']提货数量不能大于可提数量');
					return;
				}
				//网点自提
				if (pickType == 3 && parseInt(occurAmount) > parseInt(usefulAmount)) {
					$.alert('藏品[' + $(tds[0]).text() + ']提货数量不能大于库存总量');
					return;
				}
				pick.otcCode = $(tds[0]).text();
				pick.otcName = $(tds[1]).text();
				pick.enableAmount = $(tds[2]).text();
				pick.occurAmount = occurAmount;
				pick.packType = pickPack.text();
				pick.packFee = pickPack.val();
				picks.push(pick);
			}
			if (picks.length == 0) {
				$.alert('请输入提货数量');
				return;
			}
			picks = JSON.stringify(picks);
			$('#hidApplys').val(picks);
			$('#pickForm').submit();
		}
	}
}(jQuery);

$(function() {
	Position.init();
});