| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 | 
							- $(document).ready(() => {
 
-     autoFlashHeight();
 
-     // 选择账号
 
-     const refreshUnitUsersHtml = function () {
 
-         const keyword = $('#sb-keyword').val();
 
-         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;
 
-         });
 
-         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>`);
 
-             html.push(`<td>${u.name}</td>`);
 
-             html.push(`<td>${u.role}</td>`);
 
-             html.push(`<td>${u.company}</td>`);
 
-             html.push('<tr>');
 
-         }
 
-         $('#sel-batch-users').html(html.join(''));
 
-     };
 
-     $('#sel-batch').on('show.bs.modal', function() {
 
-         accountGroup.forEach(ag => {
 
-             ag.groupList.forEach(u => { u.select = false; });
 
-         });
 
-         refreshUnitUsersHtml();
 
-     });
 
-     $('#sel-batch-unit').change(function() {
 
-         refreshUnitUsersHtml();
 
-     });
 
-     $('#sb-search').click(function() {
 
-         refreshUnitUsersHtml();
 
-     });
 
-     $('#sb-keyword').change(function() {
 
-         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')); });
 
-         user.select = this.checked;
 
-     });
 
-     $('#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;
 
-         });
 
-         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);
 
-             }
 
-         }
 
-         postData(`/sp/${spid}/setting/user/permission/update`, { add: select }, function() {
 
-             window.location.reload();
 
-         });
 
-     });
 
-     // 移除账号
 
-     $('[name=remove-user]').click(function() {
 
-         const id = this.getAttribute('data-id');
 
-         postData(`/sp/${spid}/setting/user/permission/update`, { del: id }, function() {
 
-             window.location.reload();
 
-         });
 
-     });
 
-     $('[name=permission-check]').click(function() {
 
-         const ptype = $(this).attr('ptype');
 
-         if (ptype === 'contract') {
 
-             const pvalue = $(this).attr('pvalue');
 
-             if (this.checked) {
 
-                 if ((pvalue === '1' || pvalue === '2') && !$(this).parents('.permission-parent').find('[ptype=contract][pvalue="3"]').prop('checked') && !$(this).parents('.permission-parent').find('[ptype=contract][pvalue="4"]').prop('checked')) {
 
-                     $(this).parents('.permission-parent').find('[ptype=contract][pvalue="5"]').prop('checked', true);
 
-                 }
 
-                 if (pvalue === '3' || pvalue === '4') {
 
-                     $(this).parents('.permission-parent').find('[ptype=contract][pvalue="5"]').prop('checked', false);
 
-                 } else if (pvalue === '5') {
 
-                     $(this).parents('.permission-parent').find('[ptype=contract][pvalue="3"]').prop('checked', false);
 
-                     $(this).parents('.permission-parent').find('[ptype=contract][pvalue="4"]').prop('checked', false);
 
-                 }
 
-             } else if (!this.checked) {
 
-                 if (pvalue === '3' || pvalue === '4') {
 
-                     if (!$(this).parents('.permission-parent').find('[ptype=contract][pvalue="3"]').prop('checked') && !$(this).parents('.permission-parent').find('[ptype=contract][pvalue="4"]').prop('checked')) {
 
-                         $(this).parents('.permission-parent').find('[ptype=contract][pvalue="5"]').prop('checked', true);
 
-                     }
 
-                 }
 
-             }
 
-         } else if (ptype === 'payment') {
 
-             const pvalue = $(this).attr('pvalue');
 
-             if (this.checked && pvalue === '2') {
 
-                 $(this).parents('.permission-parent').find('[ptype=payment][pvalue="3"]').prop('checked', true);
 
-             }
 
-         }
 
-     });
 
-     $('[name=permission-check-all]').click(function() {
 
-         const ptype = $(this).attr('ptype');
 
-         const pvalue = $(this).attr('pvalue');
 
-         $(`[name=permission-check][ptype=${ptype}][pvalue=${pvalue}]`).attr("checked", this.checked);
 
-         $('#save-permission').show();
 
-     });
 
-     $('[name=set-permission]').click(function() {
 
-         const data = JSON.parse(this.getAttribute('data-account'));
 
-         const permissionCheck = $('[name="permission-check"]');
 
-         for (const pc of permissionCheck) {
 
-             const ptype = pc.getAttribute('ptype');
 
-             const pvalue = pc.getAttribute('pvalue');
 
-             const typePermission = (data[ptype + '_permission'] || '').split(',');
 
-             pc.checked = typePermission.indexOf(pvalue) >= 0;
 
-         }
 
-         $('#permission-uid').val(data.permission_id);
 
-         $('#permission').modal('show');
 
-     });
 
-     $('#permission-ok').click(function() {
 
-         const data = { id: $('#permission-uid').val() };
 
-         const updatePermission = [];
 
-         const permissionCheck = $('[name="permission-check"]');
 
-         for (const pc of permissionCheck) {
 
-             const ptype = pc.getAttribute('ptype');
 
-             const pvalue = pc.getAttribute('pvalue');
 
-             let up = updatePermission.find(x => { return x.key === ptype; });
 
-             if (!up) {
 
-                 up = { key: ptype, value: [] };
 
-                 updatePermission.push(up);
 
-             }
 
-             if (pc.checked) up.value.push(pvalue);
 
-         }
 
-         updatePermission.forEach(x => {
 
-             data[x.key + '_permission'] = x.value.join(',');
 
-         });
 
-         postData(`/sp/${spid}/setting/user/permission/update`, { update: data }, function() {
 
-             window.location.reload();
 
-         });
 
-     });
 
-     $('#filter-valid').change(function() {
 
-         const filter = this.checked;
 
-         const users = $('[name=user-permission]');
 
-         for (const user of users) {
 
-             if (filter) {
 
-                 const checked = $(':checked', user);
 
-                 if (checked.length > 0) {
 
-                     $(user).show();
 
-                 } else {
 
-                     $(user).hide();
 
-                 }
 
-             } else {
 
-                 $(user).show();
 
-             }
 
-         }
 
-     });
 
-     $('#save-permission').click(function() {
 
-         const updateData = [];
 
-         const users = $('[name=user-permission]');
 
-         for (const user of users) {
 
-             const data = { id: user.getAttribute('pid') };
 
-             const permissionKey = [], permission = {};
 
-             const check = $('[type=checkbox]', user);
 
-             for (const c of check) {
 
-                 const ptype = c.getAttribute('ptype');
 
-                 const pvalue = c.getAttribute('pvalue');
 
-                 if (permissionKey.indexOf(ptype) < 0) {
 
-                     permissionKey.push(ptype);
 
-                     permission[ptype] = [];
 
-                 }
 
-                 if (c.checked) permission[ptype].push(pvalue);
 
-             }
 
-             permissionKey.forEach(x => {
 
-                 data[x + '_permission'] = permission[x].join(',');
 
-             });
 
-             updateData.push(data);
 
-         }
 
-         postData(`/sp/${spid}/setting/user/permission/update`, { update: updateData }, function() {
 
-             window.location.reload();
 
-         })
 
-     });
 
-     $('[name=copy-permission]').click(function() {
 
-         let data = $('[name=set-permission]', $(this).parent()).attr('data-account');
 
-         $('#source-permission').val(data);
 
-         data = JSON.parse(data);
 
-         const html = [];
 
-         for (const u of subProjectAllAccountList) {
 
-             if (u.id === data.id) continue;
 
-             html.push('<tr>');
 
-             html.push(`<td class=text-center><input type="checkbox" name="copy-batch-check" id="${u.permission_id}"></td>`);
 
-             html.push(`<td>${u.name}</td>`);
 
-             html.push(`<td>${u.role}</td>`);
 
-             html.push(`<td>${u.company}</td>`);
 
-             html.push('</tr>');
 
-         }
 
-         $('#copy-batch-users').html(html.join(''));
 
-         $('#copy-permission').modal('show');
 
-     });
 
-     $('#copy-batch-all').click(function() {
 
-         for (const c of $('[name=copy-batch-check]')) {
 
-             c.checked = this.checked;
 
-         }
 
-     });
 
-     $('#copy-batch-ok').click(function() {
 
-         const source = JSON.parse($('#source-permission').val());
 
-         const updateData = [];
 
-         const batchUser = $('[name=copy-batch-check]:checked');
 
-         if (batchUser.length === 0) {
 
-             toastr.warning('未选择账号');
 
-             return;
 
-         }
 
-         for (const user of batchUser) {
 
-             const data = { id: user.getAttribute('id') };
 
-             const permissionCheck = $('[name="permission-check"]');
 
-             for (const pc of permissionCheck) {
 
-                 const ptype = pc.getAttribute('ptype');
 
-                 data[ptype + '_permission'] = source[ptype + '_permission'];
 
-             }
 
-             updateData.push(data);
 
-         }
 
-         postData(`/sp/${spid}/setting/user/permission/update`, { update: updateData }, function() {
 
-             window.location.reload();
 
-         })
 
-     });
 
-     $('#copy-user-batch').on('show.bs.modal', function() {
 
-         $('#cub-sp-all')[0].checked = false;
 
-         for (const c of $('[name=cub-sp-check]')) {
 
-             c.checked = false;
 
-         }
 
-         $('#cub-user-all')[0].checked = false;
 
-         for (const c of $('[name=cub-user-check]')) {
 
-             c.checked = false;
 
-         }
 
-     });
 
-     $('#cub-sp-all').click(function() {
 
-         for (const c of $('[name=cub-sp-check]')) {
 
-             c.checked = this.checked;
 
-         }
 
-     });
 
-     $('#cub-user-all').click(function() {
 
-         for (const c of $('[name=cub-user-check]')) {
 
-             c.checked = this.checked;
 
-         }
 
-     });
 
-     $('#copy-user-batch-ok').click(function() {
 
-         const spCheck = $('[name=cub-sp-check]:checked');
 
-         if (spCheck.length === 0) {
 
-             toastr.warning('未选择项目');
 
-             return;
 
-         }
 
-         const userCheck = $('[name=cub-user-check]:checked');
 
-         if (userCheck.length === 0) {
 
-             toastr.warning('未选择账号');
 
-             return;
 
-         }
 
-         const copyData = { spid: [], uid: [] };
 
-         for (const sp of spCheck) {
 
-             copyData.spid.push(sp.getAttribute('spid'));
 
-         }
 
-         for (const u of userCheck) {
 
-             copyData.uid.push(parseInt(u.getAttribute('uid')));
 
-         }
 
-         postData(`/sp/${spid}/setting/user/permission/update`, { copy: copyData }, function(result) {
 
-             toastr.success('设置成功');
 
-             $('#copy-user-batch').modal('hide');
 
-         });
 
-     });
 
- });
 
 
  |