/**
* 库房管理/仓库基本信息
* @author weidy@2020/2/24
* @constructor
*/
layui.define(['layer','element','form','table','tree','transfer'],function(exports){
var Class = function(){
this.MODELNAME = "platform/basedoc/BdWarehouse";
this.moduleKey = "BdWarehouse";
this.id='BdWarehouse';
this.sourceData={};
this.backPath = configData.compatibility?path:configData.frameworkPath;
this.buttonIconMap = {};
this.url={
controller: 'warehouseController/',
tree:'warehouseClassifyController/treeAllEnabledWarehouseClassify',
referClassifyTree:'warehouseClassifyController/referTree',
listWarehouseByClass:'gridWarehouseByClassify',
listAdmin:'getAdminByWareHouseOid',
referWarehouse:'refTree',
add:'addWarehouse',
edit:'editWarehouse',
deleteUrl:'delWarehouse',
enabled:'enableWarehouse',
disabled:'disableWarehouse',
unLinkUser:'userQueryController/refDataGrid',
linkUser:'addWarehouseAdmin',
removeLinkUser:'delWarehouseAdmin'
};
this.controllerSecret = configData.controllerSecret;
this.columns = [];
this.getContent=function(){//返回这个组件的基础html
var that = this;
var html = "";
html = [
'
',
'
',
'
',
'
',
that.getToolbarHtml(),
'
',
'
',
'
',
that.getDetailToolbarHtml(),
'
',
'
',
'
',
'
',
'
'
].join("");
return html;
};
this.getToolbarHtml = function(){
var that =this;
return ['',
'',
'',
'',
'',
'',
'',
'
'].join("");
};
this.getDetailToolbarHtml = function () {
var that =this;
return ['',
'',
'',
'',
'
'].join("");
};
this.init=function(){
//基础的html被添加后,再执行初始化
var that = this;
that.firstTreeLoad =false;
that.firstGridLoad = false;
$webUtil.copyConfig(that,that.moduleKey);
$webUtil.bindDefultButtonLisenter(that, that.id);
var tree = layui.tree;
var scrollHeight = window.innerHeight;
var treeUL = $('[layui-filter="tree_' + that.id + '"]');
var treeHeight = scrollHeight - 200;
treeUL.parent().height(treeHeight);
tree.init("tree_" + that.id, treeUL, {
url: that.url.tree,
backPath: that.backPath,
extraParams: {
isMuti: false
},
loadType:layui.tree.loadType.all,
showSearch:true,
click: function (item, elem, options) {
that.currentItemOid = item.oid;
that.currentItemAttributes = item.attributes;
that.loadListByClassify();
},
done: function (thisFilter,result) {
that.currentItemOid = "";
if(result && result.length > 0){
that.currentItemOid = result[0].oid;
}
if(!that.firstTreeLoad) {
that.initMainTable();
that.firstTreeLoad = true;
}
}
});
};
this.initMainTable = function(callback){
//加载主列表
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.listWarehouseByClass,
page: {
limit: 20,
page: 1
},
where:{
pkWarehouseClassify:that.currentItemOid
},
selectMode:table.selectMode.muti,
cols: [that.columns],
rowClick:function(filter,data){
if(data){
that.loadLinkAdmin(data.oid);
}
},
done:function(res, cur, count){
if(!that.firstGridLoad) {
that.initDetailTable((res && res.data) ? res.data[0] : "");
that.firstGridLoad = true;
}
}
});
$webUtil.createSearchHtml({
id:'库房编号',
name:'库房名称'
},$("[layui-filter='toolbar_button_" + that.id + "']"),'table_' + that.id);
$webUtil.bindDefultButtonLisenter(that, "table_" + that.id);
};
this.loadListByClassify = function(){
//加载右侧的表
var that = this;
if($webUtil.isNull(that.currentItemOid)){
return;
}
layui.table.reload("table_" + that.id,{
where:{
pkWarehouseClassify: that.currentItemOid
}
});
};
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:150
},{
field:'name',
title:'库房名称',
width:200
},{
field:'address',
title:'库房地址',
width:150
},{
field:'hearder',
title:'负责人',
width:80
},{
field:'tel',
title:'联系电话',
width:120
},{
field:'parentWarehouseText',
title:'上级库房',
width:150
},{
field:'pkDepartmentName',
title:'管理部门',
width:150
},{
field:'secretGradeText',
title:'密级',
width:90,
hidden:!that.controllerSecret
},{
field:'lcStatusText',
title:'状态',
width:90
}];
}
};
this.checkDetailColumns = function () {
var that = this;
var table = layui.table;
if(that.detailColumns==null || that.detailColumns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列
that.detailColumns = [table.getIndexColumn(),table.getCheckColumn(),{
field:'userId',
title:'用户名',
width:150
},{
field:'userName',
title:'管理员姓名',
width:200
},{
field:'options',
title:'操作',
toolbar: '#toolbar_column_' + that.id
}];
}
};
this.initDetailTable = function(wareHouseOid){
var that = this;
var table = layui.table;
that.checkDetailColumns();//主列表中列。
table.render({
elem: '#detail_table_' + that.id,
id: 'detail_table_' + that.id,
url: that.backPath + that.url.controller + that.url.listAdmin,
where:{
wareHouseOid:wareHouseOid
},
width:550,
selectMode:table.selectMode.muti,
cols: [that.detailColumns],
done:function (res,curr,count) {
table.on('tool(detail_table_' + that.id + ')',function(obj){
var data = obj.data;//当前选择行的数据
var layEvent = obj.event;//点的是什么按钮
if(layEvent == 'removeLinkPerson'){
that.doRemoveLinkPerson([data]);
}
});
}
});
document.getElementById("toolbar_column_" + that.id).innerHTML = '移除';
$webUtil.bindDefultButtonLisenter(that, "detail_table_" + that.id);
};
this.loadLinkAdmin = function (warehouseOid) {
var that = this;
layui.table.reload('detail_table_' + that.id,{
where:{
wareHouseOid:warehouseOid
}
});
};
this.ADD=function(){
var that = this;
that.addOrEdit(false);
};
this.EDIT = function () {
var that = this;
that.addOrEdit(true);
};
this.addOrEdit = function(edit){
var that = this;
var filter ="addForm_" + that.id;
var form = layui.form;
var oid;
if(edit){
//先获取数据
oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
if(!oid){
return false;
}
}
var selectRowData = layui.table.checkStatus("table_" + that.id);
var addSaveIndex = layer.open({
type:1,
title:edit?'修改库房档案':'添加库房档案',
btn:['保存','取消'],//,'保存新增'],
skin:'layui-layer-lan',
content:'',
area:['850px','510px'],
closeBtn:2,
shade:true,
shadeClose:true,
resize:true,
resizing:function(layero){
form.doResize(filter);
},
success:function(layero){
form.addItems(filter,that.getFormItems(), function(){
//新增的时候,把左侧选择的节点需要添加在库房类别上
if(!edit) {
var values = {};
if($webUtil.isNotNull(that.currentItemOid) && that.currentItemAttributes){
values = {
pkWarehouseClassify:that.currentItemAttributes.oid,
pkWarehouseClassifyText:that.currentItemAttributes.name,
warehouseClassifyId:that.currentItemAttributes.id
}
}
values['pkDepartment'] = $webUtil.getSystemVar($webUtil.systemValueKey.deptOid);
values['pkDepartmentName'] = $webUtil.getSystemVar($webUtil.systemValueKey.deptName);
form.setValues(values, filter);
}else{
//修改的时候就需要把整个数据添加进去
form.setValues(selectRowData.data[0], filter);
}
},{},{defaultColumnOneRow:2,inDialog:true});
},
yes:function(layero){
if(form.validata(filter)){
var values = form.getValues(filter,true);
$webUtil.ajax(edit?'put':'post',that.url.controller + (edit?that.url.edit:that.url.add),values,function(result){
if(result.success){
if($webUtil.isNull(result.msg)){
result.msg = edit?"修改库房成功":'添加库房成功';
}
$webUtil.showMsg(result.msg);
layer.close(addSaveIndex);
that.refresh(that.currentItemOid);
}else{
$webUtil.showErrorMsg(result.msg);
}
},function (xhr,error) {
$webUtil.showErrorMsg("维护库房的信息的时候出现了错误");
},that.backPath);
}
},
btn2:function(layero){
layer.close(addSaveIndex);
that.refresh(that.currentItemOid);
}
});
};
this.DEL = function(){
var that = this;
var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
if(!oid){
return false;
}
$webUtil.showConfirmMsg("您确定要删除这个库房吗,如果库房中已经存在业务数据将不能被删除",function () {
that.doOperaData(oid,that.url.controller + that.url.deleteUrl,'删除成功',true,true);
});
};
this.ENABLE = function(){
var that = this;
var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
if(!oid){
return false;
}
$webUtil.showConfirmMsg("是否同时启用下级库房", function () {
that.doOperaData(oid,that.url.controller + that.url.enabled,'启用成功', false, true);
}, function () {
that.doOperaData(oid,that.url.controller + that.url.enabled,'启用成功', false, false);
});
};
this.DISABLE = function(){
var that = this;
var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
if(!oid){
return false;
}
$webUtil.showConfirmMsg("是否同时停用下级库房", function () {
that.doOperaData(oid,that.url.controller + that.url.disabled,'停用成功', false, true);
}, function () {
that.doOperaData(oid,that.url.controller + that.url.disabled,'停用成功', false, false);
});
};
this.doOperaData = function (oid,url,msg,deleteFlag,cascade) {
var that = this;
$webUtil.ajax(deleteFlag?'delete':'post',url,{
oid:oid,
cascade:cascade
},function(result){
if(result.success){
if($webUtil.isNull(result.msg)){
result.msg = msg;
}
$webUtil.showMsg(msg);
that.refresh(that.currentItemOid);
}else{
$webUtil.showErrorMsg(result.msg);
}
},function(xhr,error){
$webUtil.showErrorMsg("请求服务出现了错误,可能是因为服务器被关闭,网络连接失败或者程序错误");
},that.backPath);
};
this.refresh = function(classifyOid,warehouseOid){
var that = this;
if($webUtil.isNull(classifyOid) && $webUtil.isNull(warehouseOid)){
layui.tree.reload("tree_" + that.id);
that.currentItemOid = null;
that.currentItemAttributes = null;
}
if($webUtil.isNotNull(classifyOid)){
layui.table.reload("table_" + that.id);
}
if($webUtil.isNotNull(warehouseOid)) {
layui.table.reload("detail_table_" + that.id);
}
};
this.getFormItems = function(){
var that = this;
return [{
field: 'id',
text: '库房编号',
required:true
}, {
field: 'name',
text: '库房名称',
required:true
},{
field:'pkWarehouseClassify',
text:'所属库房类别',
type:'refer',
required:true,
showField:'pkWarehouseClassifyText',
referConfig:{
type:'tree',
url: that.url.referClassifyTree,
backPath:that.backPath,
textField:'name',
valueField:'oid',
isMuti:false
}
}, {
field: 'address',
text: '库房地址'
},{
field:'hearder',
text:'库房负责人'
}, {
field: 'tel',
text: '联系电话'
},{
field: 'parentWarehouse',
text: '上级库房',
type:'refer',
showField:'parentWarehouseText',
referConfig:{
type:'tree',
url:that.url.controller + that.url.referWarehouse,
backPath:that.backPath,
textField:'id,name',
valueField:'oid',
extraParams: {
pkWarehouseClassify:that.currentItemOid
},
useFormKey:'pkWarehouseClassify',
isMuti:false
}
}, {
field: 'pkDepartment',
text: '管理部门',
type:'refer',
showField:'pkDepartmentName',
referConfig:{
type:layui.vciAlias.referRegister.departmentRefer
}
},layui.vciWebComboxStore.getSecretObject(that.controlSecret)];
};
this.LINKUSER = function() {
var that = this;
//设置管理员
var table = layui.table;
var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
if(!oid){
return false;
}
var sendPerIndex = layer.open({
type:1,
title:'选择管理员添加到库房',
btn:['确定','取消'],
skin:'layui-layer-lan',
content:'',
area:['500px','610px'],
closeBtn:2,
shade:true,
shadeClose:true,
resize:false,
yes:function(layero){
var getData = layui.transfer.getData('linkuser_'+that.id);
var userOids = [];
if(getData && getData.length > 0){
for(var i = 0 ; i < getData.length ; i ++){
var value = getData[i]["value"];
if(!value || value == "undefined"){
value = "";
}
userOids.push(value);
}
}
if(userOids.length == 0){
$webUtil.showAutoMsg("请先选择管理员后再点击【确定】按钮");
return false;
}
var submitValues = {
f_oid:oid
};
for(var i = 0 ; i < userOids.length ; i ++){
submitValues['t_oid[' + i + ']'] = userOids[i];
}
$webUtil.post(that.url.controller + that.url.linkUser,submitValues,function(result){
if(result.success){
if($webUtil.isNull(result.msg)){
result.msg = "添加管理员成功";
}
$webUtil.showMsg("添加管理员成功");
layer.close(sendPerIndex);
that.refresh(null,oid);
}else{
$webUtil.showErrorMsg(result.msg);
}
},function(xhr,err){
$webUtil.showErrorMsg("执行保存管理员的时候出现了错误");
},that.backPath);
},
btn2:function(index,layero){
layer.close(sendPerIndex);
},
success:function(layero){
//从后台获取到用户的信息,然后添加到穿梭框中
var linkedUsers = table.checkStatus("detail_table_" + that.id);
var queryMap = {
limit:-1
};
if(linkedUsers && linkedUsers.data && linkedUsers.data.length >0){
var linkedUserOids = [];
layui.each(linkedUsers.data,function(_index,_item){
linkedUserOids.push("'" + _item.toid + "'");
});
queryMap['conditionMap["oid"]'] = "\\NOTIN(" + linkedUserOids.join(",") + ")";
}
$webUtil.get( that.url.unLinkUser,queryMap,function(result){//获取穿梭框的管理员
if(result.success){
layui.transfer.render({
elem: '#inkperson_'+that.id
,data: result.data
,width:200
,height:500
,id:'linkuser_'+that.id//索引
,parseData: function(res){
return {
"value": res.oid //数据值
,"title": (res.id + " " + res.name)//数据标题
}
}
,title: ['未选管理员', '已选管理员']
,showSearch: true
})
}else{
$webUtil.showErrorMsg(result.msg);
}
},function(xhr,err){
$webUtil.showErrorMsg("执行保存管理员的时候出现了错误");
},that.backPath,true);
}
});
};
this.REMOVEUSER = function () {
var that = this;
var oid = $webUtil.getOidFromGrid("detail_table_" +that.id,true,false);
if(!oid){
return false;
}
var selectData = layui.table.checkStatus("detail_table_" +that.id);
that.doRemoveLinkPerson(selectData.data);
};
this.doRemoveLinkPerson = function(records){
var that = this;
//执行移除,和最后一列显示的一样
if(!records){
return false;
}
if(!$webUtil.isArray(records)){
records = [records];
}
var oids = "";
layui.each(records,function(_index,_item){
oids += _item.oid + ",";
});
oids = layui.util.removeComma(oids);
$webUtil.showConfirmMsg("您是否确定移除这" + records.length + "个管理员?",function(){
$webUtil.deleteRequest(that.url.controller +that.url.removeLinkUser,{warehouseAdminOids:oids},function(result){
if(result.success){
if($webUtil.isNull(result.msg)){
result.msg = "移除成功";
}
$webUtil.showMsg(result.msg);
that.refreshUser();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function(xhr,error){
$webUtil.showErrorMsg("移除管理员出错,可能是服务器无法连接")
},that.backPath);
});
};
this.refreshUser = function(){
var that = this;
layui.table.reload("detail_table_" + that.id);
};
};
var c = new Class();
exports(c.MODELNAME,c);
});