|
@@ -25,12 +25,12 @@ $(document).ready(() => {
|
|
|
const account = $(this).data('account');
|
|
|
$('#edit-user input[name="account"]').val(account.account);
|
|
|
$('#edit-user input[name="name"]').val(account.name);
|
|
|
- $('#edit-user input[name="company"]').val(account.company);
|
|
|
+ $('#edit-user select[name="company"]').val(account.company);
|
|
|
$('#edit-user input[name="role"]').val(account.role);
|
|
|
$('#edit-user input[name="mobile"]').val(account.mobile);
|
|
|
$('#edit-user input[name="telephone"]').val(account.telephone);
|
|
|
$('#edit-user input[name="id"]').val(account.id);
|
|
|
- $('#edit-user select[name="account_group"]').val(account.account_group);
|
|
|
+ $('#edit-user input[name="account_group"]').val(account.account_group);
|
|
|
$('#edit-user input[class="account-check"]').val(account.account);
|
|
|
$('#edit-user input[data-mobile="auth-mobile"]').val(account.auth_mobile);
|
|
|
$('#edit-user input[name="mobile"]').attr('readOnly', account.bind === 1);
|
|
@@ -45,6 +45,13 @@ $(document).ready(() => {
|
|
|
$('#edit-password input[name="reset_password"]').val('');
|
|
|
});
|
|
|
|
|
|
+ // 选择单位自动配置账号组
|
|
|
+ $('select[name="company"]').change(function () {
|
|
|
+ const company = $(this).val();
|
|
|
+ const oneUnit = _.find(unitList, { name: company });
|
|
|
+ $(this).siblings('input[name="account_group"]').val(oneUnit ? oneUnit.type : 7);
|
|
|
+ });
|
|
|
+
|
|
|
// 分配随机密码
|
|
|
$("#rand-password").click(function() {
|
|
|
const password = randPassword();
|
|
@@ -196,10 +203,214 @@ $(document).ready(() => {
|
|
|
// 设置页显示数目
|
|
|
$('.nav-tabs .nav-link').each(function () {
|
|
|
const pageSize = getLocalCache('account-pageSize') ? getLocalCache('account-pageSize') : '';
|
|
|
- if (getLocalCache('account-pageSize') && $(this).attr('href').indexOf('pageSize') === -1) {
|
|
|
+ if (getLocalCache('account-pageSize') && $(this).attr('href').indexOf('pageSize') === -1 && $(this).attr('href').indexOf('unit') === -1) {
|
|
|
$(this).attr('href', $(this).attr('href') + '?pageSize=' + getLocalCache('account-pageSize'));
|
|
|
}
|
|
|
});
|
|
|
+ // 设置页显示数目
|
|
|
+ $('#user-list .list-group-item').each(function (k,v) {
|
|
|
+ const pageSize = getLocalCache('account-pageSize') ? getLocalCache('account-pageSize') : '';
|
|
|
+ if (pageSize) {
|
|
|
+ $(this).attr('href', $(this).attr('href') + '&pageSize=' + pageSize);
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 参建单位页切换单位右侧显示
|
|
|
+ $('#unit_list tr').click(function () {
|
|
|
+ const id = parseInt($(this).data('id'));
|
|
|
+ const one = _.find(unitList, { id });
|
|
|
+ if (one) {
|
|
|
+ $(this).siblings('tr').removeClass('table-warning');
|
|
|
+ $(this).addClass('table-warning');
|
|
|
+ $('#unit_name').val(one.name);
|
|
|
+ $('#unit_corporation').val(one.corporation);
|
|
|
+ $('#unit_credit_code').val(one.credit_code);
|
|
|
+ $('#unit_tel').val(one.tel);
|
|
|
+ $('#unit_website').val(one.website);
|
|
|
+ $('#unit_region').val(one.region);
|
|
|
+ $('#unit_address').val(one.address);
|
|
|
+ $('#unit_basic').val(one.basic);
|
|
|
+ $('#unit_type').val(one.type);
|
|
|
+ if(one.sign_path) {
|
|
|
+ $('#sign-show').html('<img src="' + fujianOssPath + one.sign_path + '" width="120">');
|
|
|
+ $('#delete-sign').show();
|
|
|
+ $('#upload-sign').hide();
|
|
|
+ } else {
|
|
|
+ $('#sign-show').html('');
|
|
|
+ $('#delete-sign').hide();
|
|
|
+ $('#upload-sign').show();
|
|
|
+ }
|
|
|
+ oneUnit = one;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 参建单位编辑
|
|
|
+ // 回车提交
|
|
|
+ $('#one_unit input').on('keypress', function () {
|
|
|
+ if(window.event.keyCode === 13) {
|
|
|
+ $(this).blur();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#one_unit input').blur(function () {
|
|
|
+ console.log('hello');
|
|
|
+ const val_name = $(this).data('name');
|
|
|
+ let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
|
|
|
+ if (!oneUnit) {
|
|
|
+ toastr.error('所选单位有误,请重新选择');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ switch(val_name) {
|
|
|
+ case 'name':
|
|
|
+ if(val && val.length > 100) {
|
|
|
+ toastr.error('单位名称超过100个字,请缩减名称');
|
|
|
+ $(this).val(oneUnit[val_name]);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const tongming = _.find(unitList, { name: val });
|
|
|
+ if (tongming && tongming.id !== oneUnit.id) {
|
|
|
+ toastr.error('单位名称不能重复');
|
|
|
+ $(this).val(oneUnit[val_name]);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ if(val && val.length > 255) {
|
|
|
+ toastr.error('超出字段范围,请缩减');
|
|
|
+ $(this).val(oneUnit[val_name]);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(oneUnit[val_name] !== val) {
|
|
|
+ const _self = $(this);
|
|
|
+ postData('/setting/user/unit/save', { type: 'update', id: oneUnit.id, val_name, val}, function (result) {
|
|
|
+ oneUnit[val_name] = val;
|
|
|
+ _self.val(oneUnit[val_name]);
|
|
|
+ if (val_name === 'name') {
|
|
|
+ oneUnit.account_num = result.account_num;
|
|
|
+ $('#unit_list tr[class="table-warning"]').find('a').text(oneUnit[val_name]);
|
|
|
+ $('#unit_list tr[class="table-warning"]').children('td').eq(2).text(result.account_num);
|
|
|
+ }
|
|
|
+ }, function () {
|
|
|
+ _self.val(oneUnit[val_name]);
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ $(this).val(oneUnit[val_name]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#one_unit textarea').blur(function () {
|
|
|
+ const val_name = $(this).data('name');
|
|
|
+ let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
|
|
|
+ if (!oneUnit) {
|
|
|
+ toastr.error('所选单位有误,请重新选择');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if(oneUnit[val_name] !== val) {
|
|
|
+ const _self = $(this);
|
|
|
+ postData('/setting/user/unit/save', { type: 'update', id: oneUnit.id, val_name, val}, function (result) {
|
|
|
+ oneUnit[val_name] = val;
|
|
|
+ _self.val(oneUnit[val_name]);
|
|
|
+ $('#unit_list tr[class="table-warning"]').children('td').eq(4).text(oneUnit[val_name]);
|
|
|
+ }, function () {
|
|
|
+ _self.val(oneUnit[val_name]);
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ $(this).val(oneUnit[val_name]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#one_unit select').change(function () {
|
|
|
+ const val_name = $(this).attr('data-name');
|
|
|
+ let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
|
|
|
+ if (!oneUnit) {
|
|
|
+ toastr.error('所选单位有误,请重新选择');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if(oneUnit[val_name] !== val) {
|
|
|
+ const _self = $(this);
|
|
|
+ postData('/setting/user/unit/save', { type: 'update', id: oneUnit.id, name: oneUnit.name, val_name, val}, function (result) {
|
|
|
+ oneUnit[val_name] = val;
|
|
|
+ _self.val(oneUnit[val_name]);
|
|
|
+ $('#unit_list tr[class="table-warning"]').children('td').eq(3).text(accountGroup[parseInt(oneUnit[val_name])]);
|
|
|
+ }, function () {
|
|
|
+ _self.val(oneUnit[val_name]);
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ $(this).val(oneUnit[val_name]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 删除单位弹窗
|
|
|
+ $('#del-modal-btn').click(function () {
|
|
|
+ if (!oneUnit) {
|
|
|
+ toastr.error('所选单位有误,请重新选择');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (oneUnit.account_num === 0) {
|
|
|
+ $('.del-btn').show();
|
|
|
+ $('.not-del-btn').hide();
|
|
|
+ } else {
|
|
|
+ $('.del-btn').hide();
|
|
|
+ $('.not-del-btn').show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 删除单位
|
|
|
+ $('#delete-unit').click(function () {
|
|
|
+ if (!oneUnit) {
|
|
|
+ toastr.error('所选单位有误,请重新选择');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ postData('/setting/user/unit/save', { type: 'delete', name: oneUnit.name, id: oneUnit.id }, function (result) {
|
|
|
+ window.location.href = '/setting/user/unit';
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ // 上传签章
|
|
|
+ $('#sign-upload').change(function () {
|
|
|
+ if (!oneUnit) {
|
|
|
+ toastr.error('所选单位有误,请重新选择');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const file = this.files[0];
|
|
|
+ const ext = file.name.toLowerCase().split('.').splice(-1)[0];
|
|
|
+ const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
|
|
|
+ if (!imgStr.test(ext)) {
|
|
|
+ toastr.error('请上传正确的图片格式文件');
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if ($(this).val()) {
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('file', this.files[0]);
|
|
|
+ formData.append('id', oneUnit.id);
|
|
|
+ postDataWithFile('/setting/user/unit/upload', formData, function (result) {
|
|
|
+ const html = '<img src="'+ fujianOssPath + result.sign_path +'" width="120">';
|
|
|
+ $('#sign-show').html(html);
|
|
|
+ $('#sign-upload').val('');
|
|
|
+ oneUnit.sign_path = result.sign_path;
|
|
|
+ $('#upload-sign').hide();
|
|
|
+ $('#delete-sign').show();
|
|
|
+ toastr.success('上传成功');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 移除签章
|
|
|
+ $('#delete-sign').click(function () {
|
|
|
+ if (!oneUnit) {
|
|
|
+ toastr.error('所选单位有误,请重新选择');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ postData('/setting/user/unit/save', { type: 'del-sign', id: oneUnit.id }, function (result) {
|
|
|
+ $('#sign-show').html('');
|
|
|
+ toastr.warning('已移除');
|
|
|
+ oneUnit.sign_path = null;
|
|
|
+ $('#upload-sign').show();
|
|
|
+ $('#delete-sign').hide();
|
|
|
+ })
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
function checkPasswordForm() {
|
|
@@ -226,7 +437,7 @@ function checkPasswordForm() {
|
|
|
function checkUserForm(status) {
|
|
|
try {
|
|
|
if (status === 'add') {
|
|
|
- if ($('#add-user select[name="account_group"]').val() == 0) {
|
|
|
+ if ($('#add-user input[name="account_group"]').val() == 0) {
|
|
|
throw '请选择账号组';
|
|
|
}
|
|
|
if ($('#add-user input[name="account"]').val() == '' || $('#add-user input[name="account"]').hasClass('is-invalid')) {
|
|
@@ -241,8 +452,8 @@ function checkUserForm(status) {
|
|
|
if ($('#add-user input[name="name"]').val() == '') {
|
|
|
throw '姓名不能为空';
|
|
|
}
|
|
|
- if ($('#add-user input[name="company"]').val() == '') {
|
|
|
- throw '单位名称不能为空';
|
|
|
+ if (_.findIndex(unitList, $('#add-user select[name="company"]').val()) === -1) {
|
|
|
+ throw '请选择单位名称';
|
|
|
}
|
|
|
if ($('#add-user input[name="role"]').val() == '') {
|
|
|
throw '职位名称不能为空';
|
|
@@ -262,8 +473,8 @@ function checkUserForm(status) {
|
|
|
if ($('#edit-user input[name="name"]').val() == '') {
|
|
|
throw '姓名不能为空';
|
|
|
}
|
|
|
- if ($('#edit-user input[name="company"]').val() == '') {
|
|
|
- throw '单位名称不能为空';
|
|
|
+ if (_.findIndex(unitList, $('#edit-user select[name="company"]').val()) === -1) {
|
|
|
+ throw '请选择单位名称';
|
|
|
}
|
|
|
if ($('#edit-user input[name="role"]').val() == '') {
|
|
|
throw '职位名称不能为空';
|
|
@@ -281,6 +492,23 @@ function checkUserForm(status) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 表单检测
|
|
|
+ */
|
|
|
+function checkUnitForm() {
|
|
|
+ try {
|
|
|
+ if ($('#add-company input[name="name"]').val() == '') {
|
|
|
+ throw '单位名称不能为空';
|
|
|
+ }
|
|
|
+ if ($('#add-company select[name="type"]').val() == 0) {
|
|
|
+ throw '请选择类型';
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ toastr.error(err);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
* 随机密码
|
|
|
*/
|
|
|
function randPassword() {
|