/**
* 部门管理
* @author weidy@2018-06-04
* @constructor
*/
layui.define(['layer','element','form','table','tree'],function(exports){
var Dept = function(){
this.MODELNAME = "platform/orgs/orgsDepartment";
this.moduleKey = "orgDept";
this.id='orgDept';
this.sourceData={};
this.deptTree = null;
this.deptForm = null;
this.backPath = configData.compatibility?path:configData.frameworkPath;
this.buttonIconMap = {};
this.url={
controller:'departmentController/',
tree:'deptTree',
add:'add',
edit:'edit',
checkIsDelete:'checkIsCanDelete',
deleteUrl:'delete',
disableUrl:'disable',
enableUrl:"enable",
referUser:'userQueryController/refDataGrid'
};
this.getContent=function(){
var that = this;
var html = "";
html = [
that.getToolbarHtml(),
'
'
].join("");
return html;
};
this.getToolbarHtml = function(){
var that = this;
return ['',//主列表的按钮
'',
'',
'',
'',
'',
'',
'
'].join("");
};
this.init=function(){//基础的html被添加后,再执行初始化
var that = this;
$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.controller + that.url.tree,
backPath: that.backPath,
extraParams: {
isMuti: false,
isQueryAllColumn: true
},
showSearch:true,
click: function (item, elem, options) {
that.currentItemOid = item.oid;
that.currentItemAttributes = item.attributes;
that.setFormValues(that.currentItemAttributes);
},
done: function (thisFilter) {
that.initForm();
}
});
};
this.initForm = function(){
var that = this;
var form = layui.form;
form.addItems("form_inPanel" + that.id, that.getFormItems(true), function () {
}, {}, {
defaultColumnOneRow: 1,
labelWidth: 150,
textWidth:240
});
};
this.setFormValues = function (attributes) {
var that = this;
if(attributes){
try{
var form = layui.form;
form.clear("form_inPanel" + that.id,true);
form.setValues(attributes,"form_inPanel" + that.id);//不需要转换对象,因为attributes已经是对象格式了
}catch (e){
$webUtil.showDebugMsg(e);
}
}
};
this.getFormItems = function(onlyShow){
var that = this;
return [{
field: 'id',
text: '部门编号',
required:true,
readOnly: onlyShow
}, {
field: 'name',
text: '部门名称',
required:true,
readOnly: onlyShow
},{
name:'departmentLevel',
text:'部门级别',
type:'combox',
data:[{key:1,value:"业务单元/分厂"},{key:2,value:"部门"}]
},{
name:'pkLeader',
text:'部门主管领导',
type:'refer',
showField:'pkLeaderName',
readOnly: onlyShow,
referConfig:{
type:layui.vciAlias.referRegister.userRefer
}
},{
field:'pkFatherDepartment',
text:'上级部门',
type:'refer',
showField: 'pkFatherDepartmentName',
readOnly: onlyShow,
referConfig:{
type:layui.vciAlias.referRegister.departmentRefer
}
},{
name:'address',
text:'部门位置',
readOnly: onlyShow
},{
name:'tel',
readOnly: onlyShow,
text:'电话'
},{
name:'description',
readOnly: onlyShow,
text:'备注'
},{
field: 'lcStatusText',
text: '状态',
readOnly: true,
hidden:!onlyShow
}];
};
this.getUserReferColumns = function(){
var table = layui.table;
return [table.getIndexColumn(),table.getCheckColumn(),{
field:'id',
title:'用户名',
width:120
},{
field:'name',
title:'姓名',
width:120
},{
field:'secretGradeText',
title:'密级',
width:90
}];
};
this.ADD = function(){//保存
var that = this;
that.addOrEdit(true);
};
this.EDIT = function(){
var that = this;
that.addOrEdit(false);
};
this.addOrEdit = function (add) {
var that = this;
if(!add && $webUtil.isNull(that.currentItemOid)){
$webUtil.showErrorMsg("请先选择一个部门");
return false;
}
var filter = "addOrEdit_" + that.id;
var form = layui.form;
var addSaveIndex = layer.open({
type: 1,
title: add?'新增部门':'修改部门',
btn: ['保存', '取消'],
skin: 'layui-layer-lan',
content: '',
area: ['900px', '500px'],
closeBtn: 2,
shade: true,
shadeClose: true,
resize: true,
resizing: function (layero) {
form.doResize(filter);
},
success: function (layero) {
form.addItems(filter,that.getFormItems(false),
function () {
if(add){
//添加的时候,如果选择了节点,那么选择的节点就是当前的上级节点
if($webUtil.isNotNull(that.currentItemOid)){
form.setValues({
pkFatherDepartment:that.currentItemOid,
pkFatherDepartmentName:(that.currentItemAttributes.id + " " + that.currentItemAttributes.name)
},filter);
}else{
form.setValues({},filter);
}
}else{
form.setValues(that.currentItemAttributes,filter);
}
}
, {}
, {
defaultColumnOneRow: 2,
labelWidth: 150,
textWidth:240
});
},
yes:function(layero){
if(form.validata(filter)){
var formValues = form.getValues(filter,true);
$webUtil.ajax(add?'post':'put',that.url.controller + (add?that.url.add:that.url.edit),formValues,function (result) {
if(result.success){
$webUtil.showMsgFromResult(result,add?"新增部门":"修改部门");
that.refresh(that.currentItemOid);
layer.close(addSaveIndex);
}else{
$webUtil.showErrorMsg(result.msg);
}
},function (xhr,error) {
$webUtil.showErrorMsg("访问服务器出现了错误,可能服务器没有开启,或者连接失败");
},that.backPath);
}
},
btn2:function(layero){
that.refresh();
layer.close()
}
});
};
this.DEL= function(){
var that = this;
if($webUtil.isNull(that.currentItemOid)){
$webUtil.showErrorMsg("请先选择一个部门");
return false;
}
var ts = that.currentItemAttributes.ts;
$webUtil.showConfirmMsg("是否删除这个部门?如果被用户等信息引用将不能被删除!",function () {
var submitValue = {oid:that.currentItemOid,ts:ts};
$webUtil.post(that.url.controller + that.url.checkIsDelete,submitValue,function(result){
if(result.success){
if('true' == result.obj || true == result.obj){
$webUtil.showConfirmMsg("当前分类包含有下级部门,要删除的话会和下级部门一起删除,你确认继续?",function () {
that.doDelete(submitValue);
});
}else{
//说明可以删除
that.doDelete(submitValue);
}
}else{
$webUtil.showErrorMsg(result.msg);
}
},function (xhr,error) {
$webUtil.showErrorMsg("校验删除出现了错误,可能是服务器未启动")
},that.backPath);
});
};
this.doDelete = function (submitValue) {
var that = this;
$webUtil.deleteRequest(that.url.controller + that.url.deleteUrl,submitValue,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;
if($webUtil.isNull(that.currentItemOid)){
$webUtil.showErrorMsg("请先选择一个部门");
return false;
}
that.operaData(that.url.controller +that.url.enableUrl,{oid:that.currentItemOid,ts:that.currentItemAttributes.ts},'启用成功')
};
this.STOP = function(){
var that = this;
if($webUtil.isNull(that.currentItemOid)){
$webUtil.showErrorMsg("请先选择一个部门");
return false;
}
that.operaData(that.url.controller +that.url.disableUrl,{oid:that.currentItemOid,ts:that.currentItemAttributes.ts},'停用成功')
};
this.operaData = function(url,submitValue,msg){
var that = this;
if($webUtil.isNull(that.currentItemOid)){
return false;
}
that.showConfirmMsg("子节点是否一起操作?",function(){
submitValue['cascade'] = true;
$webUtil.post(url,submitValue,function(result){
if(result.success){
$webUtil.showMsgFromResult(result,msg);
that.refresh();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function (xhr,err) {
$webUtil.showErrorMsg("执行的时候出错了错误,可能是服务器暂时无法访问");
},that.backPath)
},function(){
$webUtil.post(url,submitValue,function(result){
if(result.success){
$webUtil.showMsgFromResult(result,msg);
that.refresh();
}else{
$webUtil.showErrorMsg(result.msg);
}
},function (xhr,err) {
$webUtil.showErrorMsg("执行的时候出错了错误,可能是服务器暂时无法访问");
},that.backPath);
});
};
this.showConfirmMsg = function (title,yes,cancel){
layer.open($.extend({
content: title,
btn: ['是','否'],
yes: yes,
btn2: cancel
}, {icon:3,title:'需要您确认'}));
};
this.refresh = function(parentNodeOid){
var that = this;
var tree = layui.tree;
if($webUtil.isNotNull(parentNodeOid)){
tree.reloadNode("tree_" + that.id,parentNodeOid);
}else {
tree.reload("tree_" + that.id);
}
};
};
var dept = new Dept();
exports(dept.MODELNAME,dept);
});