setting.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. const account = $(this).data('account');
  133. $('#edit-user2 input[name="id"]').val(account.id);
  134. // 权限赋值
  135. if (account.permission !== '') {
  136. const permission = JSON.parse(account.permission);
  137. for (const pm in permission) {
  138. if (pm === 'tender' && permission[pm].indexOf('1') !== -1) {
  139. $('#edit-user2 input[name="cooperation"]').attr('disabled', false);
  140. } else {
  141. $('#edit-user2 input[name="cooperation"]').attr('disabled', true);
  142. }
  143. if (pm === 'tender' && permission[pm].indexOf('5') !== -1) {
  144. $('#edit-user2 input:checkbox[id="change_1"]').prop('checked', true);
  145. }
  146. if (pm === 'tender' && permission[pm].indexOf('4') !== -1) {
  147. $('#edit-user2 input:checkbox[id="material_1"]').prop('checked', true);
  148. }
  149. if (allPermission[pm].type === 'checkbox') {
  150. for (const index of permission[pm]) {
  151. $('#edit-user2 input:checkbox[id="' + pm + '_' + index + '"]').prop('checked', true);
  152. }
  153. } else if (allPermission[pm].type === 'radio') {
  154. $('#edit-user2 input:radio[id="' + pm + '_' + permission[pm] + '"]').prop('checked', true);
  155. }
  156. }
  157. }
  158. // 协作赋值
  159. $('#edit-user2 input:radio[name="cooperation"][value="' + account.cooperation + '"]').prop('checked', true);
  160. // 微信通知赋值
  161. if (account.notice_again) {
  162. const noticeAgain = JSON.parse(account.notice_again);
  163. $('#again_all').prop('checked', noticeAgain.checked);
  164. for (const sp in noticeAgainConst.sp) {
  165. $('#again_' + sp).prop('checked', noticeAgain.sp[sp] !== undefined ? noticeAgain.sp[sp] : false);
  166. }
  167. }
  168. });
  169. // 选择创建标段功能后可选协作办公
  170. $('#edit-user2 input:checkbox').click(function () {
  171. if ($(this).attr('id') === 'tender_1') {
  172. if ($(this).is(':checked')) {
  173. $('#edit-user2 input[name="cooperation"]').attr('disabled', false);
  174. } else {
  175. $('#edit-user2 input[name="cooperation"]').attr('disabled', true);
  176. }
  177. }
  178. });
  179. // 解绑第三方平台
  180. $('.unlink-user').on('click', function () {
  181. const id = $(this).data('account');
  182. const accountData = _.find(accountList, { id });
  183. console.log(accountData);
  184. $('#bind_account').text(accountData.name + ' ' + accountData.mobile);
  185. $('#account_id').val(id);
  186. })
  187. // 设置显示默认
  188. $('body').on('click', '#set-default', function () {
  189. const attid = $(this).data('attid');
  190. const data = {id: attid};
  191. postData('/setting/show/update', data, function (result) {
  192. let html = ''
  193. result.forEach((item, idx) => {
  194. html += `<li class="list-group-item">${item.label_name}`
  195. 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>`
  196. })
  197. // <li class="list-group-item">
  198. // 标段列表<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>
  199. // </li>
  200. // <li class="list-group-item">金额概况<span class="pull-right">默认</span></li>
  201. // <li class="list-group-item">
  202. // 计量进度<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>
  203. // </li>
  204. $('#tenderList').empty()
  205. $('#tenderList').append(html)
  206. const item = result.find((i, idx) => idx=== attid)
  207. $('#nav_tender').attr('href', item.path)
  208. });
  209. });
  210. // 设置页显示数目
  211. $('.nav-tabs .nav-link').each(function () {
  212. const pageSize = getLocalCache('account-pageSize') ? getLocalCache('account-pageSize') : '';
  213. if (getLocalCache('account-pageSize') && $(this).attr('href').indexOf('pageSize') === -1 && $(this).attr('href').indexOf('unit') === -1) {
  214. $(this).attr('href', $(this).attr('href') + '?pageSize=' + getLocalCache('account-pageSize'));
  215. }
  216. });
  217. // 设置页显示数目
  218. $('#user-list .list-group-item').each(function (k,v) {
  219. const pageSize = getLocalCache('account-pageSize') ? getLocalCache('account-pageSize') : '';
  220. if (pageSize) {
  221. $(this).attr('href', $(this).attr('href') + '&pageSize=' + pageSize);
  222. }
  223. })
  224. // 参建单位页切换单位右侧显示
  225. $('body').on('click', '#unit_list tr', function () {
  226. const id = parseInt($(this).data('id'));
  227. $(this).siblings('tr').removeClass('table-warning');
  228. $(this).addClass('table-warning');
  229. setUnitRightHtml(id);
  230. });
  231. // 参建单位编辑
  232. // 回车提交
  233. $('#one_unit input').on('keypress', function () {
  234. if(window.event.keyCode === 13) {
  235. $(this).blur();
  236. }
  237. });
  238. $('#one_unit input').blur(function () {
  239. const val_name = $(this).data('name');
  240. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  241. if (!oneUnit) {
  242. toastr.error('所选单位有误,请重新选择');
  243. return false;
  244. }
  245. switch(val_name) {
  246. case 'name':
  247. if(val && val.length > 100) {
  248. toastr.error('单位名称超过100个字,请缩减名称');
  249. $(this).val(oneUnit[val_name]);
  250. return false;
  251. }
  252. const tongming = _.find(unitList, { name: val });
  253. if (tongming && tongming.id !== oneUnit.id) {
  254. toastr.error('单位名称不能重复');
  255. $(this).val(oneUnit[val_name]);
  256. return false;
  257. }
  258. break;
  259. default:
  260. if(val && val.length > 255) {
  261. toastr.error('超出字段范围,请缩减');
  262. $(this).val(oneUnit[val_name]);
  263. return false;
  264. }
  265. break;
  266. }
  267. if(oneUnit[val_name] !== val) {
  268. const _self = $(this);
  269. postData('/setting/user/unit/save', { type: 'update', id: oneUnit.id, val_name, val}, function (result) {
  270. oneUnit[val_name] = val;
  271. _self.val(oneUnit[val_name]);
  272. if (val_name === 'name') {
  273. oneUnit.account_num = result.account_num;
  274. $('#unit_list tr[class="table-warning"]').find('a').text(oneUnit[val_name]);
  275. $('#unit_list tr[class="table-warning"]').children('td').eq(2).text(result.account_num);
  276. }
  277. }, function () {
  278. _self.val(oneUnit[val_name]);
  279. })
  280. } else {
  281. $(this).val(oneUnit[val_name]);
  282. }
  283. });
  284. $('#one_unit textarea').blur(function () {
  285. const val_name = $(this).data('name');
  286. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  287. if (!oneUnit) {
  288. toastr.error('所选单位有误,请重新选择');
  289. return false;
  290. }
  291. if(oneUnit[val_name] !== val) {
  292. const _self = $(this);
  293. postData('/setting/user/unit/save', { type: 'update', id: oneUnit.id, val_name, val}, function (result) {
  294. oneUnit[val_name] = val;
  295. _self.val(oneUnit[val_name]);
  296. $('#unit_list tr[class="table-warning"]').children('td').eq(4).text(oneUnit[val_name]);
  297. }, function () {
  298. _self.val(oneUnit[val_name]);
  299. })
  300. } else {
  301. $(this).val(oneUnit[val_name]);
  302. }
  303. });
  304. $('#one_unit select').change(function () {
  305. const val_name = $(this).attr('data-name');
  306. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  307. if (!oneUnit) {
  308. toastr.error('所选单位有误,请重新选择');
  309. return false;
  310. }
  311. if(oneUnit[val_name] !== val) {
  312. const _self = $(this);
  313. postData('/setting/user/unit/save', { type: 'update', id: oneUnit.id, name: oneUnit.name, val_name, val}, function (result) {
  314. oneUnit[val_name] = val;
  315. _self.val(oneUnit[val_name]);
  316. $('#unit_list tr[class="table-warning"]').children('td').eq(3).text(accountGroup[parseInt(oneUnit[val_name])]);
  317. }, function () {
  318. _self.val(oneUnit[val_name]);
  319. })
  320. } else {
  321. $(this).val(oneUnit[val_name]);
  322. }
  323. });
  324. // 删除单位弹窗
  325. $('#del-modal-btn').click(function () {
  326. if (!oneUnit) {
  327. toastr.error('所选单位有误,请重新选择');
  328. return false;
  329. }
  330. if (oneUnit.account_num === 0) {
  331. $('.del-btn').show();
  332. $('.not-del-btn').hide();
  333. } else {
  334. $('.del-btn').hide();
  335. $('.not-del-btn').show();
  336. }
  337. });
  338. // 删除单位
  339. $('#delete-unit').click(function () {
  340. if (!oneUnit) {
  341. toastr.error('所选单位有误,请重新选择');
  342. return false;
  343. }
  344. postData('/setting/user/unit/save', { type: 'delete', name: oneUnit.name, id: oneUnit.id }, function (result) {
  345. window.location.href = '/setting/user/unit';
  346. })
  347. });
  348. // 上传签章
  349. $('#sign-upload').change(function () {
  350. if (!oneUnit) {
  351. toastr.error('所选单位有误,请重新选择');
  352. return false;
  353. }
  354. const file = this.files[0];
  355. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  356. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  357. if (!imgStr.test(ext)) {
  358. toastr.error('请上传正确的图片格式文件');
  359. return
  360. }
  361. if ($(this).val()) {
  362. const formData = new FormData();
  363. formData.append('file', this.files[0]);
  364. formData.append('id', oneUnit.id);
  365. postDataWithFile('/setting/user/unit/upload', formData, function (result) {
  366. const html = '<img src="'+ fujianOssPath + result.sign_path +'" width="120">';
  367. $('#sign-show').html(html);
  368. $('#sign-upload').val('');
  369. oneUnit.sign_path = result.sign_path;
  370. $('#upload-sign').hide();
  371. $('#delete-sign').show();
  372. toastr.success('上传成功');
  373. });
  374. }
  375. });
  376. // 移除签章
  377. $('#delete-sign').click(function () {
  378. if (!oneUnit) {
  379. toastr.error('所选单位有误,请重新选择');
  380. return false;
  381. }
  382. postData('/setting/user/unit/save', { type: 'del-sign', id: oneUnit.id }, function (result) {
  383. $('#sign-show').html('');
  384. toastr.warning('已移除');
  385. oneUnit.sign_path = null;
  386. $('#upload-sign').show();
  387. $('#delete-sign').hide();
  388. })
  389. });
  390. // 导入账号功能
  391. let importFile = null;
  392. $('#upload-xls-file').change(function () {
  393. const file = this.files[0];
  394. importFile = file;
  395. });
  396. $('#import-bills-btn').click(function() {
  397. if (!importFile) {
  398. toastr.error('请选择excel文件再确定');
  399. return;
  400. }
  401. const ext = importFile.name.toLowerCase().split('.').splice(-1)[0];
  402. const imgStr = /(xls|xlsx|XLS|XLSX)$/;
  403. if (!imgStr.test(ext)) {
  404. toastr.error('请导入正确格式的excel文件。');
  405. return
  406. }
  407. const fileReader = new FileReader();
  408. fileReader.onload = async function(ev) {
  409. try{
  410. const data = ev.target.result;
  411. const tree = [];
  412. const includeSpec = $('#xls-spec').is(':checked');
  413. if (/(xls|xlsx|XLS|XLSX)$/.test(ext)) {
  414. const workbook = XLSX.read(data, {type: 'binary'}); // 以二进制流方式读取得到整份excel表格对象
  415. const jsonData = transExcel(XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { defval: null }));
  416. console.log(jsonData);
  417. // 判断新密码的强度
  418. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  419. for (const j of jsonData) {
  420. if (j.account === undefined || j.account === null || j.password === undefined || j.password === null ||
  421. j.name === undefined || j.name === null || j.company === undefined || j.company === null ||
  422. j.role === undefined || j.role === null || j.mobile === undefined || j.telephone === undefined) {
  423. continue;
  424. }
  425. if (!reg.test(j.password)) {
  426. continue;
  427. }
  428. tree.push(j);
  429. // if (_.findIndex(tree, function (o) { return o.account === j.account; }) === -1) {
  430. // tree.push(j);
  431. // }
  432. }
  433. }
  434. console.log(tree);
  435. if (tree.length === 0) {
  436. toastr.error('导入数据为空,请检查excel是否符合模版要求。');
  437. return
  438. }
  439. postData('/setting/user/unit/save', { type: 'import-users', users: tree }, function (result) {
  440. if (result.insertNum > 0) {
  441. toastr.success('成功导入了' + result.insertNum + '个账号');
  442. if (result.overMax) {
  443. toastr.warning('添加账号个数受限,部分账号无法导入,请去后台开放限制。');
  444. }
  445. setTimeout(function () {
  446. window.location.reload();
  447. }, 1500);
  448. } else if (result.insertNum === 0 && !result.overMax) {
  449. toastr.error('未能导入任何账号,请检查账号、公司是否已存在或excel是否符合模版要求。');
  450. } else if (result.insertNum === 0 && result.overMax) {
  451. toastr.warning('添加账号个数受限,账号无法导入,请去后台开放限制。');
  452. }
  453. })
  454. } catch (error) {
  455. console.log(error);
  456. toastr.error(error);
  457. return
  458. }
  459. };
  460. // 以二进制方式打开文件
  461. fileReader.readAsBinaryString(importFile);
  462. $('#upload-xls-file').val('');
  463. importFile = null;
  464. });
  465. function transExcel(results) {
  466. const mapInfo = {
  467. '登录账号': 'account',
  468. '登录密码': 'password',
  469. '姓名': 'name',
  470. '单位名称': 'company',
  471. '职位': 'role',
  472. '手机': 'mobile',
  473. '电话': 'telephone',
  474. };
  475. return results.map(zhObj => {
  476. const enObj = {}
  477. const zhKeys = Object.keys(zhObj);
  478. zhKeys.forEach(zhKey => {
  479. const enKey = mapInfo[zhKey];
  480. enObj[enKey] = zhObj[zhKey] && _.isString(zhObj[zhKey]) ? _.trim(zhObj[zhKey]) : zhObj[zhKey];
  481. });
  482. return enObj
  483. })
  484. }
  485. });
  486. function checkPasswordForm() {
  487. try {
  488. if ($('#edit-password input[name="account"]').val() == '' || $('#edit-password input[name="account"]').hasClass('is-invalid')) {
  489. throw '账号不能为空或已存在';
  490. }
  491. const resetPassword = $('#edit-password input[name="reset_password"]').val();
  492. if (resetPassword.length < 6) {
  493. throw '密码长度不能小于6';
  494. }
  495. if (!/^[0-9a-zA-Z*~!@&%$^\\(\\)#_\[\]\-\+={}|?'":,<>.`]+$/.test(resetPassword)) {
  496. throw '密码只支持英文数字及符号';
  497. }
  498. // 判断新密码的强度
  499. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  500. if (!reg.test(resetPassword)) {
  501. throw '请设置至少包含数字和字母的密码';
  502. }
  503. } catch (err) {
  504. toastr.error(err);
  505. return false;
  506. }
  507. }
  508. function setUnitRightHtml(id) {
  509. const one = _.find(unitList, { id });
  510. if (one) {
  511. $('#unit_name').val(one.name);
  512. $('#unit_corporation').val(one.corporation);
  513. $('#unit_credit_code').val(one.credit_code);
  514. $('#unit_tel').val(one.tel);
  515. $('#unit_website').val(one.website);
  516. $('#unit_region').val(one.region);
  517. $('#unit_address').val(one.address);
  518. $('#unit_basic').val(one.basic);
  519. $('#unit_type').val(one.type);
  520. if(one.sign_path) {
  521. $('#sign-show').html('<img src="' + fujianOssPath + one.sign_path + '" width="120">');
  522. $('#delete-sign').show();
  523. $('#upload-sign').hide();
  524. } else {
  525. $('#sign-show').html('');
  526. $('#delete-sign').hide();
  527. $('#upload-sign').show();
  528. }
  529. oneUnit = one;
  530. $('#add_user_company').val(one.name);
  531. }
  532. }
  533. /**
  534. * 表单检测
  535. */
  536. function checkUserForm(status) {
  537. try {
  538. if (status === 'add') {
  539. if ($('#add-user input[name="account_group"]').val() == 0) {
  540. throw '请选择账号组';
  541. }
  542. if ($('#add-user input[name="account"]').val() == '' || $('#add-user input[name="account"]').hasClass('is-invalid')) {
  543. throw '账号不能为空或已存在';
  544. }
  545. if ($('#add-user input[name="password"]').val() == '' || $('#add-user input[name="password"]').val().length < 6) {
  546. throw '密码不能为空或不能小于6位';
  547. }
  548. if (!/^[0-9a-zA-Z*~!@&%$^\\(\\)#_\[\]\-\+={}|?'":,<>.`]+$/.test($('#add-user input[name="password"]').val())) {
  549. throw '密码只支持英文数字及符号';
  550. }
  551. // 判断新密码的强度
  552. const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
  553. if (!reg.test($('#add-user input[name="password"]').val())) {
  554. throw '请设置至少包含数字和字母的密码';
  555. }
  556. if ($('#add-user input[name="name"]').val() == '') {
  557. throw '姓名不能为空';
  558. }
  559. if (_.findIndex(unitList, { name: $('#add-user select[name="company"]').val() }) === -1) {
  560. throw '请选择单位名称';
  561. }
  562. if ($('#add-user input[name="role"]').val() == '') {
  563. throw '职位名称不能为空';
  564. }
  565. $('#add-user input[name="account"]').val(trimInvalidChar($('#add-user input[name="account"]').val()));
  566. $('#add-user input[name="name"]').val(trimInvalidChar($('#add-user input[name="name"]').val()));
  567. // $('#add-user input[name="company"]').val(trimInvalidChar($('#add-user input[name="company"]').val()));
  568. $('#add-user input[name="role"]').val(trimInvalidChar($('#add-user input[name="role"]').val()));
  569. $('#add-user input[name="telephone"]').val(trimInvalidChar($('#add-user input[name="telephone"]').val()));
  570. } else {
  571. if ($('#edit-user input[name="account_group"]').val() == 0) {
  572. throw '请选择账号组';
  573. }
  574. if ($('#edit-user input[name="account"]').val() == '' || $('#add-user input[name="account"]').hasClass('is-invalid')) {
  575. throw '账号不能为空或已存在';
  576. }
  577. if ($('#edit-user input[name="name"]').val() == '') {
  578. throw '姓名不能为空';
  579. }
  580. if (_.findIndex(unitList, { name: $('#edit-user select[name="company"]').val() }) === -1) {
  581. throw '请选择单位名称';
  582. }
  583. if ($('#edit-user input[name="role"]').val() == '') {
  584. throw '职位名称不能为空';
  585. }
  586. $('#edit-user input[name="account"]').val(trimInvalidChar($('#edit-user input[name="account"]').val()));
  587. $('#edit-user input[name="name"]').val(trimInvalidChar($('#edit-user input[name="name"]').val()));
  588. // $('#edit-user input[name="company"]').val(trimInvalidChar($('#edit-user input[name="company"]').val()));
  589. $('#edit-user input[name="role"]').val(trimInvalidChar($('#edit-user input[name="role"]').val()));
  590. $('#edit-user input[name="telephone"]').val(trimInvalidChar($('#edit-user input[name="telephone"]').val()));
  591. }
  592. } catch (err) {
  593. toastr.error(err);
  594. return false;
  595. }
  596. }
  597. /**
  598. * 表单检测
  599. */
  600. function checkUnitForm() {
  601. try {
  602. if ($('#add-company input[name="name"]').val() == '') {
  603. throw '单位名称不能为空';
  604. }
  605. if ($('#add-company select[name="type"]').val() == 0) {
  606. throw '请选择类型';
  607. }
  608. // 检测同名
  609. if (_.findIndex(unitList, { name: $('#add-company input[name="name"]').val() }) !== -1) {
  610. throw '已存在对应的单位名称';
  611. }
  612. } catch (err) {
  613. toastr.error(err);
  614. return false;
  615. }
  616. }
  617. /**
  618. * 随机密码(必须包含数字和字母)
  619. */
  620. function randPassword() {
  621. const result = [];
  622. // 随机6-10位
  623. const length = Math.ceil(Math.random() * 2 + 6);
  624. let numberSeed = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  625. let stringSeed = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
  626. 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
  627. 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  628. const numRan = numberSeed[Math.floor((Math.random() * numberSeed.length))];
  629. const strRan = stringSeed[Math.floor((Math.random() * stringSeed.length))];
  630. const randSeed = stringSeed.concat(numberSeed);
  631. const seedLength = randSeed.length - 1;
  632. for (let i = 0; i < length; i++) {
  633. const index = Math.ceil(Math.random() * seedLength);
  634. result.push(randSeed[index]);
  635. }
  636. result.splice(Math.floor((Math.random() * result.length)), 0, numRan);
  637. result.splice(Math.floor((Math.random() * result.length)), 0, strRan);
  638. return result.join('');
  639. }