/**
* 货位管理
* @author weidy@2020/2/24
* @constructor
*/
layui.define(['layer','element','form','table','tree'],function(exports){
var Class = function(){
this.MODELNAME = "platform/basedoc/BdGoodsLocation";
this.moduleKey = "BdGoodsLocation";
this.id='BdGoodsLocation';
this.sourceData={};//来源数据,需要至少包含type,如果没有则默认为批产
this.columns = [];
this.personColumns = [];
this.backPath = configData.compatibility?path:configData.frameworkPath;//默认流程和项目的路径是一样的
this.url={
controller:"goodsLocationController/",
referWarehouse:'warehouseController/refTree',//参照库房
dataGrid:'getGoodsLocationByWarehouseOid',//列表数据和查询
add:'addGoodsLocation',//添加货位
edit:'editGoodsLocation',//编辑货位
checkIsDelete:'checkIsCanDelete',//是否可以删除
deleteUrl:'delGoodsLocation',//删除库房
disable:'disableGoodsLocation',//停用
enable:'enableGoodsLocation',//启用
referUser:'userQueryController/refDataGrid'
};
this.getContent=function(){//返回这个组件的基础html
var that = this;
var html = "";
html = [
'
',
'
',
'
',
'
',
that.getToolbarHtml(),
'
',//主列表
'
',
'
',
'
'
].join("");
return html;
};
this.getToolbarHtml =function(){
var that = this;
var html = [
'',//主列表的按钮
'',
'',
'',
'',
'',
'',
'
'
].join("");
return html;
};
this.init=function(){//基础的html被添加后,再执行初始化
var that = this;
that.firstTreeLoad =false;
$webUtil.copyConfig(that,that.moduleKey);
$webUtil.bindDefultButtonLisenter(that, that.id);
//初始化树界面
var filter= that.id;
var scrollHeight = window.innerHeight;
var treeUL = $('[layui-filter="tree_' + filter + '"]');
var treeHeight = scrollHeight - 200;
treeUL.parent().height(treeHeight);
layui.tree.init("tree_" + filter,$('[layui-filter="tree_' + filter + '"]'),{
url:that.url.referWarehouse,
backPath:that.backPath,
showSearch:true,
loadType:layui.tree.loadType.all,
treeFilter:that.id,
treeName:'goodLocations',
click:function(item,elem,options){
that.currentItemOid = item.oid;
that.currentItemAttributes = item.attributes;
layui.table.reload("table_" + that.id,{
where:{
warehouseOid:that.currentItemOid
}
});
},
done:function (thisFilter,result) {
//loadType为all的时候才能用这个事件
that.currentItemOid = "";
if(result && result.length > 0){
that.currentItemOid = result[0].oid;
}
if(!that.firstTreeLoad) {
that.initMainTable();
that.firstTreeLoad = true;
}
}
});
};
this.initMainTable = function () {
//初始化主列表
var that = this;
var table = layui.table;
that.checkColumns();//主列表中列。
table.render({
elem: '#table_' + that.id,
id: 'table_' + that.id,
url: that.backPath + that.url.controller + that.url.dataGrid,
page: {
limit: 30,
page: 1
},
where:{
warehouseOid:that.currentItemOid
},
cols: [that.columns],
done: function (res, cur, count) {
if(res && res.data && res.data.length>0){
table.selectRecord('table_' + that.id,res.data[0]);
}
}
});
$webUtil.createSearchHtml({
id: '货位编号',
name: '货位名称'
}, $('[layui-filter="toolbar_' + that.id + '"]'), 'table_' + that.id);
};
this.ADD = function(){//保存
var that = this;
that.dealData(true);
};
this.EDIT = function(){
var that = this;
var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
if(!oid){
return false;
}
that.dealData(false);
};
this.getFormItems = function(isEdit){
var that = this;
var table = layui.table;
return [{
type: 'text',
name: 'id',
text: '货位/货架编号',
required: true
}, {
type: 'text',
name: 'name',
text: '货位/货架名称',
required: true
}, {
type: 'refer',
name: 'curators',
text: '保管员',
showField:'curators',
referConfig:{
textField:'id,name',
valueField:'id,name',
type:'grid',
url: that.url.referUser,
backPath:that.backPath,
tableConfig:{
page:{
limit:15,
page:1
},
cols:[table.getIndexColumn(),table.getCheckColumn(),{
field:'id',
title:'用户名(账号)',
width:150
},{
field:'name',
title:'姓名',
width:150
},{
field:'usersecurity',
title:'密级',
width:80,
templet:function (d) {
return $webUtil.formateUserSecret(d.usersecurity);
}
}],
queryColumns:[{
field:'id',
title:'用户名(账号)'
},{
field:'name',
title:'姓名'
}]
}
}
},{
type: 'text',
name: 'outboundpriority',
text: '出库优先级',
verify:'number',
minValue:1,
maxValue:10,
defaultValue:1,
required: true
}, {
type: 'text',
name: 'inboundpriority',
text: '入库优先级',
verify:'number',
minValue:1,
maxValue:10,
defaultValue:1,
required: true
},{
type:'text',
name:'volume',
text:'容积'
},{
name:'description',
text:'描述',
useAllWidth:true,
width:570
}];
};
this.dealData = function(add){
var that = this;
if($webUtil.isNull(that.currentItemOid)){
$webUtil.showErrorMsg("请先选择库房节点");
return false;
}
var form = layui.form;
var filter ="form_" + that.id;
var locationOids = $webUtil.getOidFromGrid("table_" + that.id,false,true);
if(locationOids){
var pkFatherGoodsLocation = $webUtil.getOidFromGrid("table_" + that.id,false,false,'pkFatherGoodsLocation');
if(add && $webUtil.isNotNull(pkFatherGoodsLocation)){
$webUtil.showErrorMsg("货位上不能再添加下级货位;第一级为货架,货架的下级为货位");
return false;
}
}
var title = "货架";
if($webUtil.isNotNull(locationOids)){
title = "货位";
}
var addSaveIndex = layer.open({
type:1,
title:add?('添加' + title):('修改' + title),
btn:['保存','取消'],
skin:'layui-layer-lan',
content:'',
area:['800px','500px'],
closeBtn:2,
shade:true,
shadeClose:true,
resize:true,
resizing:function(layero){
form.doResize(filter);
},
success:function(layero) {
form.addItems(filter,that.getFormItems(),
function () {
if(!add){
//修改时直接设置值
var selectRowData = layui.table.checkStatus("table_" + that.id);
form.setValues(selectRowData.data[0],filter);
}else{
form.setValues({pkFatherGoodsLocation:locationOids},filter);
}
}, {}, {defaultColumnOneRow: 2});
},
yes:function(layero){
if(form.validata(filter)){
var values = form.getValues(filter,true);
values['pkWarehouse'] = that.currentItemOid;
var url = that.url.controller + (add?that.url.add:that.url.edit);
$webUtil.ajax(add?'post':'put',url,values,function(result){
if(result.success){
if($webUtil.isNull(result.msg)){
result.msg = add?"添加成功":"修改成功";
}
$webUtil.showMsg(result.msg);
layer.close(addSaveIndex);
that.refresh();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function(xhr,error){},that.backPath);
}
},
btn2:function(layero){
layer.close(addSaveIndex);
that.refresh();
}
});
};
this.DELETE = function(){
var that = this;
var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
if(!oid){
return false;
}
var ts = $webUtil.getOidFromGrid("table_" +that.id,false,false,"ts");
var submitValues = {oid:oid,ts:ts};
$webUtil.showConfirmMsg("是否删除这个货架/货位",function () {
$webUtil.post(that.url.controller + that.url.checkIsDelete,submitValues,function(result){
if(result.success){
if('true' == result.obj || result.obj == true ){
$webUtil.showConfirmMsg("当前货架包含有下级货位,将会把下级货位一起删除,你确定要继续?",function () {
that.doDelete(submitValues);
});
}else{
that.doDelete(submitValues);
}
}else{
$webUtil.showErrorMsg(result.msg);
}
},function (xhr,err) {
$webUtil.showErrorMsg("校验是否删除的时候出错了错误,可能是服务器暂时无法访问");
},that.backPath);
});
};
this.doDelete = function(submitValues) {
var that = this;
$webUtil.deleteRequest(that.url.controller + that.url.deleteUrl,submitValues,function(result){
if(result.success){
$webUtil.showMsgFromResult(result,"删除成功");
that.refresh();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function (xhr,err) {
$webUtil.showErrorMsg("执行删除的时候出错了错误,可能是服务器暂时无法访问");
},that.backPath);
};
this.STAR = function(){
var that = this;
that.operaData(that.url.controller +that.url.enable,'启用成功')
};
this.STOP = function(){
var that = this;
that.operaData(that.url.controller +that.url.disable,'停用成功')
};
this.operaData = function(url,msg){
var that = this;
var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
if(!oid){
return false;
}
$webUtil.showConfirmMsg("子节点是否一起操作?",function(){
$webUtil.post(url,{
oid:oid,
children:true
},function(result){
if(result.success){
$webUtil.showMsg(msg);
that.refresh();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function (xhr,err) {
$webUtil.showErrorMsg("执行的时候出错了错误,可能是服务器暂时无法访问");
},that.backPath)
},function(){
$webUtil.post(url,{
oid:oid,
children:false
},function(result){
if(result.success){
$webUtil.showMsg(msg);
that.refresh();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function (xhr,err) {
$webUtil.showErrorMsg("执行的时候出错了错误,可能是服务器暂时无法访问");
},that.backPath);
});
};
this.checkColumns = function(){
var that = this;
var table = layui.table;
if(that.columns==null || that.columns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列
that.columns = [table.getIndexColumn(),table.getCheckColumn(),{
field:'id',
title:'货位/货架编号',
width:120
},{
field:'name',
title:'货位/货架名称',
width:200
},{
field:'curators',
title:'保管员',
width:100
},{
field:'outboundpriority',
title:'出库优先级',
width:100
},{
field:'inboundpriority',
title:'入库优先级',
width:100
},{
field:'volume',
title:'容积',
width:100
},{
field:'lcStatusText',
title:"状态",
width:100
}];
}
};
this.refresh = function(){
var that = this;
layui.table.reload("table_" + that.id);
};
};
var c = new Class();
exports(c.MODELNAME,c);
});