setting.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. 'use strict';
  2. /**
  3. * 项目信息js
  4. *
  5. * @author EllisRan.
  6. * @date 2019/3/19
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. // 启用和停用账号
  11. $('.account-switch-btn').on('click', function () {
  12. const data = {
  13. enable: $(this).hasClass('btn-outline-success') ? 1 : 0,
  14. id: $(this).data('account'),
  15. };
  16. postData('/setting/user/switch', data, function () {
  17. window.location.href = '/setting/user';
  18. });
  19. });
  20. // 编辑账号
  21. $('a[data-target="#edit-user"]').on('click', function () {
  22. const account = $(this).data('account');
  23. $('#edit-user input[name="account"]').val(account.account);
  24. $('#edit-user input[name="name"]').val(account.name);
  25. $('#edit-user select[name="company"]').val(account.company);
  26. $('#edit-user input[name="role"]').val(account.role);
  27. $('#edit-user input[name="mobile"]').val(account.mobile);
  28. $('#edit-user input[name="telephone"]').val(account.telephone);
  29. $('#edit-user input[name="id"]').val(account.id);
  30. $('#edit-user input[name="account_group"]').val(account.account_group);
  31. $('#edit-user input[class="account-check"]').val(account.account);
  32. $('#edit-user input[data-mobile="auth-mobile"]').val(account.auth_mobile);
  33. $('#edit-user input[name="mobile"]').attr('readOnly', account.bind === 1);
  34. if (account.bind === 1) {
  35. $('#edit-user input[name="mobile"]').siblings('small').show();
  36. } else {
  37. $('#edit-user input[name="mobile"]').siblings('small').hide();
  38. }
  39. $('#edit-password input[name="account"]').val(account.account);
  40. $('#edit-password input[class="account-check"]').val(account.account);
  41. $('#edit-password input[name="id"]').val(account.id);
  42. $('#edit-password input[name="reset_password"]').val('');
  43. });
  44. // 选择单位自动配置账号组
  45. $('select[name="company"]').change(function () {
  46. const company = $(this).val();
  47. const oneUnit = _.find(unitList, { name: company });
  48. $(this).siblings('input[name="account_group"]').val(oneUnit ? oneUnit.type : 7);
  49. });
  50. // 分配随机密码
  51. $("#rand-password").click(function() {
  52. const password = randPassword();
  53. $(this).parent().parent().find('input').val(password);
  54. });
  55. // 分配随机密码
  56. $("#rand-password2").click(function() {
  57. const password = randPassword();
  58. $(this).parent().parent().find('input').val(password);
  59. });
  60. // 重置密码
  61. let isChange = false;
  62. $("#reset-password-btn").click(function() {
  63. try {
  64. if (isChange) {
  65. throw '稍后再操作';
  66. }
  67. const resetPassword = $("#reset-password").val();
  68. const id = $("#user-id").val();
  69. if (resetPassword.length < 6) {
  70. throw '密码长度不能小于6';
  71. }
  72. if (!/^[0-9a-zA-Z*~!@&%$^\\(\\)#_\[\]\-\+={}|?'":,<>.`]+$/.test(resetPassword)) {
  73. throw '密码只支持英文数字及符号';
  74. }
  75. // 判断新密码的强度
  76. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  77. if (!reg.test(resetPassword)) {
  78. throw '请设置至少包含数字和字母的密码';
  79. }
  80. const btn = $(this);
  81. $.ajax({
  82. url: '/setting/user/reset/password',
  83. type: 'post',
  84. data: { id: id, reset_password: resetPassword },
  85. dataType: 'json',
  86. error: function() {
  87. isChange = false;
  88. btn.html('重置密码');
  89. throw '网络错误!';
  90. },
  91. beforeSend: function(xhr) {
  92. let csrfToken = Cookies.get('csrfToken_j');
  93. xhr.setRequestHeader('x-csrf-token', csrfToken);
  94. isChange = true;
  95. btn.html('<i class="fa fa-spinner fa-pulse"></i>');
  96. },
  97. success: function(response) {
  98. isChange = false;
  99. btn.html('重置密码');
  100. if (response.err !== 0) {
  101. throw response.msg;
  102. }
  103. $("#reset-password").val('');
  104. toastr.success('重置成功');
  105. }
  106. });
  107. } catch (error) {
  108. toastr.error(error);
  109. console.log(error);
  110. }
  111. });
  112. // 账号查重
  113. $('input[name="account"]').on('blur', function () {
  114. const self = $(this);
  115. if (self.val() !== self.siblings('input').val()) {
  116. const data = {account: $(this).val()};
  117. postData('/setting/user/exist', data, function (data) {
  118. if (data === null) {
  119. self.removeClass('is-invalid');
  120. } else {
  121. self.addClass('is-invalid');
  122. }
  123. })
  124. } else {
  125. self.removeClass('is-invalid');
  126. }
  127. });
  128. // 选中创建标段才可以选择协作办公
  129. $('a[aria-controls="edit-user2"]').on('click', function () {
  130. $('#edit-user2 input:radio').prop('checked', false);
  131. $('#edit-user2 input:checkbox').prop('checked', false);
  132. $('#sign_permission').hide();
  133. const account = $(this).data('account');
  134. $('#edit-user2 input[name="id"]').val(account.id);
  135. $('#edit-user2 input[name="unit_sign_path"]').val(account.unit_sign_path);
  136. // 权限赋值
  137. if (account.permission !== '') {
  138. const permission = JSON.parse(account.permission);
  139. for (const pm in permission) {
  140. if (pm === 'tender' && permission[pm].indexOf('1') !== -1) {
  141. $('#edit-user2 input[name="cooperation"]').attr('disabled', false);
  142. } else {
  143. $('#edit-user2 input[name="cooperation"]').attr('disabled', true);
  144. }
  145. if (pm === 'tender' && permission[pm].indexOf('5') !== -1) {
  146. $('#edit-user2 input:checkbox[id="change_1"]').prop('checked', true);
  147. }
  148. if (pm === 'tender' && permission[pm].indexOf('4') !== -1) {
  149. $('#edit-user2 input:checkbox[id="material_1"]').prop('checked', true);
  150. }
  151. if (allPermission[pm].type === 'checkbox') {
  152. for (const index of permission[pm]) {
  153. $('#edit-user2 input:checkbox[id="' + pm + '_' + index + '"]').prop('checked', true);
  154. }
  155. } else if (allPermission[pm].type === 'radio') {
  156. $('#edit-user2 input:radio[id="' + pm + '_' + permission[pm] + '"]').prop('checked', true);
  157. }
  158. if (pm === 'other' && permission[pm].indexOf('1') !== -1) {
  159. $('#sign_permission').show();
  160. }
  161. }
  162. }
  163. // 协作赋值
  164. $('#edit-user2 input:radio[name="cooperation"][value="' + account.cooperation + '"]').prop('checked', true);
  165. // 微信通知赋值
  166. if (account.notice_again) {
  167. const noticeAgain = JSON.parse(account.notice_again);
  168. $('#again_all').prop('checked', noticeAgain.checked);
  169. for (const sp in noticeAgainConst.sp) {
  170. $('#again_' + sp).prop('checked', noticeAgain.sp[sp] !== undefined ? noticeAgain.sp[sp] : false);
  171. }
  172. }
  173. });
  174. // 选择创建标段功能后可选协作办公
  175. $('#edit-user2 input:checkbox').click(function () {
  176. if ($(this).attr('id') === 'tender_1') {
  177. if ($(this).is(':checked')) {
  178. $('#edit-user2 input[name="cooperation"]').attr('disabled', false);
  179. } else {
  180. $('#edit-user2 input[name="cooperation"]').attr('disabled', true);
  181. }
  182. }
  183. if ($(this).attr('id') === 'other_1') {
  184. if ($(this).is(':checked')) {
  185. $('#sign_permission').show();
  186. $('#sign_permission').click();
  187. } else {
  188. $('#sign_permission').hide();
  189. }
  190. }
  191. });
  192. $('#sign_permission').on('click', function () {
  193. const uid = $('#edit-user2 input[name="id"]').val();
  194. if (!uid) {
  195. toastr.error('请先选择用户');
  196. return;
  197. }
  198. const user = _.find(accountData, { id: parseInt(uid) });
  199. if (!user) {
  200. toastr.error('用户不存在');
  201. return;
  202. }
  203. let html = '';
  204. if (user.company) {
  205. const unit = _.find(unitList, { name: user.company });
  206. const unit_sign_path = $('#edit-user2 input[name="unit_sign_path"]').val();
  207. if (unit) {
  208. const paths = unit.sign_path ? unit.sign_path.split('&%&') : [];
  209. if (paths.length > 0) {
  210. console.log(paths);
  211. for (const sp of paths) {
  212. const checked = unit_sign_path && unit_sign_path.indexOf(sp) !== -1 ? 'checked' : '';
  213. html += '<div class="col-3 text-center my-2"><img src="'+ fujianOssPath + sp +'" width="120">' +
  214. '<div class="w-100 mt-2"><input type="checkbox" name="signpath[]" '+ (checked ? 'checked' : '') +' data-path="' + sp + '" />' +
  215. '</div></div>';
  216. }
  217. }
  218. }
  219. }
  220. $('#unit-sign').html(html);
  221. $('#sign_permission_modal').modal('show');
  222. });
  223. $('#set_unit_sign').on('click', function () {
  224. $('#sign_permission_modal').modal('hide');
  225. const uid = $('#edit-user2 input[name="id"]').val();
  226. const signPaths = [];
  227. $('#unit-sign input[name="signpath[]"]:checked').each(function () {
  228. signPaths.push($(this).data('path'));
  229. });
  230. $('#edit-user2 input[name="unit_sign_path"]').val(signPaths.join('&%&'));
  231. });
  232. // 解绑第三方平台
  233. $('.unlink-user').on('click', function () {
  234. const id = $(this).data('account');
  235. const accountData = _.find(accountList, { id });
  236. console.log(accountData);
  237. $('#bind_account').text(accountData.name + ' ' + accountData.mobile);
  238. $('#account_id').val(id);
  239. })
  240. // 设置显示默认
  241. $('body').on('click', '#set-default', function () {
  242. const attid = $(this).data('attid');
  243. const data = {id: attid};
  244. postData('/setting/show/update', data, function (result) {
  245. let html = ''
  246. result.forEach((item, idx) => {
  247. html += `<li class="list-group-item">${item.label_name}`
  248. html+= item.is_default ? `<span class="pull-right">默认</span></li>`:`<a href="javascript:void(0)" id="set-default" class="btn btn-primary btn-sm pull-right" data-attid="${idx}">设为默认</a></li>`
  249. })
  250. // <li class="list-group-item">
  251. // 标段列表<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>
  252. // </li>
  253. // <li class="list-group-item">金额概况<span class="pull-right">默认</span></li>
  254. // <li class="list-group-item">
  255. // 计量进度<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>
  256. // </li>
  257. $('#tenderList').empty()
  258. $('#tenderList').append(html)
  259. const item = result.find((i, idx) => idx=== attid)
  260. $('#nav_tender').attr('href', item.path)
  261. });
  262. });
  263. // 设置页显示数目
  264. $('.nav-tabs .nav-link').each(function () {
  265. const pageSize = getLocalCache('account-pageSize') ? getLocalCache('account-pageSize') : '';
  266. if (getLocalCache('account-pageSize') && $(this).attr('href').indexOf('pageSize') === -1 && $(this).attr('href').indexOf('unit') === -1) {
  267. $(this).attr('href', $(this).attr('href') + '?pageSize=' + getLocalCache('account-pageSize'));
  268. }
  269. });
  270. // 设置页显示数目
  271. $('#user-list .list-group-item').each(function (k,v) {
  272. const pageSize = getLocalCache('account-pageSize') ? getLocalCache('account-pageSize') : '';
  273. if (pageSize) {
  274. $(this).attr('href', $(this).attr('href') + '&pageSize=' + pageSize);
  275. }
  276. })
  277. // 参建单位页切换单位右侧显示
  278. $('body').on('click', '#unit_list tr', function () {
  279. const id = parseInt($(this).data('id'));
  280. $(this).siblings('tr').removeClass('table-warning');
  281. $(this).addClass('table-warning');
  282. setUnitRightHtml(id);
  283. });
  284. // 参建单位编辑
  285. // 回车提交
  286. $('#one_unit input').on('keypress', function () {
  287. if(window.event.keyCode === 13) {
  288. $(this).blur();
  289. }
  290. });
  291. $('#one_unit input').blur(function () {
  292. const val_name = $(this).data('name');
  293. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  294. if (!oneUnit) {
  295. toastr.error('所选单位有误,请重新选择');
  296. return false;
  297. }
  298. switch(val_name) {
  299. case 'name':
  300. if(val && val.length > 100) {
  301. toastr.error('单位名称超过100个字,请缩减名称');
  302. $(this).val(oneUnit[val_name]);
  303. return false;
  304. }
  305. const tongming = _.find(unitList, { name: val });
  306. if (tongming && tongming.id !== oneUnit.id) {
  307. toastr.error('单位名称不能重复');
  308. $(this).val(oneUnit[val_name]);
  309. return false;
  310. }
  311. break;
  312. default:
  313. if(val && val.length > 255) {
  314. toastr.error('超出字段范围,请缩减');
  315. $(this).val(oneUnit[val_name]);
  316. return false;
  317. }
  318. break;
  319. }
  320. if(oneUnit[val_name] !== val) {
  321. const _self = $(this);
  322. postData('/setting/user/unit/save', { type: 'update', id: oneUnit.id, val_name, val}, function (result) {
  323. oneUnit[val_name] = val;
  324. _self.val(oneUnit[val_name]);
  325. if (val_name === 'name') {
  326. oneUnit.account_num = result.account_num;
  327. $('#unit_list tr[class="table-warning"]').find('a').text(oneUnit[val_name]);
  328. $('#unit_list tr[class="table-warning"]').children('td').eq(2).text(result.account_num);
  329. }
  330. }, function () {
  331. _self.val(oneUnit[val_name]);
  332. })
  333. } else {
  334. $(this).val(oneUnit[val_name]);
  335. }
  336. });
  337. $('#unit_user_permission').change(function () {
  338. const val_name = 'sign_permission';
  339. let val = $(this).is(':checked') ? 1 : 0;
  340. if (!oneUnit) {
  341. toastr.error('所选单位有误,请重新选择');
  342. return false;
  343. }
  344. if(oneUnit[val_name] !== val) {
  345. postData('/setting/user/unit/save', {type: 'update', id: oneUnit.id, val_name, val}, function (result) {
  346. oneUnit[val_name] = val;
  347. });
  348. }
  349. });
  350. $('#one_unit textarea').blur(function () {
  351. const val_name = $(this).data('name');
  352. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  353. if (!oneUnit) {
  354. toastr.error('所选单位有误,请重新选择');
  355. return false;
  356. }
  357. if(oneUnit[val_name] !== val) {
  358. const _self = $(this);
  359. postData('/setting/user/unit/save', { type: 'update', id: oneUnit.id, val_name, val}, function (result) {
  360. oneUnit[val_name] = val;
  361. _self.val(oneUnit[val_name]);
  362. $('#unit_list tr[class="table-warning"]').children('td').eq(4).text(oneUnit[val_name]);
  363. }, function () {
  364. _self.val(oneUnit[val_name]);
  365. })
  366. } else {
  367. $(this).val(oneUnit[val_name]);
  368. }
  369. });
  370. $('#one_unit select').change(function () {
  371. const val_name = $(this).attr('data-name');
  372. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  373. if (!oneUnit) {
  374. toastr.error('所选单位有误,请重新选择');
  375. return false;
  376. }
  377. if(oneUnit[val_name] !== val) {
  378. const _self = $(this);
  379. postData('/setting/user/unit/save', { type: 'update', id: oneUnit.id, name: oneUnit.name, val_name, val}, function (result) {
  380. oneUnit[val_name] = val;
  381. _self.val(oneUnit[val_name]);
  382. $('#unit_list tr[class="table-warning"]').children('td').eq(3).text(accountGroup[parseInt(oneUnit[val_name])]);
  383. }, function () {
  384. _self.val(oneUnit[val_name]);
  385. })
  386. } else {
  387. $(this).val(oneUnit[val_name]);
  388. }
  389. });
  390. // 删除单位弹窗
  391. $('#del-modal-btn').click(function () {
  392. if (!oneUnit) {
  393. toastr.error('所选单位有误,请重新选择');
  394. return false;
  395. }
  396. if (oneUnit.account_num === 0) {
  397. $('.del-btn').show();
  398. $('.not-del-btn').hide();
  399. } else {
  400. $('.del-btn').hide();
  401. $('.not-del-btn').show();
  402. }
  403. });
  404. $('#mseal').on('shown.bs.modal', function () {
  405. if (!oneUnit) {
  406. toastr.error('所选单位有误,请重新选择');
  407. return false;
  408. }
  409. makeManageSignHtml(oneUnit.sign_path);
  410. });
  411. // 删除单位
  412. $('#delete-unit').click(function () {
  413. if (!oneUnit) {
  414. toastr.error('所选单位有误,请重新选择');
  415. return false;
  416. }
  417. postData('/setting/user/unit/save', { type: 'delete', name: oneUnit.name, id: oneUnit.id }, function (result) {
  418. window.location.href = '/setting/user/unit';
  419. })
  420. });
  421. // 上传签章
  422. $('#sign-upload').change(function () {
  423. if (!oneUnit) {
  424. toastr.error('所选单位有误,请重新选择');
  425. return false;
  426. }
  427. const files = Array.from(this.files)
  428. const valiData = files.map(v => {
  429. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  430. return {
  431. size: v.size,
  432. ext
  433. }
  434. });
  435. if (validateFiles(valiData)) {
  436. if (files.length) {
  437. const formData = new FormData();
  438. formData.append('id', oneUnit.id);
  439. files.forEach(file => {
  440. formData.append('name', file.name);
  441. formData.append('size', file.size);
  442. formData.append('file', file);
  443. });
  444. postDataWithFile('/setting/user/unit/upload', formData, function (result) {
  445. oneUnit.sign_path = result.sign_path;
  446. makeSignHtml(oneUnit.sign_path);
  447. $('#sign-upload').val('');
  448. toastr.success('上传成功');
  449. });
  450. }
  451. }
  452. });
  453. $('#manage-sign-upload').change(function () {
  454. if (!oneUnit) {
  455. toastr.error('所选单位有误,请重新选择');
  456. return false;
  457. }
  458. const files = Array.from(this.files)
  459. const valiData = files.map(v => {
  460. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  461. return {
  462. size: v.size,
  463. ext
  464. }
  465. });
  466. if (validateFiles(valiData)) {
  467. if (files.length) {
  468. const formData = new FormData();
  469. formData.append('id', oneUnit.id);
  470. files.forEach(file => {
  471. formData.append('name', file.name);
  472. formData.append('size', file.size);
  473. formData.append('file', file);
  474. });
  475. postDataWithFile('/setting/user/unit/upload', formData, function (result) {
  476. oneUnit.sign_path = result.sign_path;
  477. makeManageSignHtml(oneUnit.sign_path);
  478. makeSignHtml(oneUnit.sign_path);
  479. $('#manage-sign-upload').val('');
  480. toastr.success('上传成功');
  481. });
  482. }
  483. }
  484. });
  485. // 移除签章
  486. $('body').on('click', '#manage-unit-sign .delete-sign', function () {
  487. if (!oneUnit) {
  488. toastr.error('所选单位有误,请重新选择');
  489. return false;
  490. }
  491. const delPath = $(this).attr('data-path');
  492. if (!delPath) {
  493. toastr.error('所选签章有误,请重新选择');
  494. return false;
  495. }
  496. postData('/setting/user/unit/save', { type: 'del-sign', id: oneUnit.id, path: delPath }, function (result) {
  497. oneUnit.sign_path = result;
  498. makeManageSignHtml(oneUnit.sign_path);
  499. makeSignHtml(oneUnit.sign_path);
  500. toastr.warning('已移除');
  501. $('#delete-sign').hide();
  502. })
  503. });
  504. // 导入账号功能
  505. let importFile = null;
  506. $('#upload-xls-file').change(function () {
  507. const file = this.files[0];
  508. importFile = file;
  509. });
  510. $('#import-bills-btn').click(function() {
  511. if (!importFile) {
  512. toastr.error('请选择excel文件再确定');
  513. return;
  514. }
  515. const ext = importFile.name.toLowerCase().split('.').splice(-1)[0];
  516. const imgStr = /(xls|xlsx|XLS|XLSX)$/;
  517. if (!imgStr.test(ext)) {
  518. toastr.error('请导入正确格式的excel文件。');
  519. return
  520. }
  521. const fileReader = new FileReader();
  522. fileReader.onload = async function(ev) {
  523. try{
  524. const data = ev.target.result;
  525. const tree = [];
  526. const includeSpec = $('#xls-spec').is(':checked');
  527. if (/(xls|xlsx|XLS|XLSX)$/.test(ext)) {
  528. const workbook = XLSX.read(data, {type: 'binary'}); // 以二进制流方式读取得到整份excel表格对象
  529. const jsonData = transExcel(XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { defval: null }));
  530. console.log(jsonData);
  531. // 判断新密码的强度
  532. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  533. for (const j of jsonData) {
  534. if (j.account === undefined || j.account === null || j.password === undefined || j.password === null ||
  535. j.name === undefined || j.name === null || j.company === undefined || j.company === null ||
  536. j.role === undefined || j.role === null || j.mobile === undefined || j.telephone === undefined) {
  537. continue;
  538. }
  539. if (!reg.test(j.password)) {
  540. continue;
  541. }
  542. tree.push(j);
  543. // if (_.findIndex(tree, function (o) { return o.account === j.account; }) === -1) {
  544. // tree.push(j);
  545. // }
  546. }
  547. }
  548. console.log(tree);
  549. if (tree.length === 0) {
  550. toastr.error('导入数据为空,请检查excel是否符合模版要求。');
  551. return
  552. }
  553. postData('/setting/user/unit/save', { type: 'import-users', users: tree }, function (result) {
  554. if (result.insertNum > 0) {
  555. toastr.success('成功导入了' + result.insertNum + '个账号');
  556. if (result.overMax) {
  557. toastr.warning('添加账号个数受限,部分账号无法导入,请去后台开放限制。');
  558. }
  559. setTimeout(function () {
  560. window.location.reload();
  561. }, 1500);
  562. } else if (result.insertNum === 0 && !result.overMax) {
  563. toastr.error('未能导入任何账号,请检查账号、公司是否已存在或excel是否符合模版要求。');
  564. } else if (result.insertNum === 0 && result.overMax) {
  565. toastr.warning('添加账号个数受限,账号无法导入,请去后台开放限制。');
  566. }
  567. })
  568. } catch (error) {
  569. console.log(error);
  570. toastr.error(error);
  571. return
  572. }
  573. };
  574. // 以二进制方式打开文件
  575. fileReader.readAsBinaryString(importFile);
  576. $('#upload-xls-file').val('');
  577. importFile = null;
  578. });
  579. function transExcel(results) {
  580. const mapInfo = {
  581. '登录账号': 'account',
  582. '登录密码': 'password',
  583. '姓名': 'name',
  584. '单位名称': 'company',
  585. '职位': 'role',
  586. '手机': 'mobile',
  587. '电话': 'telephone',
  588. };
  589. return results.map(zhObj => {
  590. const enObj = {}
  591. const zhKeys = Object.keys(zhObj);
  592. zhKeys.forEach(zhKey => {
  593. const enKey = mapInfo[zhKey];
  594. enObj[enKey] = zhObj[zhKey] && _.isString(zhObj[zhKey]) ? _.trim(zhObj[zhKey]) : zhObj[zhKey];
  595. });
  596. return enObj
  597. })
  598. }
  599. });
  600. function checkPasswordForm() {
  601. try {
  602. if ($('#edit-password input[name="account"]').val() == '' || $('#edit-password input[name="account"]').hasClass('is-invalid')) {
  603. throw '账号不能为空或已存在';
  604. }
  605. const resetPassword = $('#edit-password input[name="reset_password"]').val();
  606. if (resetPassword.length < 6) {
  607. throw '密码长度不能小于6';
  608. }
  609. if (!/^[0-9a-zA-Z*~!@&%$^\\(\\)#_\[\]\-\+={}|?'":,<>.`]+$/.test(resetPassword)) {
  610. throw '密码只支持英文数字及符号';
  611. }
  612. // 判断新密码的强度
  613. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  614. if (!reg.test(resetPassword)) {
  615. throw '请设置至少包含数字和字母的密码';
  616. }
  617. } catch (err) {
  618. toastr.error(err);
  619. return false;
  620. }
  621. }
  622. function makeManageSignHtml(signPath) {
  623. const paths = signPath ? signPath.split('&%&') : [];
  624. let html = '';
  625. if (paths.length > 0) {
  626. for (const sp of paths) {
  627. html += '<div class="col-3 text-center my-2"><img src="'+ fujianOssPath + sp +'" width="120"><div class="w-100"><button class="btn btn-sm btn-outline-danger delete-sign" data-path="' + sp + '">移除</button></div></div>';
  628. }
  629. }
  630. $('#manage-unit-sign').html(html);
  631. }
  632. function makeSignHtml(signPath) {
  633. const paths = signPath ? signPath.split('&%&') : [];
  634. let html = '';
  635. if (paths.length > 0) {
  636. for (const sp of paths.slice(0, 5)) {
  637. html += '<img src="' + fujianOssPath + sp + '" width="120" class="mr-1">';
  638. }
  639. }
  640. $('#sign-show').html(html);
  641. }
  642. function setUnitRightHtml(id) {
  643. const one = _.find(unitList, { id });
  644. if (one) {
  645. $('#unit_name').val(one.name);
  646. $('#unit_corporation').val(one.corporation);
  647. $('#unit_credit_code').val(one.credit_code);
  648. $('#unit_tel').val(one.tel);
  649. $('#unit_website').val(one.website);
  650. $('#unit_region').val(one.region);
  651. $('#unit_address').val(one.address);
  652. $('#unit_basic').val(one.basic);
  653. $('#unit_type').val(one.type);
  654. if(one.sign_path) {
  655. makeSignHtml(one.sign_path);
  656. // $('#upload-sign').hide();
  657. } else {
  658. $('#sign-show').html('');
  659. // $('#upload-sign').show();
  660. }
  661. oneUnit = one;
  662. $('#add_user_company').val(one.name);
  663. $('#unit_user_permission').prop('checked', !!oneUnit.sign_permission);
  664. }
  665. }
  666. /**
  667. * 表单检测
  668. */
  669. function checkUserForm(status) {
  670. try {
  671. if (status === 'add') {
  672. if ($('#add-user input[name="account_group"]').val() == 0) {
  673. throw '请选择账号组';
  674. }
  675. if ($('#add-user input[name="account"]').val() == '' || $('#add-user input[name="account"]').hasClass('is-invalid')) {
  676. throw '账号不能为空或已存在';
  677. }
  678. if ($('#add-user input[name="password"]').val() == '' || $('#add-user input[name="password"]').val().length < 6) {
  679. throw '密码不能为空或不能小于6位';
  680. }
  681. if (!/^[0-9a-zA-Z*~!@&%$^\\(\\)#_\[\]\-\+={}|?'":,<>.`]+$/.test($('#add-user input[name="password"]').val())) {
  682. throw '密码只支持英文数字及符号';
  683. }
  684. // 判断新密码的强度
  685. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  686. if (!reg.test($('#add-user input[name="password"]').val())) {
  687. throw '请设置至少包含数字和字母的密码';
  688. }
  689. if ($('#add-user input[name="name"]').val() == '') {
  690. throw '姓名不能为空';
  691. }
  692. if (_.findIndex(unitList, { name: $('#add-user select[name="company"]').val() }) === -1) {
  693. throw '请选择单位名称';
  694. }
  695. if ($('#add-user input[name="role"]').val() == '') {
  696. throw '职位名称不能为空';
  697. }
  698. $('#add-user input[name="account"]').val(trimInvalidChar($('#add-user input[name="account"]').val()));
  699. $('#add-user input[name="name"]').val(trimInvalidChar($('#add-user input[name="name"]').val()));
  700. // $('#add-user input[name="company"]').val(trimInvalidChar($('#add-user input[name="company"]').val()));
  701. $('#add-user input[name="role"]').val(trimInvalidChar($('#add-user input[name="role"]').val()));
  702. $('#add-user input[name="telephone"]').val(trimInvalidChar($('#add-user input[name="telephone"]').val()));
  703. } else {
  704. if ($('#edit-user input[name="account_group"]').val() == 0) {
  705. throw '请选择账号组';
  706. }
  707. if ($('#edit-user input[name="account"]').val() == '' || $('#add-user input[name="account"]').hasClass('is-invalid')) {
  708. throw '账号不能为空或已存在';
  709. }
  710. if ($('#edit-user input[name="name"]').val() == '') {
  711. throw '姓名不能为空';
  712. }
  713. if (_.findIndex(unitList, { name: $('#edit-user select[name="company"]').val() }) === -1) {
  714. throw '请选择单位名称';
  715. }
  716. if ($('#edit-user input[name="role"]').val() == '') {
  717. throw '职位名称不能为空';
  718. }
  719. $('#edit-user input[name="account"]').val(trimInvalidChar($('#edit-user input[name="account"]').val()));
  720. $('#edit-user input[name="name"]').val(trimInvalidChar($('#edit-user input[name="name"]').val()));
  721. // $('#edit-user input[name="company"]').val(trimInvalidChar($('#edit-user input[name="company"]').val()));
  722. $('#edit-user input[name="role"]').val(trimInvalidChar($('#edit-user input[name="role"]').val()));
  723. $('#edit-user input[name="telephone"]').val(trimInvalidChar($('#edit-user input[name="telephone"]').val()));
  724. }
  725. } catch (err) {
  726. toastr.error(err);
  727. return false;
  728. }
  729. }
  730. function validateFiles(files) {
  731. if (files.length > 10) {
  732. toastr.error('至多同时上传10个文件');
  733. return false
  734. }
  735. return files.every(file => {
  736. if (file.size > 1024 * 1024 * 50) {
  737. toastr.error('文件大小限制为50MB');
  738. return false
  739. }
  740. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  741. if (!imgStr.test(file.ext)) {
  742. toastr.error('请上传正确的图片格式文件');
  743. return false
  744. }
  745. return true
  746. })
  747. }
  748. /**
  749. * 表单检测
  750. */
  751. function checkUnitForm() {
  752. try {
  753. if ($('#add-company input[name="name"]').val() == '') {
  754. throw '单位名称不能为空';
  755. }
  756. if ($('#add-company select[name="type"]').val() == 0) {
  757. throw '请选择类型';
  758. }
  759. // 检测同名
  760. if (_.findIndex(unitList, { name: $('#add-company input[name="name"]').val() }) !== -1) {
  761. throw '已存在对应的单位名称';
  762. }
  763. } catch (err) {
  764. toastr.error(err);
  765. return false;
  766. }
  767. }
  768. /**
  769. * 随机密码(必须包含数字和字母)
  770. */
  771. function randPassword() {
  772. const result = [];
  773. // 随机6-10位
  774. const length = Math.ceil(Math.random() * 2 + 6);
  775. let numberSeed = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  776. let stringSeed = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
  777. 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
  778. 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  779. const numRan = numberSeed[Math.floor((Math.random() * numberSeed.length))];
  780. const strRan = stringSeed[Math.floor((Math.random() * stringSeed.length))];
  781. const randSeed = stringSeed.concat(numberSeed);
  782. const seedLength = randSeed.length - 1;
  783. for (let i = 0; i < length; i++) {
  784. const index = Math.ceil(Math.random() * seedLength);
  785. result.push(randSeed[index]);
  786. }
  787. result.splice(Math.floor((Math.random() * result.length)), 0, numRan);
  788. result.splice(Math.floor((Math.random() * result.length)), 0, strRan);
  789. return result.join('');
  790. }