You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

502 lines
19 KiB

4 years ago
define(function(require, exports, module) {
var Biz = require('system/base/biz');
var ModifyPswWin = require('../frs007/change');
var CopyUserRight = require('./CopyUserRight');
var multiWindow = require("system/views/pages/multiwindow/multiwindow");
var md5 = window.CryptoJS.md5;
var userType = Store.logOn.userType;
var userOrgCode = Store.logOn.rightCtrlOrgCode;
function UserBiz(vm) {
Biz.call(this, vm);
};
inherits(UserBiz, Biz);
UserBiz.prototype.initCompleted = function() {
this.super('initCompleted');
};
UserBiz.prototype.beforeRefresh = function() {
// if (userType !== '0')
// this.dsMaster.fixQuery['RightCtrlOrgId'] = Store.logOn.rightCtrlOrgId;
return this.super('beforeRefresh');
};
UserBiz.prototype.doOp = function(opCode) {
this.super('doOp');
var self = this;
function addRole(data) {
var _nwRow = self.dsDetail1.addRow();
_nwRow.setColumnText("RoleID", data.RoleID);
_nwRow.setColumnText("RoleCode", data.RoleCode);
_nwRow.setColumnText("RoleName", data.RoleName);
return true;
}
function addOrg(data) {
var _nwRow = self.dsDetail2.addRow();
_nwRow.setColumnText("ValueCode", data.OrgCode);
_nwRow.setColumnText("ValueName", data.OrgName);
return true;
}
var modifyPswWin = null;
var copyUserRight = null;
var userId = null;
var userCode = null;
var userName = null;
var oldPsw = null;
var userTypeCur = null;
var userOrgIdCur = null;
var currentRow = self.dsMaster.currentRow;
if (currentRow !== null) {
userId = currentRow['UserID'];
userCode = currentRow['UserCode'];
userName = currentRow['UserName'];
oldPsw = currentRow['Passwd'];
userOrgIdCur = currentRow['RightCtrlOrgCode'];
userTypeCur = currentRow['UserType'];
} else {
return false;
}
switch (opCode) {
//修改密码按钮操作事件
case 'cus01':
if (userId !== Store.logOn.userId) {
Store.messager.warn(Store.MSG.FRS001_01);
return false;
}
currentRow.setColumnValue('IsClear', '0');
var options = {
doneCb: function(data) {
if (data.success) {
Store.messager.tip(Store.MSG.PASSWORD_CHANGE_SUCCESS);
}
}
};
modifyPswWin = new ModifyPswWin(options);
modifyPswWin.open();
break;
//清密码按钮操作事件
case 'cus02':
if (currentRow === null) return false;
if (userType === '2') {
Store.messager.warn(Store.MSG.FRS001_02);
return false;
}
if ((userType === '1' || userType === '0') && currentRow['UserID'] === Store.logOn.userId) {
Store.messager.warn(Store.MSG.FRS001_03);
return false;
}
if (userType === '1' && userTypeCur === '0') {
Store.messager.warn(Store.MSG.FRS001_07);
return false;
}
if (userType === '1' && userOrgIdCur !== userOrgCode) {
Store.messager.warn(Store.MSG.FRS001_08);
return false;
}
Store.messager.confirm(Store.format(Store.MSG.FRS001_09, userCode, userName), function(cfmClear) {
if (cfmClear) {
currentRow.setColumnValue('IsClear', '1');
currentRow.setColumnValue('PasswdOri', '0');
var params = {
plugin: 'userCommPlugin',
pluginData: {
isClear: '1',
userId: userId,
userCode: userCode,
oldPassword: md5(userCode.toLowerCase()+oldPsw).toString(),
newPassword: md5(userCode.toLowerCase()+'0').toString()
}
};
Store.services.executeplugin(params, function(isOk, result) {
if (isOk)
Store.messager.tip(Store.MSG.FRS001_10);
else
currentRow.setColumnValue('PasswdOri', null);
});
}
});
break;
//失效按钮操作事件
case 'cus03':
if (userType === '2') {
Store.messager.warn(Store.MSG.FRS001_11);
return false;
}
if (userType === '1' && userTypeCur === '0') {
Store.messager.warn(Store.MSG.FRS001_12);
return false;
}
if (userType === '1' && userOrgIdCur !== userOrgCode) {
Store.messager.warn(Store.MSG.FRS001_13);
return false;
}
var isEnable = currentRow['IsEnable'];
if (isEnable === '0') {
Store.messager.confirm(Store.format(Store.MSG.FRS001_14, userCode, userName), function(cfm) {
if (cfm) {
currentRow.setColumnValue('IsEnable', '1');
currentRow.setColumnValue('BgnDate', Store.bizDao.getSysDate());
currentRow.setColumnValue('EndDate', '9999-01-01 00:00:00');
self.dsMaster.save(function(isSuccess) {
if (!isSuccess) {
currentRow.setColumnValue('IsEnable', '0');
self.dsMaster.rejectChanges();
} else {
Store.messager.tip(Store.MSG.FRS001_15);
self.callView('updateOpEnable', true);
}
});
}
});
} else {
Store.messager.confirm(Store.format(Store.MSG.FRS001_16, userCode, userName), function(cfmFail) {
if (cfmFail) {
currentRow.setColumnValue('IsEnable', '0');
currentRow.setColumnValue('EndDate', Store.bizDao.getSysDate());
self.dsMaster.save(function(isSuccess) {
if (!isSuccess) {
currentRow.setColumnValue('IsEnable', '1');
self.dsMaster.rejectChanges();
} else {
Store.messager.tip(Store.MSG.FRS001_17);
self.callView('updateOpEnable', true);
}
});
}
});
}
break;
//复制权限按钮操作事件
case 'cus04':
if (userType === '2') {
Store.messager.warn(Store.MSG.FRS001_18);
return false;
}
if (copyUserRight) {
copyUserRight.open();
} else {
copyUserRight = new CopyUserRight(self.dsMaster);
copyUserRight.open();
}
break;
//批量增加角色
case 'cus05':
if (userType === '2') {
Store.messager.warn(Store.MSG.FRS001_19);
return false;
}
//tab页焦点设置在角色明细上
this.view.selectTab(self.dsMaster, 0);
var exists = new Array();
for (var j = 0; j < self.dsDetail1.rows.length; j++) {
exists.push({
'RoleID': self.dsDetail1.rows[j].RoleID
});
}
var param = {
exists: exists,
uiObjCode: 'tFrsRole',
biz: self,
itreator: function(data) {
return addRole(data);
}
};
var mywindow = new multiWindow(param);
mywindow.open();
break;
//批量增加组织
case 'cus06':
if (userType === '2') {
Store.messager.warn(Store.MSG.FRS001_20);
return false;
}
//tab页焦点设置在组织明细上
this.view.selectTab(self.dsMaster, 1);
var exists = new Array();
for (var j = 0; j < self.dsDetail2.rows.length; j++) {
exists.push({
'OrgId': self.dsDetail2.rows[j].ValueID
});
}
var param = {
exists: exists,
uiObjCode: 'vFrsOrg',
biz: self,
fixQuery: {
'!OrgCode': '0'
},
itreator: function(data) {
return addOrg(data);
}
};
var mywindow = new multiWindow(param);
mywindow.open();
break;
}
return true;
}
UserBiz.prototype.afterDataSrcLoadData = function(dataSrc, isOk) {
var self = this;
if (dataSrc === self.dsFrsUserOrgRight) {
initDataListCheck(self);
}
};
UserBiz.prototype.stateChanged = function(newState, oldState) {
var self = this;
if ((newState === 'browser' && oldState === 'cancel') || (newState === 'add' && oldState === 'browser')) {
initDataListCheck(self);
}
}
/**
* 打开界面时组织权限限定字段的初始化勾选状态
* @param {[type]} self [当前biz]
* @return {[type]} [description]
*/
function initDataListCheck(self) {
var orgCtrlEnable = Store.bizDao.getOptionValueSync('FRS_IsOrgFieldCtrlEnable', '', '');
if(orgCtrlEnable === '0') return;
var orgCtrlDataObjId = Store.bizDao.getOptionValueSync('FRS_OrgFieldCtrlDataObjId', '', '');
var orgFieldCtrlName = Store.bizDao.getOptionValueSync('FRS_OrgFieldCtrlName', '', '');
if (orgCtrlDataObjId === '' || orgFieldCtrlName === '') return;
var fieldCtrlArray = orgFieldCtrlName.split(';');
for (var i = 0; i < fieldCtrlArray.length; i++) {
_.each(self.view.resultData[i].data, function(resultData, dataIndex) {
var flag = false; //
_.each(self.dsFrsUserOrgRight.rows, function(row, rowIndex) {
if (row['UserId'] === self.dsMaster.currentRow['UserID'] && resultData['fieldname'] === row['OrgFieldName'] && resultData['value'] === row['OrgFieldValue']) {
$('.pageuser-widgebt-gridOrgCtrl:eq(' + i + ')').datalist('checkRow', dataIndex);
flag = true;
}
});
if (!flag) {
$('.pageuser-widget-gridOrgCtrl:eq(' + i + ')').datalist('uncheckRow', dataIndex);
}
});
}
}
UserBiz.prototype.beforeAdd = function() {
if (userType === '2') {
Store.messager.warn(Store.MSG.FRS001_21);
return false;
}
return this.super('beforeAdd');
}
UserBiz.prototype.beforeEdit = function() {
var self = this;
var currentRow = self.dsMaster.currentRow;
if (currentRow === null)
return false;
var userTypeCur = currentRow['UserType'];
var userOrgIdCur = currentRow['RightCtrlOrgCode'];
if (userType === '2') {
Store.messager.warn(Store.MSG.FRS001_22);
return false;
}
if (userTypeCur === '0') {
Store.messager.warn(Store.MSG.FRS001_23);
return false;
}
if (userType === '1' && userOrgIdCur !== userOrgCode) {
Store.messager.warn(Store.MSG.FRS001_24);
return false;
}
return this.super('beforeEdit');
}
UserBiz.prototype.beforeDelete = function() {
var self = this;
var currentRow = self.dsMaster.currentRow;
if (currentRow === null)
return false;
var userCode = currentRow['UserCode'];
var userTypeCur = currentRow['UserType'];
var isActivation = currentRow['IsActivation'];
var userOrgIdCur = currentRow['RightCtrlOrgCode'];
if (userType === '2') {
Store.messager.warn(Store.MSG.FRS001_25);
return false;
}
if (userTypeCur === '0') {
Store.messager.warn(Store.MSG.FRS001_26);
return false;
}
if (userCode === Store.logOn.userCode) {
Store.messager.warn(Store.MSG.FRS001_27);
return false;
}
if (isActivation === '1') {
Store.messager.warn(Store.MSG.FRS001_28);
return false;
}
if (userType === '1' && userOrgIdCur !== userOrgCode) {
Store.messager.warn(Store.MSG.FRS001_29);
return false;
}
return this.super('beforeDelete');
}
UserBiz.prototype.beforeSave = function() {
var self = this;
self.setServerBiz('userSavePlugin');
var currentRow = self.dsMaster.currentRow;
if (currentRow === null) return false;
currentRow.setColumnValue('IsClear', '1');
var curUserID = currentRow['UserID'];
var curUserCode = currentRow['UserCode'];
//循环为用户角色明细表赋值
for (var j = 0; j < self.dsDetail1.rows.length; j++) {
var _nwRow = self.dsDetail1.rows[j];
_nwRow.setColumnValue("UserCode", curUserCode);
}
var afterSavePro = self.getDataSrc("sFrs_User_AfterSave");
afterSavePro.getColumn('ps_KeyValue').paraValue = currentRow["UserID"];
afterSavePro.getColumn('ps_UserId').paraValue = '';
afterSavePro.getColumn('ps_UserCode').paraValue = '';
afterSavePro.getColumn('ps_UserName').paraValue = '';
afterSavePro.getColumn('ps_OrgId').paraValue = '';
afterSavePro.getColumn('ps_OrgCode').paraValue = '';
afterSavePro.getColumn('ps_OrgName').paraValue = '';
self.dsMaster.afterSaveProc = afterSavePro;
return this.super('beforeSave');
}
UserBiz.prototype.getOpEnabled = function(opCode) {
var self = this;
// 仅在新增和编辑状态下可勾选
if (self.getState() !== 'add' && self.getState() !== 'edit') {
$('.pageuser-tabitem-full .datalist input[type="checkbox"]').attr('disabled', true)
}
if (self.dsMaster !== null) {
var currentRow = self.dsMaster.currentRow;
switch (opCode) {
case 'edit':
case 'delete':
if (currentRow === null) {
return false;
}
break;
case 'cus01':
case 'cus02':
if (currentRow === null || self.getState() === 'add' || self.getState() === 'edit') {
return false;
}
break;
case 'cus03':
if (currentRow === null || self.getState() === 'add' || self.getState() === 'edit') {
return false;
}
var isEnable = currentRow['IsEnable'];
if (isEnable === '1') {
self.view.vm.toolbar_main.vmodel.$setText(opCode, Store.MSG.FRS001_30);
} else {
self.view.vm.toolbar_main.vmodel.$setText(opCode, Store.MSG.FRS001_31);
}
break;
case 'cus04':
if (currentRow === null || self.getState() === 'add' || self.getState() === 'edit') {
return false;
}
break;
case 'cus05':
if (currentRow === null || self.getState() !== 'edit' && self.getState() !== 'add') {
return false;
}
break;
case 'cus06':
if (currentRow === null || self.getState() !== 'edit' && self.getState() !== 'add') {
return false;
}
break;
}
}
return this.super('getOpEnabled', opCode);
};
UserBiz.prototype.afterAdd = function() {
$('.pageuser-tabitem-full .datalist input[type="checkbox"]').attr('disabled', false)
this.curState = 'add';
var self = this;
this.super('afterAdd');
var currentRow = self.dsMaster.currentRow;
if (currentRow === null) return false;
if (userType === '1') {
currentRow.setColumnText('RightCtrlOrgCode', Store.logOn.rightCtrlOrgCode);
this.view.setEditLimit(self.dsMaster, 'UserType', false);
this.view.setEditLimit(self.dsMaster, 'RightCtrlOrgCode', false);
}
currentRow.setColumnValue('IsClear', '1');
var curUserID = currentRow['UserID'];
var curUserCode = currentRow['UserCode'];
if (curUserID === '*') {
// TODO 为UserID进行赋值
currentRow.setColumnValue('UserID', this.super('generateUUID'));
}
currentRow.setColumnValue('PasswdOri', '0');
};
UserBiz.prototype.afterEdit = function() {
$('.pageuser-tabitem-full .datalist input[type="checkbox"]').attr('disabled', false)
this.curState = 'edit';
this.super('afterEdit');
var self = this;
if (userType === '1') {
this.view.setEditLimit(self.dsMaster, 'UserType', false);
this.view.setEditLimit(self.dsMaster, 'RightCtrlOrgCode', false);
}
this.view.setEditLimit(self.dsMaster, 'UserCode', false);
}
return UserBiz;
})