var DepotsArea = { InTable: undefined, // 查询 PageClick: function (PageIndex, PageSize) { $.jBox.tip("正在努力加载数据...", "loading"); var search = DepotsArea.GetSearch(); search["PageIndex"] = PageIndex; search["PageSize"] = PageSize; $.gitAjax({ async: false, url: "/DepotsAreaAjax/GetDepotsAreaItems", data: { ajaxdata: JSON.stringify(search) }, type: "post", dataType: "json", success: function (result) { $.jBox.closeTip(); if (result != null) { if (result.Code == 1) { // 查询成功,绑定Table DepotsArea.SetTable(result); } else { // 查询失败,提示操作员 $.jBox.tip(result.Message, "warn"); } } } }); }, // 加载Table表格 SetTable: function (result) { // 定义Table列 var cols = [ { title: '库区编号', name: 'DepotsCode', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return data; } }, { title: '库区名称', name: 'DepotsName', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return data; } }, //{ // title: '所属区域', name: 'RegionName', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { // return data; // } //}, //{ // title: '区域Id', name: 'RegionID', width: 100, hidden: true, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { // return data; // } //}, { title: '库区排数', name: 'DepotsRow', width: 70, hidden: false, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return data; } }, { title: '库区列数', name: 'DepotsColumn', width: 70, hidden: false, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return data; } }, { title: '库区层数', name: 'DepotsLayer', width: 70, hidden: false, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return data; } }, //{ // title: '入库过度库位', name: 'InStorageLocation', hidden: true, width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { // return data; // } //}, //{ // title: '出库过度库位', name: 'OutStorageLocation', hidden: true,width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { // return data; // } //}, { title: '备注', name: 'Demo', width: 150, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return data; } }, { title: '创建日期', name: 'CreatTime', width: 120, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return git.JsonToDateTimeto(data); } }, { title: '创建人', name: 'CreatUser', width: 80, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return data; } }, { title: '修改日期', name: 'UpdateTime', width: 120, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return git.JsonToDateTimeto(data); } }, { title: '修改人', name: 'UpdateUser', width: 80, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { return data; } }, { title: '操作', name: 'Guid', width: 70, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) { var html = ""; html += '编辑  '; return html; } }, ]; // 设置Table if (this.InTable == undefined) { var ht = masterUI.MMGridHeight(); this.InTable = $("#tabList").mmGrid({ cols: cols, sortName: 'CreateTime', sortStatus: 'desc', fullWidthRows: true, multiSelect: true, //indexCol: true, items: result.Result.List, checkCol: true, nowrap: true, height: ht }); //绑定事件 DepotsArea.BindEvent(); } else { this.InTable.load(result.Result.List); } // 绑定分页信息,切换分页调用查询方法 var pageInfo = result.PageInfo; if (pageInfo != undefined) { $("#mypager").pager({ pagenumber: pageInfo.PageIndex, recordCount: pageInfo.RowCount, pageSize: pageInfo.PageSize, buttonClickCallback: DepotsArea.PageClick }); } }, // 绑定行事件 BindEvent: function () { this.InTable.on('loadSuccess', function (e, data) { //loadSuccess LoadBtn.SetBtn(); }); this.InTable.off("cellSelected").on("cellSelected", function (e, item, rowIndex, colIndex) { // 绑定编辑库区事件 if ($(e.target).is("a.edit")) { var Guid = item.Guid; DepotsArea.Dialog(Guid, "Edit"); } }); }, // 获取查询条件 GetSearch: function () { var searchBar = $("div[data-condition='search']"); var DepotsCode = searchBar.find("input[name='DepotsCode']").val(); var DepotsName = searchBar.find("input[name='DepotsName']").val(); var RegionID = searchBar.find("select[name='Region']").val(); var search = {}; search["DepotsCode"] = DepotsCode; search["DepotsName"] = DepotsName; search["RegionID"] = RegionID; return search; }, // 获取Table选中行 GetSelect: function () { var list = []; if (this.InTable != undefined) { var rows = this.InTable.selectedRows(); if (rows != undefined && rows.length > 0) { for (var i = 0; i < rows.length; i++) { list.push(rows[i].Guid); } } } return list; }, // Add Edit 窗体赋值 Dialog: function (Guid, Command) { var submit = function (v, h, f) { if (v) { var DepotsCode = h.find('input[name="DepotsCode"]').val(); var DepotsName = h.find("input[name='DepotsName']").val(); var RegionID = h.find('select[name="RegionId"]').val(); var DepotsRow = h.find('input[name="DepotsRow"]').val(); var DepotsColumn = h.find('input[name="DepotsColumn"]').val(); var DepotsLayer = h.find('input[name="DepotsLayer"]').val(); var Demo = h.find("input[name='Demo']").val(); if (git.IsEmpty(DepotsCode)) { $.jBox.tip("请输入库区编码!", "warn"); return false; } if (git.IsEmpty(DepotsName)) { $.jBox.tip("请输入库区名称!", "warn"); return false; } //if (git.IsEmpty(RegionID)) //{ // $.jBox.tip("请选择所属区域!", "warn"); // return false; //} var regPos = /^[1-9]\d*$/; // 正则 整数 if (git.IsEmpty(DepotsRow)) { $.jBox.tip("请输入库区排数!", "warn"); return false; } if (!regPos.test(DepotsRow)) { $.jBox.tip("库区排数 :请输入数字", "warn"); return false; } if (git.IsEmpty(DepotsColumn)) { $.jBox.tip("请输入库区列数!", "warn"); return false; } if (!regPos.test(DepotsColumn)) { $.jBox.tip("库区列数 :请输入数字", "warn"); return false; } if (git.IsEmpty(DepotsLayer)) { $.jBox.tip("请输入库区层数!", "warn"); return false; } if (!regPos.test(DepotsLayer)) { $.jBox.tip("库区层数 :请输入数字", "warn"); return false; } var param = {}; param["Guid"] = Guid; param["RegionID"] = RegionID; param["DepotsCode"] = DepotsCode; param["DepotsName"] = DepotsName; param["DepotsRow"] = DepotsRow; param["DepotsColumn"] = DepotsColumn; param["DepotsLayer"] = DepotsLayer; param["Demo"] = Demo; // 判断是否重复 var bl = "Fales"; $.gitAjax({ async: false, url: "/DepotsAreaAjax/IsExist", data: { ajaxdata: JSON.stringify(param) }, type: "post", dataType: "json", success: function (result) { if (result.Result == "True") { $.jBox.tip("编号或名称重复,请修改!", "warn"); bl = "True"; } } }); if (bl == "True") { return false; } $.gitAjax({ url: "/DepotsAreaAjax/SetDepotsAreas", data: { ajaxdata: JSON.stringify(param) }, type: "post", dataType: "json", success: function (result) { if (result.Code == 1) { $.jBox.tip(result.Message, "info"); var pageSize = $("#mypager").pager("GetPageSize"); var pageIndex = $("#mypager").pager("GetCurrent"); DepotsArea.PageClick(pageIndex, pageSize); } else { $.jBox.tip(result.Message, "warn"); } } }); } } //窗体加载完成回调事件 var loaded = function (h) { // 设置禁止更改列 h.find('input[name="DepotsCode"]').attr("disabled", "disabled"); h.find('input[name="DepotsRow"]').attr("disabled", "disabled"); h.find('input[name="DepotsColumn"]').attr("disabled", "disabled"); h.find('input[name="DepotsLayer"]').attr("disabled", "disabled"); h.find('select[name="RegionId"]').attr("disabled", "disabled"); } switch (Command) { case "Add": $.jBox.open("get:/BasicInfo/DepotsArea/AddEdit", "新增库区", 370, 340, { buttons: { "确定": true, "关闭": false }, submit: submit }); break; case "Edit": $.jBox.open("get:/BasicInfo/DepotsArea/AddEdit?Guid=" + Guid, "编辑库区", 370, 340, { buttons: { "确定": true, "关闭": false }, submit: submit, loaded: loaded }); break; default: break; } }, // view页操作响应 ToolBar: function () { var btnClick = $("div.toolbar"); btnClick.find("a.btn").click(function () { var command = $(this).attr("data-command"); switch (command) { case "Add": var list = DepotsArea.Dialog("", "Add"); break; case "Del": var submit = function (v, h, f) { if (v == "ok") { var list = DepotsArea.GetSelect(); if (list.length == 0) { $.jBox.tip("请选择要删除的项", "warn"); return false; } var param = {}; param["list"] = JSON.stringify(list); $.gitAjax({ url: "/DepotsAreaAjax/DelDepotsAreas", data: param, type: "post", dataType: "json", success: function (result) { // 提示操作信息 $.jBox.tip(result.Message, "success"); var pageSize = $("#mypager").pager("GetPageSize"); DepotsArea.PageClick(1, pageSize); } }); } } $.jBox.confirm("确定要删除吗?", "提示", submit); default: break; } }) // 搜索按钮绑定查询事件 获取div => div.find事件搜寻按钮 => click事件 var searchBar = $("div[data-condition='search']"); searchBar.find("a[data-command='search']").click(function () { // 调用查询方法,绑定分页信息 DepotsArea.PageClick(1, 15); }); //监听回车事件,用于扫描 searchBar.find("input[name='DepotsCode']").keydown(function (event) { if (event.keyCode == 13) { var value = $(this).val(); if (!git.IsEmpty(value)) { DepotsArea.PageClick(1, 15); setTimeout(function () { searchBar.find("input[name='DepotsCode']").val(""); searchBar.find("input[name='DepotsCode']").focus(); }, 300); } } }); //窗体加载获得焦点 searchBar.find("input[name='DepotsCode']").focus(); //加载默认数据 DepotsArea.PageClick(1, 15); } }