|
|
@@ -2,58 +2,27 @@ $(document).ready(() => {
|
|
|
autoFlashHeight();
|
|
|
// 选择账号
|
|
|
const refreshUnitUsersHtml = function () {
|
|
|
- const keyword = $('#sb-keyword').val();
|
|
|
+ const keyword = $('#sb-keyword').val().trim();
|
|
|
const html = [];
|
|
|
const select = $('#sel-batch-unit').val();
|
|
|
- const selectGroup = accountGroup.find(x => { return x.name === select; });
|
|
|
- if (selectGroup) {
|
|
|
- const filter = keyword ? selectGroup.groupList.filter(x => {
|
|
|
- return x.role.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0;
|
|
|
- }) : selectGroup.groupList;
|
|
|
- for (const u of filter) {
|
|
|
- html.push(`<tr class="text-center">`);
|
|
|
- html.push(`<td><input type="checkbox" name="sel-batch-check" id="${u.id}" unit="${selectGroup.name}" ${(u.select ? 'checked' : '')} ${u.sp_exist ? 'disabled' : ''}></td>`);
|
|
|
- html.push(`<td>${u.name}</td>`);
|
|
|
- html.push(`<td>${u.role}</td>`);
|
|
|
- html.push(`<td>${u.company}</td>`);
|
|
|
- html.push('<tr>');
|
|
|
- }
|
|
|
- }
|
|
|
- const noCompanyAccount = accountList.filter(x => {
|
|
|
- if (!x.company) return true;
|
|
|
- const unit = accountGroup.find(y => { return y.name === x.company; });
|
|
|
- if (unit) return false;
|
|
|
- return keyword ? x.role.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0 : true;
|
|
|
- });
|
|
|
- for (const u of noCompanyAccount) {
|
|
|
- html.push(`<tr class="text-center table-secondary">`);
|
|
|
- html.push(`<td><input type="checkbox" name="sel-batch-check" id="${u.id}" unit="${selectGroup.name}" ${(u.select ? 'checked' : '')} disabled></td>`);
|
|
|
- html.push(`<td>${u.name}</td>`);
|
|
|
- html.push(`<td>${u.role}</td>`);
|
|
|
- html.push(`<td>${u.company}</td>`);
|
|
|
- html.push('<tr>');
|
|
|
- }
|
|
|
- const otherCompanyAccount = accountList.filter(x => {
|
|
|
- if (!keyword) return false;
|
|
|
- if (!x.company || x.company === selectGroup.name) return false;
|
|
|
- const unit = accountGroup.find(y => { return y.name === x.company; });
|
|
|
- if (!unit) return false;
|
|
|
- return x.role.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0;
|
|
|
+ const users = accountList.filter(user => {
|
|
|
+ if (select && user.company !== select) return false;
|
|
|
+ return !keyword || (user.role || '').indexOf(keyword) >= 0 || (user.name || '').indexOf(keyword) >= 0;
|
|
|
});
|
|
|
- for (const u of otherCompanyAccount) {
|
|
|
- html.push(`<tr class="text-center table-secondary">`);
|
|
|
- html.push(`<td><input type="checkbox" name="sel-batch-check" id="${u.id}" unit="${selectGroup.name}" ${(u.select ? 'checked' : '')} disabled></td>`);
|
|
|
+ const selectableUsers = users.filter(user => !user.sp_exist);
|
|
|
+ for (const u of users) {
|
|
|
+ html.push('<tr class="text-center">');
|
|
|
+ html.push(`<td><input type="checkbox" name="sel-batch-check" id="${u.id}" ${(u.select ? 'checked' : '')} ${u.sp_exist ? 'disabled' : ''}></td>`);
|
|
|
html.push(`<td>${u.name}</td>`);
|
|
|
- html.push(`<td>${u.role}</td>`);
|
|
|
- html.push(`<td>${u.company}</td>`);
|
|
|
- html.push('<tr>');
|
|
|
+ html.push(`<td>${u.role || ''}</td>`);
|
|
|
+ html.push(`<td>${u.company || ''}</td>`);
|
|
|
+ html.push('</tr>');
|
|
|
}
|
|
|
$('#sel-batch-users').html(html.join(''));
|
|
|
+ $('#sel-batch-all').prop('checked', selectableUsers.length > 0 && selectableUsers.every(user => user.select));
|
|
|
};
|
|
|
$('#sel-batch').on('show.bs.modal', function() {
|
|
|
- accountGroup.forEach(ag => {
|
|
|
- ag.groupList.forEach(u => { u.select = false; });
|
|
|
- });
|
|
|
+ accountList.forEach(user => { user.select = false; });
|
|
|
refreshUnitUsersHtml();
|
|
|
});
|
|
|
$('#sel-batch-unit').change(function() {
|
|
|
@@ -66,26 +35,21 @@ $(document).ready(() => {
|
|
|
refreshUnitUsersHtml();
|
|
|
});
|
|
|
$('body').on('click', '[name=sel-batch-check]', function() {
|
|
|
- const select = $('#sel-batch-unit').val();
|
|
|
- const selectGroup = accountGroup.find(x => { return x.name === select; });
|
|
|
- const user = selectGroup.groupList.find(x => { return x.id === parseInt(this.getAttribute('id')); });
|
|
|
+ const user = accountList.find(user => user.id === parseInt(this.getAttribute('id')));
|
|
|
+ if (!user || user.sp_exist) return;
|
|
|
user.select = this.checked;
|
|
|
+ const checks = $('[name=sel-batch-check]:enabled');
|
|
|
+ $('#sel-batch-all').prop('checked', checks.length > 0 && checks.filter(':checked').length === checks.length);
|
|
|
});
|
|
|
$('#sel-batch-all').change(function() {
|
|
|
- const select = $('#sel-batch-unit').val();
|
|
|
- const selectGroup = accountGroup.find(x => { return x.name === select; });
|
|
|
- selectGroup.groupList.forEach(x => {
|
|
|
- x.select = x.sp_exist ? false : this.checked;
|
|
|
- });
|
|
|
+ for (const check of $('[name=sel-batch-check]:enabled')) {
|
|
|
+ const user = accountList.find(user => user.id === parseInt(check.getAttribute('id')));
|
|
|
+ if (user) user.select = this.checked;
|
|
|
+ }
|
|
|
refreshUnitUsersHtml();
|
|
|
});
|
|
|
$('#sel-batch-ok').click(() => {
|
|
|
- const select = [];
|
|
|
- for (const ag of accountGroup) {
|
|
|
- for (const u of ag.groupList) {
|
|
|
- if (u.select && !u.sp_exist) select.push(u.id);
|
|
|
- }
|
|
|
- }
|
|
|
+ const select = accountList.filter(user => user.select && !user.sp_exist).map(user => user.id);
|
|
|
postData(`/sp/${spid}/setting/user/permission/update`, { add: select }, function() {
|
|
|
window.location.reload();
|
|
|
});
|
|
|
@@ -294,4 +258,11 @@ $(document).ready(() => {
|
|
|
$('#copy-user-batch').modal('hide');
|
|
|
});
|
|
|
});
|
|
|
+ $('#sel-batch-unit').select2({
|
|
|
+ placeholder: '全部单位',
|
|
|
+ allowClear: true,
|
|
|
+ width: '300px',
|
|
|
+ dropdownParent: $('#sel-batch'),
|
|
|
+ minimumResultsForSearch: 0,
|
|
|
+ });
|
|
|
});
|