warehouse.js 4.37 KB
/**
 * 网点管理
 */

var Warehouse = function(){
	
	return {
		
		search : function(){
			$('#data-grid').datagrid({
				url : '/user/warehouse/search',
				queryParams : App.dataGridQueryParams('search-form')
			});
		},
		
		formatInventory : function(value, row, index){
			return '<a href="javascript:Warehouse.queryInventory(\'' + row.code + '\')">查看</a>';
		},
		
		queryInventory : function(code){
			$("#inventory-detail-dialog").dialog('open');
			$("#inventory-detail-data-grid").datagrid({
				url : '/user/warehouse/inventory',
				queryParams : {
					warehouseCode : code
				}	
			});
			
		},
		
		formatStatus : function(value, row, index){
			switch (value) {
			case '0':
				return '禁用';
			case '1':
				return '可用';
			}
		},
		
		/**加载新增网点信息窗口*/
		addDailog : function(){
			$("#add-form").form('clear');
			$("#code").textbox("readonly", false);
			$.getJSON("/user/warehouse/otcCodeList", function(data){
				var text = new Array();
				text.push("<table>");
				for (var i = 0; i < data.length; i++) {
					var otc = data[i];
					if(i%2 == 0){
						text.push("<tr>");
					}
					text.push("<td><input type='checkbox' name='list["+i+"].otcCode' value='"+otc.OTC_CODE+"'>"+otc.OTC_CODE+" ("+otc.OTC_NAME+")</td>");
					if(i%2 == 1){
						text.push("</tr>");
					}
				}
				text.push("</table>");
				$("#otcBox").html(text.join(''));
				$("#status").val("1");
				$("#address").textbox("setValue", "请填写详细地址");
				$('#add-warehouse-dialog').dialog('open');
			});
		},
		
		/**网点信息提交*/
		formSubmit : function(){
			$('#add-form').form('submit', {
				onSubmit : function(param) {
					return $(this).form('validate');
				},
				success : function(data) {
					var result = $.parseJSON(data);
					if(result.success == true){
						$('#add-warehouse-dialog').dialog('close');
						$('#data-grid').datagrid("reload");
					}
					$.messager.alert('操作结果', result.data);
				},
				error : function() {

				}
			});
		},
		
		address : function(){
			if($("#address").textbox('getText') == '请填写详细地址'){
				$("#address").textbox('setText', '');
				$("#address").textbox('setValue', '');
			}
		},
		
		/**作废网点*/
		cancleWarehouse : function(){
			var row = $('#data-grid').datagrid('getSelected');
			if(row){
				$.messager.confirm('Confirm', '你确定要作废该网点么?', function(ok) {
					if (ok) {
						$.post('/user/warehouse/cancel', {code : row.code}, function(data){
							if(data.success == true){
								$('#data-grid').datagrid("reload");
							}
							$.messager.alert('提示', data.data);
						}, 'json');
					}
				});
			}else{
				$.messager.alert('Warning', '请选择要作废的数据');
			}
		},
		
		/**加载修改网点信息窗口*/
		updateDialog : function(){
			var row = $('#data-grid').datagrid('getSelected');
			if(row){
				$.getJSON("/user/warehouse/info", {code : row.code}, function(data){
					var text = new Array();
					text.push("<table>");
					for (var i = 0; i < data.list.length; i++) {
						var otc = data.list[i];
						if(i%2 == 0){
							text.push("<tr>");
						}
						text.push("<td><input type='checkbox' name='list["+i+"].otcCode' id='"+otc.OTC_CODE+"' value='"+otc.OTC_CODE+"'>"+otc.OTC_CODE+" ("+otc.OTC_NAME+")</td>");
						if(i%2 == 1){
							text.push("</tr>");
						}
					}
					text.push("</table>");
					$("#otcBox").html(text.join(''));
					$("#code").textbox("readonly", true);
					$("#add-form").form('load', data.info);
					$("#combobox-province").combobox("setValue", data.info.provinceId);
					$("#combobox-province").combobox("setText", data.info.province);
					$("#combobox-city").combobox("setValue", data.info.cityId);
					$("#combobox-city").combobox("setText", data.info.city);
					$("#combobox-area").combobox("setValue", data.info.areaId);
					$("#combobox-area").combobox("setText", data.info.area);
					$("#businessStartTime").timespinner("setValue", data.info.businessStartTime);
					$("#businessEndTime").timespinner("setValue", data.info.businessEndTime);
					$("#status").val("2");
					for (var i = 0; i < data.info.list.length; i++) {
						var inventory = data.info.list[i];
						$("#"+ inventory.otcCode).attr("checked", true);
					}
					$("#add-warehouse-dialog").dialog('open');
				});
			}else{
				$.messager.alert('Warning', '请选择要修改的数据');
			}
		}
		
	}
	
}();

$(function(){
	Address.initAddress();
});