var GoodsManager = { GoodsGrid: undefined, Server: function () { var config = (function () { var URL_GetList = "/GoodsPosAjax/GetList"; var URL_Lock = "/GoodsPosAjax/GetGoodsPosLock"; var URL_Add = "/GoodsPosAjax/AddGoods"; var URL_Property = "/GoodsPosAjax/GetGoodsPosProperty"; var URL_Print = "/GoodsPosAjax/PrintBarCode"; // 打印库位 var URL_PrintTray = "/GoodsPosAjax/PrintTrayBarCode"; // 批量打印托盘 return { URL_GetList: URL_GetList, URL_Lock: URL_Lock, URL_Add: URL_Add, URL_Property: URL_Property, URL_Print: URL_Print, URL_PrintTray: URL_PrintTray, }; })(); //数据操作服务 var dataServer = (function ($, config) { //查询分页列表 var GetList = function (data, callback) { $.gitAjax({ url: config.URL_GetList, data: { ajaxdata: JSON.stringify(data) }, type: "post", dataType: "json", success: function (result) { if (callback != undefined && typeof callback == "function") { callback(result); } } }); } var Lock = function (data, callback) { $.gitAjax({ url: config.URL_Lock, data: { ajaxdata: JSON.stringify(data) }, type: "post", dataType: "json", success: function (result) { if (callback != undefined && typeof callback == "function") { callback(result); } } }); } // 打印货位 var PrintBarCode = function (data, callback) { $.gitAjax({ url: config.URL_Print, data: data, type: "post", dataType: "json", success: function (result) { if (callback != undefined && typeof callback == "function") { callback(result); } } }); } // 打印托盘 var PrintTrayBarCode = function (data, callback) { $.gitAjax({ url: config.URL_PrintTray, data: data, type: "post", dataType: "json", success: function (result) { if (callback != undefined && typeof callback == "function") { callback(result); } } }); } var Property = function (data, callback) { $.gitAjax({ url: config.URL_Property, data: { ajaxdata: JSON.stringify(data) }, type: "post", dataType: "json", success: function (result) { if (callback != undefined && typeof callback == "function") { callback(result); } } }); } var Add = function (data, callback) { $.gitAjax({ url: config.URL_Add, data: { ajaxdata: JSON.stringify(data) }, type: "post", dataType: "json", success: function (result) { if (callback != undefined && typeof callback == "function") { callback(result); } } }); } return { GetList: GetList, Lock: Lock, Property: Property, Add: Add, PrintBarCode: PrintBarCode, PrintTrayBarCode: PrintTrayBarCode, } })($, config); return dataServer; }, Dialog: function (Addre, Command) { var submit = function (v, h, f) { if (v) { var Property = h.find('select[name="property"]').val(); if (git.IsEmpty(Property)) { $.jBox.tip("请选择库位属性", "warn"); return false; } var statu = h.find('select[name="statu"]').val(); if (git.IsEmpty(statu)) { $.jBox.tip("请选择库位状态", "warn"); return false; } var Alock = h.find('select[name="Alock"]').val(); if (git.IsEmpty(Alock)) { $.jBox.tip("请选择库位锁定状态", "warn"); return false; } var Demo = h.find('input[name="Demo"]').val(); var param = {}; param["Operation"] = Command; param["Area"] = Addre; param["Property"] = Property; param["statu"] = statu; param["Alock"] = Alock; param["Demo"] = Demo; var Server = GoodsManager.Server(); Server.Add(param, function (result) { if (result.Code == 1) { var pageSize = $("#mypager").pager("GetPageSize"); var pageIndex = $("#mypager").pager("GetCurrent"); if (Command == "Add") { GoodsManager.PageClick(pageIndex, pageSize); } else if (Command == "Edit") { GoodsManager.Refresh(); //$.jBox.tip(result.Message, "warn"); // 库位编辑成功哦那个! 提示 } } else { $.jBox.tip(result.Message, "warn"); } }); // liudl 注释 //Server.Property(param, function (result) { // if (result.Code == 1) { // $.jBox.tip(result.Message, "info"); // var pageSize = $("#mypager").pager("GetPageSize"); // var pageIndex = $("#mypager").pager("GetCurrent"); // GoodsManager.PageClick(pageIndex, pageSize); // } else { // //$.jBox.tip(result.Message, "warn"); // 提示空提示 // } //}); } } //窗体加载完成回调事件 var loaded = function (h) { // 设置禁止更改列 h.find('select[name="Area"]').attr("disabled", "disabled"); h.find('select[name="pai"]').attr("disabled", "disabled"); // 库区编码 总排 列 行 禁止编辑 h.find('select[name="lie"]').attr("disabled", "disabled"); h.find('select[name="ceng"]').attr("disabled", "disabled"); } if (Command == "Property") { $.jBox.open("get:/BasicInfo/GoodsPos/SetProperty", "设定库位属性", 650, 200, { buttons: { "确定": true, "取消": false }, submit: submit }); } if (Command == "Add") { $.jBox.open("get:/BasicInfo/GoodsPos/AddGoods", "新增库位信息", 400, 500, { buttons: { "确定": true, "关闭": false }, submit: submit }); } else if (Command == "Edit") { $.jBox.open("get:/BasicInfo/GoodsPos/AddGoods?Addre=" + Addre, "编辑库位信息", 400, 500, { buttons: { "确定": true, "关闭": false }, submit: submit }); } }, PageClick: function (PageIndex, PageSize) { $.jBox.tip("正在努力加载数据...", "loading"); var Server = GoodsManager.Server(); // 绑定方法 var search = GoodsManager.GetSearch(); // 加载视图过滤条件 search["PageIndex"] = PageIndex; search["PageSize"] = PageSize; console.log(JSON.stringify(search)); Server.GetList(search, function (result) { GoodsManager.SetTable(result); $.jBox.closeTip(); }); }, Refresh: function () { var PageSize = $("#mypager").pager("GetPageSize"); var PageIndex = $("#mypager").pager("GetCurrent"); $.jBox.tip("正在努力加载数据...", "loading"); var Server = GoodsManager.Server(); var search = GoodsManager.GetSearch(); search["PageIndex"] = PageIndex; search["PageSize"] = PageSize; Server.GetList(search, function (result) { GoodsManager.SetTable(result); $.jBox.closeTip(); }); }, SetTable: function (result) { var cols = [ { title: '库区', name: 'Area', width: 90, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) { return data; } }, { title: '货位地址', name: 'Addre', width: 110, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) { return data; } }, { title: '排', name: 'pai', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) { return data; } }, { title: '列', name: 'lie', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) { return data; } }, { title: '层', name: 'ceng', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) { return data; } }, { title: '货位属性', name: 'property', width: 100, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) { return data; } }, { title: '货位状态', name: 'statu', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) { return data; } }, { title: '锁定状态', name: 'ALock', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) { return data; } }, { title: '备注', name: 'Demo', width: 120, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) { return data; } }, { title: '操作', name: 'ID', width: 180, align: 'left', lockWidth: false, renderer: function (data, item, rowIndex) { var html = ""; html += '打印  '; html += '打印托盘码  '; return html; } }, ]; if (this.GoodsGrid == undefined) { var ht = masterUI.MMGridHeight(); this.GoodsGrid = $("#tabList").mmGrid({ cols: cols, // 定义表头 items: result.Result.List, checkCol: true, // 是否显示选择框 nowrap: true, remoteSort: true, multiSelect: false, // 单选 / 多选 默认单选 // indexCol: true, // 增加索引列 height: ht }); //绑定事件 GoodsManager.BindEvent(); } else { this.GoodsGrid.load(result.Result.List); } var pageInfo = result.PageInfo; if (pageInfo != undefined) { $("#mypager").pager({ pagenumber: pageInfo.PageIndex, recordCount: pageInfo.RowCount, pageSize: pageInfo.PageSize, buttonClickCallback: GoodsManager.PageClick }); } }, BindEvent: function () { this.GoodsGrid.on('loadSuccess', function (e, data) { LoadBtn.SetBtn(); }); this.GoodsGrid.off("cellSelected").on("cellSelected", function (e, item, rowIndex, colIndex) { // 编辑绑定生成库位事件 if ($(e.target).is("a.print")) { var Addre = item.Addre; var submit = function (v, h, f) { if (v == "ok") { var list = []; list.push(Addre); var param = {}; param["list"] = JSON.stringify(list); var Server = GoodsManager.Server(); Server.PrintBarCode(param, function (result) { // 此方法内的执行顺序是由下往上。 // 刷新页面 var pageSize = $("#mypager").pager("GetPageSize"); GoodsManager.PageClick(1, pageSize); $.jBox.tip(result.Message, "warn"); // 条形码打印完毕! 提示 }); } } $.jBox.confirm("打印 " + Addre + " 库位条形码?", "提示", submit); } else if ($(e.target).is("a.printTray")) { var Addre = item.Addre; var submit = function (v, h, f) { if (v == "ok") { var list = []; list.push(Addre); var param = {}; param["list"] = JSON.stringify(list); var Server = GoodsManager.Server(); Server.PrintTrayBarCode(param, function (result) { // 此方法内的执行顺序是由下往上。 // 刷新页面 var pageSize = $("#mypager").pager("GetPageSize"); GoodsManager.PageClick(1, pageSize); $.jBox.tip(result.Message, "warn"); // 条形码打印完毕! 提示 }); } } $.jBox.confirm("批量打印 " + Addre + " 库位中所有托盘条形码?", "提示", submit); } }); }, GetSelect: function () { var list = []; if (this.GoodsGrid != undefined) { var rows = this.GoodsGrid.selectedRows(); if (rows != undefined && rows.length > 0) { for (var i = 0; i < rows.length; i++) { list.push(rows[i].Addre); } } } return list; }, GetSearch: function () { // 获取下拉框值 var searchBar = $("div[data-condition='search']"); var pai = searchBar.find("select[name='pai']").val(); var lie = searchBar.find("select[name='lie']").val(); var ceng = searchBar.find("select[name='ceng']").val(); var area = searchBar.find("select[name='Area']").val(); var statu = searchBar.find("select[name='statu']").val(); var property = searchBar.find("select[name='property']").val(); var Alock = searchBar.find("select[name='Alock']").val(); var search = {}; search["pai"] = pai; search["lie"] = lie; search["ceng"] = ceng; search["area"] = area; search["statu"] = statu; search["property"] = property; search["Alock"] = Alock; return search; }, ToolBar: function () { //工具栏按钮点击事件 $("div.toolbar").find("a.btn").click(function () { var command = $(this).attr("data-command"); if (command == "Lock") { var list = GoodsManager.GetSelect(); if (list.length == 0) { $.jBox.tip("请选择要锁定的货位", "warn"); return false; } var param = {}; param["list"] = JSON.stringify(list); param["Operation"] = "Lock"; var Server = GoodsManager.Server(); Server.Lock(param, function (result) { $.jBox.tip(result.Message, "success"); var pageSize = $("#mypager").pager("GetPageSize"); GoodsManager.PageClick(1, pageSize); }); } else if (command == "Unlock") { var list = GoodsManager.GetSelect(); if (list.length == 0) { $.jBox.tip("请选择要解锁的货位", "warn"); return false; } var param = {}; param["list"] = JSON.stringify(list); param["Operation"] = "UnLock"; var Server = GoodsManager.Server(); Server.Lock(param, function (result) { $.jBox.tip(result.Message, "success"); var pageSize = $("#mypager").pager("GetPageSize"); GoodsManager.PageClick(1, pageSize); }); } else if (command == "Property") { var list = GoodsManager.GetSelect(); if (list.length == 0) { $.jBox.tip("请选择要设定属性的库位", "warn"); return false; } //var param = {}; //param["list"] = JSON.stringify(list); GoodsManager.Dialog(list, "Property") } else if (command == "Add") { GoodsManager.Dialog(undefined, command); } // 编辑库位属性 else if (command == "Edit") { var list = GoodsManager.GetSelect(); if (list.length == 0) { $.jBox.tip("请选择要编辑的项", "warn"); return false; } var GoodsPos = list[0]; GoodsManager.Dialog(GoodsPos, command); } }); //搜索 var searchBar = $("div[data-condition='search']"); searchBar.find("a[data-command='search']").click(function () { GoodsManager.PageClick(1, 10); }); // 下拉框选择事件 $("#areaid").change(function () { var areaid = ($(this).val()); // 获取库区编码 if (areaid != "") { $.gitAjax({ url: "/GoodsPosAjax/BindOption", data: { ajaxdata: areaid }, type: "post", dataType: "json", success: function (result) { // result = 后台返回值 if (result != null) { // 清空下拉框选项 重新赋值 $("#paiid").empty(); $("#paiid").html(result.pai); $("#lieid").empty(); $("#lieid").html(result.lie); $("#cengid").empty(); $("#cengid").html(result.ceng); } } }) } }); //监听回车事件,用于扫描 $("input[name='pai']").keydown(function (event) { if (event.keyCode == 13) { var value = $(this).val(); if (!git.IsEmpty(value)) { GoodsManager.PageClick(1, 10); setTimeout(function () { $("input[name='pai']").val(""); $("input[name='pai']").focus(); }, 300); } } }); $("input[name='pai']").focus(); //加载默认数据 GoodsManager.PageClick(1, 10); } };