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.
194 lines
5.6 KiB
194 lines
5.6 KiB
|
|
define(function (require, exports, module) {
|
|
let Window = require('system/views/pages/window');
|
|
let tpl = require('text!./user-finance-win.tpl');
|
|
|
|
|
|
function UserDepWin(dsUserDep, userId) {
|
|
this.options = {
|
|
title: '用户财务组织',
|
|
content: tpl,
|
|
width: 600,
|
|
height: 700,
|
|
modal: true,
|
|
closed: true,
|
|
closable: true,
|
|
draggable: true,
|
|
data: null
|
|
}
|
|
|
|
this.userId = userId
|
|
this.dsUserDep = dsUserDep;
|
|
this.selectedData = {}
|
|
|
|
this.dsOrg = new DataSource({
|
|
funcCode: dsUserDep.funcCode,
|
|
funcObjCode: '5002',
|
|
isMultiPage: false
|
|
})
|
|
this.dsOrg.setServerBiz(this.dsUserDep.serverBiz)
|
|
|
|
this.dsOrgDep = new DataSource({
|
|
funcCode: dsUserDep.funcCode,
|
|
funcObjCode: '5004',
|
|
isMultiPage: false
|
|
})
|
|
|
|
this.dsOrgDep.setServerBiz(this.dsUserDep.serverBiz)
|
|
|
|
Window.call(this, this.options);
|
|
}
|
|
|
|
function getKey(r) {
|
|
return r['FOrgCode'] + '-' + r['DepCode']
|
|
}
|
|
|
|
function updateSelected(self) {
|
|
self.selectedData = _.uniq(self.dsUserDep.rows.map(r => r['OrgCode']));
|
|
}
|
|
|
|
inherits(UserDepWin, Window);
|
|
|
|
function buildTreeData(rows, self) {
|
|
let treeData = []
|
|
rows.forEach(r => {
|
|
const node = {
|
|
name: r['FOrgCode'] + '-' + r['FOrgName'],
|
|
OrgCode: r['FOrgCode'],
|
|
PreOrgCode: '*',
|
|
open: true,
|
|
checked: self.selectedData.indexOf(r['FOrgCode']) >= 0
|
|
// row: r
|
|
}
|
|
treeData.push(node);
|
|
})
|
|
|
|
return treeData
|
|
}
|
|
|
|
|
|
UserDepWin.prototype.init = function () {
|
|
let self = this;
|
|
|
|
this.dsOrg.search(() => { }, { sync: true })
|
|
|
|
updateSelected(self)
|
|
|
|
let treeOpts = {
|
|
opts: {
|
|
showLine: true,
|
|
simpleData: true,
|
|
idKey: 'OrgCode',
|
|
pIdKey: 'PreOrgCode',
|
|
rootPId: '*',
|
|
checkEnable: true,
|
|
checkOpts: {
|
|
chkboxType: { "Y": "", "N": "" }
|
|
}
|
|
},
|
|
data: buildTreeData(this.dsOrg.rows, this),
|
|
actions: {
|
|
onCheck: function (e, treeNode) {
|
|
if (self.isCheckAll()) {
|
|
self.$checkAll.checkbox('check')
|
|
} else {
|
|
self.$checkAll.checkbox('uncheck')
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
this.register('tree', 'treeOrg', treeOpts);
|
|
}
|
|
|
|
UserDepWin.prototype.open = function () {
|
|
const self = this
|
|
let params = {
|
|
uiObjCodes: '5002;5004'
|
|
}
|
|
Store.services.getUiObjSchema(params, function (isOk, data) {
|
|
if (isOk) {
|
|
self.dsOrg.initUIObj(data['5002']);
|
|
self.dsOrgDep.initUIObj(data['5004']);
|
|
Window.prototype.open.call(self);
|
|
}
|
|
});
|
|
}
|
|
|
|
UserDepWin.prototype.isCheckAll = function () {
|
|
const self = this;
|
|
if (!self.widgets['treeOrg']) { return false; }
|
|
|
|
const unCheckedNodes = self.widgets['treeOrg'].getCheckedNodes(false);
|
|
return unCheckedNodes.length === 0;
|
|
}
|
|
|
|
/**
|
|
* [执行windows窗体上自定义按钮事件]
|
|
*/
|
|
UserDepWin.prototype.customerize = function () {
|
|
let self = this;
|
|
|
|
self.$checkAll = this.getElement('.check-all').checkbox({
|
|
checked: self.isCheckAll(),
|
|
onChange(checked) {
|
|
if (self.isCheckAll() === checked) { return; }
|
|
|
|
self.widgets['treeOrg'].tree('checkAllNodes', checked);
|
|
}
|
|
})
|
|
|
|
//保存按钮事件
|
|
this.getElement('.btn-save').linkbutton({
|
|
onClick: function () {
|
|
let selectedNodes = self.widgets.treeOrg.getCheckedNodes(true);
|
|
let orgMap = {}
|
|
let userOrgMap = {}
|
|
self.dsUserDep.rows.forEach(r => {
|
|
userOrgMap[r.OrgCode] = r
|
|
})
|
|
|
|
selectedNodes.forEach(node => {
|
|
if (node.OrgCode === '*') { return; }
|
|
orgMap[node.OrgCode] = node
|
|
if (!userOrgMap[node.OrgCode]) {
|
|
let newRow = self.dsUserDep.addRow();
|
|
newRow['UserID'] = self.userId;
|
|
newRow['OrgCode'] = node.OrgCode;
|
|
newRow['OrgStyle'] = '1';
|
|
newRow['DepCode'] = '*';
|
|
}
|
|
})
|
|
|
|
for (let index = self.dsUserDep.rows.length - 1; index >= 0; index--) {
|
|
const r = self.dsUserDep.rows[index];
|
|
if (!orgMap[r.OrgCode]) {
|
|
r.delete()
|
|
}
|
|
}
|
|
|
|
self.dsUserDep.save(isOk => {
|
|
if (isOk) {
|
|
self.close()
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
//取消按钮事件,恢复到刚打开界面的初始状态
|
|
this.getElement('.btn-cancel').linkbutton({
|
|
onClick: function () {
|
|
Store.messager.confirm('取消操作无法撤回,确定?', function (confirmIsOk) {
|
|
if (confirmIsOk) {
|
|
self.dsUserDep.rejectChanges();
|
|
self.close()
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
return UserDepWin;
|
|
}) |