$(function() { $("#detailList").datagrid({}); $("#handeleDetailList").datagrid({}); var detailOperate = 'add'; var $inventoryAdjustId= $("#inventoryAdjustForm").find("input[name='inventoryAdjustId']"); /** * 跳转到明细页面 */ $("#addDetailBtn").bind("click",function() { if ($inventoryAdjustId.val() == "") { $.messager.alert("提示", "请先填写基本信息", "error"); } else { showWindow({ title:'新增明细', width:900, height:300, closed : false, cache : false, modal : true, onOpen:function() { document.getElementById("addDetailTabs").style.display=""; $('#demoReasonTd').show(); document.getElementById("adjustReason").style.display="none"; $("#inventoryAdjustDetailForm").form('clear'); } }); } }); // 保存明细的方法 $("#submitDetailBtn").click(function() { if ($("#inventoryAdjustDetailForm").form('validate')) { var locationName = $("#inventoryAdjustDetailForm").find("input[name='locationName']").val(); if (null == locationName || "" == locationName){ showMsg('提示', '请点击“获取明细”按钮来获取明细'); } else{ var postData = { formData: $.encodeJSON($("#inventoryAdjustDetailForm").getFormValue()), updateFields : JSON.stringify($.InventoryAdjustDetailEdit.changeList), inventoryAdjustId : $("input[name='inventoryAdjustId']").val(), operate : detailOperate }; ajaxRequest(WEBROOT + '/InventoryAdjust/doSaveDetail.action', postData, function(response) { if (response.code == "success") {// succeed showMsg('提示', '保存成功'); $("#detailList").datagrid({ width : '90%', checkOnSelect:true, nowrap : false, striped : true, collapsible : false, fitColumns : true, idField : 'id', url : WEBROOT + '/InventoryAdjust/showDetailList.action', queryParams : { inventoryAdId: $inventoryAdjustId.val() }, remoteSort : true, rownumbers : true, onDblClickRow : function(index,rowdata){ if($inventoryAdjustId.val() == "") { $.messager.alert("提示", "请先保存基本信息", "error"); } else { //$("#addDetailTabs").tabs('enableTab',1); showWindow({ title:'详细明细', width:900, height:300, onOpen:function() { ajaxRequest(WEBROOT + "/InventoryAdjust/showDetailEdit.action", { id : rowdata.id }, function(data) { $.InventoryAdjustDetailEdit.fillData(data); $('#demoReasonTd').hide(); document.getElementById("adjustReason").style.display=""; $("#inventoryAdjustDetailForm").find("input[name='adjustReason']").val(data.adjustReason); detailOperate = 'edit'; }); } }); } } }); } else { var errorDesc = response.errorDesc; showMsg('保存失败', errorDesc); }; }); // 关闭窗口前,回复明细的操作符为新增 detailOperate = 'add'; closeWindow(); } } }); // 删除明细的方法 $("#removeDetailBtn").click(function() { var rows = $("#detailList").datagrid('getSelections'); var ids = []; for ( var i = 0; i < rows.length; i++) { if (rows[i].id) { ids.push(rows[i].id); } } if (ids.length > 0) { $.messager.confirm('提示', '共选择:' + ids.length + '条记录,确定要删除吗?', function(result) { if (result) { var postData = { ids : $.encodeJSON(ids), adjustStatus : $("input[name='adjustStatus']").val() }; ajaxRequest(WEBROOT + "/InventoryAdjust/doDeleteDetail.action", postData, function(response) { if (response.code == "success") { showMsg('提示', '删除成功'); $("#detailList").datagrid('reload'); } else { var errorDesc = response.errorDesc; showMsg('删除失败', errorDesc); }; }); } }); } else { $.messager.alert("提示", "请选择要删除的行", "error"); } }); /** * 明细列表的展示 */ $("#detailList").datagrid({ width : '90%', checkOnSelect:true, nowrap : false, striped : true, collapsible : false, fitColumns : true, idField : 'id', url : WEBROOT + '/InventoryAdjust/showDetailList.action', queryParams : { inventoryAdId: $inventoryAdjustId.val() }, remoteSort : true, rownumbers : true, onDblClickRow : function(index,rowdata){ if($inventoryAdjustId.val() == "") { $.messager.alert("提示", "请先保存基本信息", "error"); } else { showWindow({ title:'详细明细', width:800, height:200, onOpen:function() { document.getElementById("addDetailTabs").style.display=""; ajaxRequest(WEBROOT + "/InventoryAdjust/showDetailEdit.action", { id : rowdata.id }, function(data) { $('#inventoryAdjustDetailForm').form('load',{ locationName : data.locationName, relationedCustomerName : data.relationedCustomerName, itemCode : data.itemCode, itemName : data.itemName, normalFlag : data.normalFlag, quantity : data.quantity, id : rowdata.id }); $('#adjustQuantity').numberbox('setValue', data.adjustQuantity); $('#demoReasonTd').hide(); document.getElementById("adjustReason").style.display=""; $("#inventoryAdjustDetailForm").find("input[name='adjustReason']").val(data.adjustReason); detailOperate = 'edit'; }); } }); } } }); /** * 弹出处理明细页面 */ $("#addHandeleDetailBtn").bind("click",function() { $('#addHandleDetail').window({ title : '获取明细', width : 800, height : 350, closed : false, cache : false, modal : true }); $("#locationContainerList").datagrid({ width : '100%', checkOnSelect:true, nowrap : false, striped : true, collapsible : false, fitColumns : true, pagination : true, singleSelect : true, pageSize : 5, idField : 'id', url : locationContainerSearchUrl, queryParams : queryParams, remoteSort : true, rownumbers : true, pageList : [ 5, 10, 20, 30, 50, 100 ] }); }); /** * 库存明细数据列表填充以及查询 */ var locationContainerSearchForm = $("#locationContainerSearchForm").searchForm(); // 处理明细的按钮查询事件 $("#locationContainerSearch").bind("click",function() { $("#locationContainerList").datagrid('load', { locationName : $("#locationContainerSearchForm").find("input[name=queryLocationName]").val(), itemName : $("#locationContainerSearchForm").find("input[name=queryItemName]").val(), quantity : $("#locationContainerSearchForm").find("input[name=queryQuantity]").val(), inventoryAdjustId : inventoryAdjustId }); }); // 查询库存明细的URL var locationContainerSearchUrl = WEBROOT + '/InventoryAdjust/doSearchLocationContainer.action'; locationContainerSearchUrl = locationContainerSearchUrl.format('LocationContainer'); // 查询库存明细的参数 var queryParams = { locationName : $("#locationContainerSearchForm").find("input[name=queryLocationName]").val(), itemName : $("#locationContainerSearchForm").find("input[name=queryItemName]").val(), quantity : $("#locationContainerSearchForm").find("input[name=queryQuantity]").val(), inventoryAdjustId : inventoryAdjustId }; /** * 最后弹出窗口输入数量和新储位 */ $("#submitHandeleDetailBtn").bind("click",function() { var rows = $("#locationContainerList").datagrid('getSelections'); var ids = []; for ( var i = 0; i < rows.length; i++) { if (rows[i].id) { ids.push(rows[i].id); } } if (ids.length != 1) { $.messager.alert("提示", "请选择一条具体明细", "error"); }else{ $('#addHandleDetail').window('close'); $('#inventoryAdjustDetailForm').form('load',{ locationContainerId:rows[0].id, quantity:rows[0].usableQuantity, locationId:rows[0].locationId, locationName:rows[0].locationName, itemId:rows[0].itemId, itemName:rows[0].itemName, itemCode:rows[0].itemCode, customerId:rows[0].customerId, customerCode:rows[0].customerCode, customerName:rows[0].customerName, zoneId:rows[0].zoneId, zoneName:rows[0].zoneName, relationedCustomerId:rows[0].relationedCustomerId, relationedCustomerCode:rows[0].relationedCustomerCode, relationedCustomerName:rows[0].relationedCustomerName, warehouseId:rows[0].warehouseId, warehouseName:rows[0].warehouseName, lotNumber:rows[0].lotNumber, normalFlag:rows[0].normalFlag }); } }); /** * 保存或修改处理明细至DB */ $("#submitHandleDetailBtn").bind("click",function(){ }); // 删除处理明细的方法 $("#removeHandleDetailBtn").click(function() { var rows = $("#handeleDetailList").datagrid('getSelections'); var ids = []; for ( var i = 0; i < rows.length; i++) { if (rows[i].id) { ids.push(rows[i].id); } } if (ids.length > 0) { $.messager.confirm('提示', '共选择:' + ids.length + '条记录,确定要删除吗?', function(result) { if (result) { ajaxRequest(WEBROOT + "/InventoryAdjust/doDeleteHandleDetail.action", { ids : $.encodeJSON(ids) }, function(data) { $("#handeleDetailList").datagrid('reload'); showMsg('提示', '删除成功'); }); } }); } else { $.messager.alert("提示", "请选择要删除的行", "error"); } }); // $('#customerId').combogrid({ // panelWidth : 150, // url : WEBROOT + "/loadData.action?entity=customer", // idField : 'customerId', // textField : 'customerName', // showHeader : false, // delay : 500, // mode : 'remote', // columns : [ [ // { field : 'customerId', hidden : true }, // { field : 'customerName', title : '', width : 150 } // ] ], // //请勿使用onSelect避免和baseedit.js里的控件绑定事件冲突 // onSelectAfter : function(rowIndex, record) { // $("#customerName").val(record.customerName); // // }, onBeforeLoad : function(param) { // //此设置使控件不会自动加载数据 这里不能使用this // if (!$('#customerId').combogrid('getText')) { // return false; // } else { // return true; // } // }, onShowPanel : function() { // //在第一次触发下拉框事件是加载数据 // if (!$(this).combogrid('getText')) { // $(this).combogrid({ onBeforeLoad : function(param) { // return true; // } }); // } // } // }); // $('#warehouseId').combogrid({// 仓库 // url : WEBROOT + "/loadData.action?entity=warehouse", // idField : 'warehouseId', // textField : 'warehouseName', // delay : 500, // showHeader : false, // mode : 'remote', // columns : [ [ { // field : 'warehouseName', // title : '仓库名称', // width : 155 // } ] ], // onBeforeLoad : function(param) { // 此设置使控件不会自动加载数据 这里不能使用this // if (!$('#warehouseId').combogrid('getText')) { // return false; // } else { // return true; // } // }, // onShowPanel : function() { // 在第一次触发下拉框事件是加载数据 // if (!$(this).combogrid('getText')) { // $(this).combogrid({ // onBeforeLoad : function(param) { // return true; // } // }); // } // } // }); });