var DepotsLocation = {
InTable: undefined,
// 查询
PageClick: function (PageIndex, PageSize) {
$.jBox.tip("正在努力加载数据...", "loading");
var search = DepotsLocation.GetSearch();
search["PageIndex"] = PageIndex;
search["PageSize"] = PageSize;
$.gitAjax({
async: false,
url: "/DLocationAjax/GetDLocationItems",
data: { ajaxdata: JSON.stringify(search) },
type: "post",
dataType: "json",
success: function (result) {
$.jBox.closeTip();
if (result != null) {
if (result.Code == 1) {
// 查询成功,绑定Table
DepotsLocation.SetTable(result);
}
else {
// 查询失败,提示操作员
$.jBox.tip(result.Message, "warn");
}
}
}
});
},
// 加载Table表格
SetTable: function (result) {
// 定义Table列
var cols = [
{
title: '库位编码', name: 'LocationCode', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '所属库区', name: 'DepotsAreaName', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '库排', name: 'LRow', width: 90, hidden:'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '库列', name: 'LColumn', width: 90, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '库层', name: 'LLayer', width: 90, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '库位属性', name: 'Property', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '库位状态', name: 'TurnoverDemand', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '库位类型', name: 'Type', width: 110, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '重量限制', name: 'Weight', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '体积限制', name: 'Volume', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '长', name: 'Long', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '宽', name: 'Width', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '高', name: 'Height', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '层数', name: 'NumPlies', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '混放产品', name: 'IsProduct', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
var html = "";
if (data == 0) {
html += '';
}
else {
html += '';
}
return html;
}
},
{
title: '混放批次', name: 'IsBatch', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
var html = "";
if (data == 0) {
html += '';
}
else {
html += '';
}
return html;
}
},
{
title: '备注', name: 'Demo', width: 120, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '创建日期', name: 'CreatTime', width: 130, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return git.JsonToDateTimeto(data);
}
},
{
title: '创建人', name: 'CreatUser', width: 80, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '修改日期', name: 'UpdateTime', width: 130, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return git.JsonToDateTimeto(data);
}
},
{
title: '修改人', name: 'UpdateUser', width: 80, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
return data;
}
},
{
title: '操作', name: 'Guid', width: 80, 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
});
//绑定事件
DepotsLocation.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: DepotsLocation.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;
$.gitAjax({
url: "/DLocationAjax/CheckDepartment",
data: { ajaxdata: Guid },
type: "post",
dataType: "json",
async: false,
success: function (result) {
if (result.Code == '1') {
$.jBox.tip("该库位别的部门已使用,不可修改!", "warn");
return false;
}
}
});
DepotsLocation.Dialog(Guid, "Edit");
}
});
},
// 获取查询条件
GetSearch: function () {
var search = {};
var searchBar = $("div[data-condition='search']");
search["DepotsAreaID"] = searchBar.find("select[name='DepotsArea']").val();
var LRow = searchBar.find("select[name='DepotsRow']").val();
var LColumn = searchBar.find("select[name='DepotsColumn']").val();
var LLayer = searchBar.find("select[name='DepotsLayer']").val();
search["LRow"] = 0;
if (LRow.length > 0)
{
search["LRow"] = LRow;
}
search["LColumn"] = 0;
if (LColumn.length > 0) {
search["LColumn"] = LColumn;
}
search["LLayer"] = 0;
if (LLayer.length > 0) {
search["LLayer"] = LLayer;
}
search["LocationCode"] = searchBar.find("input[name='LocationCode']").val();
search["PropertyID"] = searchBar.find("select[name='Property']").val();
search["TurnoverDemandID"] = searchBar.find("select[name='TurnoverDemand']").val();
search["TypeID"] = searchBar.find("select[name='Type']").val();
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 param = validation(h);
param["Guid"] = Guid;
$.gitAjax({
url: "/DLocationAjax/SetDLocations",
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");
DepotsLocation.PageClick(pageIndex, pageSize);
}
else {
$.jBox.tip(result.Message, "warn");
}
}
});
}
}
var validation = function (h) {
var param = {};
param["LRow"] = h.find('select[name = "LRow"]').val(); // 库排
param["LColumn"] = h.find('select[name = "LColumn"]').val(); // 库列
param["DepotsArea"] = h.find('select[name = "DepotsArea"]').val(); // 库区
param["LLayer"] = h.find('select[name = "LLayer"]').val(); // 库层
param["Type"] = h.find('select[name="Type"]').val(); // 库位类型
param["Property"] = h.find('select[name="Property"]').val(); // 库位属性
param["TurnoverDemand"] = h.find('select[name="TurnoverDemand"]').val(); // 库位状态
param["Weight"] = h.find("input[name='Weight']").val(); // 重量限制
param["Volume"] = h.find("input[name='Volume']").val(); // 体积限制
param["Long"] = h.find("input[name='Long']").val(); // 长
param["Width"] = h.find("input[name='Width']").val(); // 宽
param["Height"] = h.find("input[name='Height']").val(); // 高
param["NumPlies"] = h.find("input[name='NumPlies']").val(); // 层
param["Demo"] = h.find("input[name='Demo']").val(); // 备注
param["IsBatch"] = "1"; // 混放批次
param["IsProduct"] = "1"; // 混放产品
if ($("#IsBatch").prop('checked')){
param["IsBatch"] = "0";
}
if ($("#IsProduct").prop('checked')){
param["IsProduct"] = "0";
}
if (git.IsEmpty(param["Type"])) {
$.jBox.tip("请选择库位类型!", "warn");
return;
}
if (git.IsEmpty(param["Property"])){
$.jBox.tip("请选择库位属性!", "warn");
return;
}
if (git.IsEmpty(param["TurnoverDemand"])) {
$.jBox.tip("请选择库位状态!", "warn");
return;
}
var regPos = /^[+-]?(0|([1-9]\d*))(\.\d+)?$/; // 正则 数字
var regex = /^[0]+/;
var Weight = param["Weight"].replace(regex, "");
if (!regPos.test(Weight) || git.IsEmpty(Weight))
{
$.jBox.tip("重量限制应为数字!", "warn");
return;
}
//var Volume = param["Volume"].replace(regex, "");
if (!regPos.test(param["Volume"]) || git.IsEmpty(param["Volume"])) {
$.jBox.tip("体积限制应为数字!", "warn");
return;
}
var Long = param["Long"].replace(regex, "");
if (!regPos.test(Long) || git.IsEmpty(Long)) {
$.jBox.tip("长应为数字!", "warn");
return;
}
var Width = param["Width"].replace(regex, "");
if (!regPos.test(Width) || git.IsEmpty(Width)) {
$.jBox.tip("宽应为数字!", "warn");
return;
}
var Height = param["Height"].replace(regex, "");
if (!regPos.test(Height) || git.IsEmpty(Height)) {
$.jBox.tip("高应为数字!", "warn");
return;
}
return param;
}
//窗体加载完成回调事件
var loaded = function (h) {
// 设置禁止更改列
h.find('input[name="LocationCode"]').attr("disabled", "disabled");
h.find('input[name="NumPlies"]').attr("disabled", "disabled");
h.find('select[name = "DepotsArea"]').attr("disabled", "disabled");
h.find('select[name = "LRow"]').attr("disabled", "disabled");
h.find('select[name = "LColumn"]').attr("disabled", "disabled");
h.find('select[name = "LLayer"]').attr("disabled", "disabled");
}
switch (Command) {
case "Add":
$.jBox.open("get:/BasicInfo/DepotsLocation/AddEdit", "新增库位", 600, 450, { buttons: { "确定": true, "关闭": false },top:'5%', submit: submit });
break;
case "Edit":
$.jBox.open("get:/BasicInfo/DepotsLocation/AddEdit?Guid=" + Guid, "编辑库位", 600, 450, { 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 = DepotsLocation.Dialog("", "Add");
break;
case "Del":
var submit = function (v, h, f) {
if (v == "ok") {
var list = DepotsLocation.GetSelect();
if (list.length == 0) {
$.jBox.tip("请选择要删除的项", "warn");
return false;
}
var param = {};
param["list"] = JSON.stringify(list);
$.gitAjax({
url: "/DLocationAjax/DelLocations",
data: param,
type: "post",
dataType: "json",
success: function (result) {
// 提示操作信息
$.jBox.tip(result.Message, "success");
var pageSize = $("#mypager").pager("GetPageSize");
DepotsLocation.PageClick(1, pageSize);
}
});
}
}
$.jBox.confirm("确定要删除吗?", "提示", submit);
break;
case "Edits":
var list = DepotsLocation.GetSelect();
if (list.length == 0) {
$.jBox.tip("请选择要编辑的项", "warn");
return false;
}
for (i = list.length - 1; i >= 0; i--) {
console.log(i)
$.gitAjax({
url: "/DLocationAjax/CheckDepartment",
data: { ajaxdata: list[i]},
type: "post",
dataType: "json",
async: false ,
success: function (result) {
if (result.Code == '1') {
list.pop();
$.jBox.tip("已自动移除别的部门占用的库位!", "warn");
}
}
});
}
if (list.length == 0) {
$.jBox.tip("请选择本部门占用储位!", "warn");
return false;
}
var param = {};
param["list"] = JSON.stringify(list);
$.gitAjax({
url: "/DLocationAjax/SetLocationsSeession",
data: param,
type: "post",
dataType: "json",
success: function (result) {
// 提示操作信息
//$.jBox.tip(result.Message, "success");
// var pageSize = $("#mypager").pager("GetPageSize");
//DepotsArea.PageClick(1, pageSize);
}
});
var Guid = list[0];
DepotsLocation.Dialog(Guid, "Edit");
break;
default: break;
}
})
// 搜索按钮绑定查询事件 获取div => div.find事件搜寻按钮 => click事件
var searchBar = $("div[data-condition='search']");
searchBar.find("a[data-command='search']").click(function () {
// 调用查询方法,绑定分页信息
DepotsLocation.PageClick(1, 50);
});
$("#Region").change(function () {
var Region = ($(this).val()); // 获取库区编码
if (Region != "") {
$.gitAjax({
url: "/DLocationAjax/BindOption",
data: { ajaxdata: Region, opertype:"Region"},
type: "post",
dataType: "json",
success: function (result) { // result = 后台返回值
if (result != null) {
// 清空下拉框选项 重新赋值
$("#DepotsArea").empty();
$("#DepotsArea").html(result.DepotsArea);
$("#DepotsRow").empty();
$("#DepotsColumn").empty();
$("#DepotsLayer").empty();
}
}
})
}
});
$("#DepotsArea").change(function () {
var DepotsArea = ($(this).val()); // 获取库区编码
if (DepotsArea != "") {
$.gitAjax({
url: "/DLocationAjax/BindOption",
data: { ajaxdata: DepotsArea, opertype: ""},
type: "post",
dataType: "json",
success: function (result) { // result = 后台返回值
if (result != null) {
// 清空下拉框选项 重新赋值
$("#DepotsRow").empty();
$("#DepotsRow").html(result.DepotsRow);
$("#DepotsColumn").empty();
$("#DepotsColumn").html(result.DepotsColumn);
$("#DepotsLayer").empty();
$("#DepotsLayer").html(result.DepotsLayer);
}
}
})
}
});
//监听回车事件,用于扫描
searchBar.find("input[name='DepotsCode']").keydown(function (event) {
if (event.keyCode == 13) {
var value = $(this).val();
if (!git.IsEmpty(value)) {
DepotsLocation.PageClick(1, 50);
setTimeout(function () {
searchBar.find("input[name='DepotsCode']").val("");
searchBar.find("input[name='DepotsCode']").focus();
}, 300);
}
}
});
//窗体加载获得焦点
searchBar.find("input[name='DepotsCode']").focus();
//加载默认数据
DepotsLocation.PageClick(1, 50);
}
}