| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 | 'use strict';/** * 项目信息js * * @author EllisRan. * @date 2019/3/19 * @version */$(document).ready(() => {    // 启用和停用账号    $('.account-switch-btn').on('click', function () {        const data = {            enable: $(this).hasClass('btn-outline-success') ? 1 : 0,            id: $(this).data('account'),        };        postData('/setting/user/switch', data, function () {            window.location.href = '/setting/user';        });    });    // 编辑账号    $('a[data-target="#edit-user"]').on('click', function () {        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 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[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);        if (account.bind === 1) {            $('#edit-user input[name="mobile"]').siblings('small').show();        } else {            $('#edit-user input[name="mobile"]').siblings('small').hide();        }        $('#edit-password input[name="account"]').val(account.account);        $('#edit-password input[class="account-check"]').val(account.account);        $('#edit-password input[name="id"]').val(account.id);        $('#edit-password input[name="reset_password"]').val('');    });    // 分配随机密码    $("#rand-password").click(function() {        const password = randPassword();        $(this).parent().parent().find('input').val(password);    });    // 分配随机密码    $("#rand-password2").click(function() {        const password = randPassword();        $(this).parent().parent().find('input').val(password);    });    // 重置密码    let isChange = false;    $("#reset-password-btn").click(function() {        try {            if (isChange) {                throw '稍后再操作';            }            const resetPassword = $("#reset-password").val();            const id = $("#user-id").val();            if (resetPassword.length < 6) {                throw '密码长度不能小于6';            }            if (!/^[0-9a-zA-Z*~!@&%$^\\(\\)#_\[\]\-\+={}|?'":,<>.`]+$/.test(resetPassword)) {                throw '密码只支持英文数字及符号';            }            const btn = $(this);            $.ajax({                url: '/setting/user/reset/password',                type: 'post',                data: { id: id, reset_password: resetPassword },                dataType: 'json',                error: function() {                    isChange = false;                    btn.html('重置密码');                    throw '网络错误!';                },                beforeSend: function(xhr) {                    let csrfToken = Cookies.get('csrfToken_j');                    xhr.setRequestHeader('x-csrf-token', csrfToken);                    isChange = true;                    btn.html('<i class="fa fa-spinner fa-pulse"></i>');                },                success: function(response) {                    isChange = false;                    btn.html('重置密码');                    if (response.err !== 0) {                        throw response.msg;                    }                    $("#reset-password").val('');                    toastr.success('重置成功');                }            });        } catch (error) {            toastr.error(error);            console.log(error);        }    });    // 账号查重    $('input[name="account"]').on('blur', function () {        const self = $(this);        if (self.val() !== self.siblings('input').val()) {            const data = {account: $(this).val()};            postData('/setting/user/exist', data, function (data) {                if (data === null) {                    self.removeClass('is-invalid');                } else {                    self.addClass('is-invalid');                }            })        } else {            self.removeClass('is-invalid');        }    });    // 选中创建标段才可以选择协作办公    $('a[data-target="#edit-user2"]').on('click', function () {        $('#edit-user2 input:radio').prop('checked', false);        $('#edit-user2 input:checkbox').prop('checked', false);        const account = $(this).data('account');        $('#edit-user2 input[name="id"]').val(account.id);        // 权限赋值        if (account.permission !== '') {            const permission = JSON.parse(account.permission);            for (const pm in permission) {                if (pm === 'tender' && permission[pm].indexOf('1') !== -1) {                    $('#edit-user2 input[name="cooperation"]').attr('disabled', false);                } else {                    $('#edit-user2 input[name="cooperation"]').attr('disabled', true);                }                if (allPermission[pm].type === 'checkbox') {                    for (const index of permission[pm]) {                        $('#edit-user2 input:checkbox[id="' + pm + '_' + index + '"]').prop('checked', true);                    }                } else if (allPermission[pm].type === 'radio') {                    $('#edit-user2 input:radio[id="' + pm + '_' + permission[pm] + '"]').prop('checked', true);                }            }        }        // 协作赋值        $('#edit-user2 input:radio[name="cooperation"][value="' + account.cooperation + '"]').prop('checked', true);    });    // 选择创建标段功能后可选协作办公    $('#edit-user2 input:checkbox').click(function () {        if ($(this).attr('id') === 'tender_1') {            if ($(this).is(':checked')) {                $('#edit-user2 input[name="cooperation"]').attr('disabled', false);            } else {                $('#edit-user2 input[name="cooperation"]').attr('disabled', true);            }        }    });    // 解绑第三方平台    $('.unlink-user').on('click', function () {        const id = $(this).data('account');        const accountData = _.find(accountList, { id });        console.log(accountData);        $('#bind_account').text(accountData.name + ' ' + accountData.mobile);        $('#account_id').val(id);    })    // 设置显示默认    $('body').on('click', '#set-default', function () {        const attid = $(this).data('attid');        const data = {id: attid};        postData('/setting/show/update', data, function (result) {           let html = ''            result.forEach((item, idx) => {                html += `<li class="list-group-item">${item.label_name}`                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>`            })            // <li class="list-group-item">            // 标段列表<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>            // </li>            // <li class="list-group-item">金额概况<span class="pull-right">默认</span></li>            // <li class="list-group-item">            //     计量进度<a href="#" class="btn btn-primary btn-sm pull-right">设为默认</a>            // </li>            $('.list-group').empty()            $('.list-group').append(html)            const item = result.find((i, idx) => idx=== attid)            $('#nav_tender').attr('href', item.path)        });    });    // 设置页显示数目    $('.nav-tabs .nav-link').each(function () {        const pageSize = getLocalCache('account-pageSize') ? getLocalCache('account-pageSize') : '';        if (getLocalCache('account-pageSize') && $(this).attr('href').indexOf('pageSize') === -1) {            $(this).attr('href', $(this).attr('href') + '?pageSize=' + getLocalCache('account-pageSize'));        }    });});function checkPasswordForm() {    try {        if ($('#edit-password input[name="account"]').val() == '' || $('#edit-password input[name="account"]').hasClass('is-invalid')) {            throw '账号不能为空或已存在';        }        const resetPassword = $('#edit-password input[name="reset_password"]').val();        if (resetPassword.length < 6) {            throw '密码长度不能小于6';        }        if (!/^[0-9a-zA-Z*~!@&%$^\\(\\)#_\[\]\-\+={}|?'":,<>.`]+$/.test(resetPassword)) {            throw '密码只支持英文数字及符号';        }    } catch (err) {        toastr.error(err);        return false;    }}/** * 表单检测 */function checkUserForm(status) {    try {        if (status === 'add') {            if ($('#add-user select[name="account_group"]').val() == 0) {                throw '请选择账号组';            }            if ($('#add-user input[name="account"]').val() == '' || $('#add-user input[name="account"]').hasClass('is-invalid')) {                throw '账号不能为空或已存在';            }            if ($('#add-user input[name="password"]').val() == '' || $('#add-user input[name="password"]').val().length < 6) {                throw '密码不能为空或不能小于6位';            }            if (!/^[0-9a-zA-Z*~!@&%$^\\(\\)#_\[\]\-\+={}|?'":,<>.`]+$/.test($('#add-user input[name="password"]').val())) {                throw '密码只支持英文数字及符号';            }            if ($('#add-user input[name="name"]').val() == '') {                throw '姓名不能为空';            }            if ($('#add-user input[name="company"]').val() == '') {                throw '单位名称不能为空';            }            if ($('#add-user input[name="role"]').val() == '') {                throw '职位名称不能为空';            }            $('#add-user input[name="account"]').val(trimInvalidChar($('#add-user input[name="account"]').val()));            $('#add-user input[name="name"]').val(trimInvalidChar($('#add-user input[name="name"]').val()));            $('#add-user input[name="company"]').val(trimInvalidChar($('#add-user input[name="company"]').val()));            $('#add-user input[name="role"]').val(trimInvalidChar($('#add-user input[name="role"]').val()));            $('#add-user input[name="telephone"]').val(trimInvalidChar($('#add-user input[name="telephone"]').val()));        } else {            if ($('#edit-user select[name="account_group"]').val() == 0) {                throw '请选择账号组';            }            if ($('#edit-user input[name="account"]').val() == '' || $('#add-user input[name="account"]').hasClass('is-invalid')) {                throw '账号不能为空或已存在';            }            if ($('#edit-user input[name="name"]').val() == '') {                throw '姓名不能为空';            }            if ($('#edit-user input[name="company"]').val() == '') {                throw '单位名称不能为空';            }            if ($('#edit-user input[name="role"]').val() == '') {                throw '职位名称不能为空';            }            $('#edit-user input[name="account"]').val(trimInvalidChar($('#edit-user input[name="account"]').val()));            $('#edit-user input[name="name"]').val(trimInvalidChar($('#edit-user input[name="name"]').val()));            $('#edit-user input[name="company"]').val(trimInvalidChar($('#edit-user input[name="company"]').val()));            $('#edit-user input[name="role"]').val(trimInvalidChar($('#edit-user input[name="role"]').val()));            $('#edit-user input[name="telephone"]').val(trimInvalidChar($('#edit-user input[name="telephone"]').val()));        }    } catch (err) {        toastr.error(err);        return false;    }}/** * 随机密码 */function randPassword() {    let result = '';    // 随机6-10位    const length = Math.ceil(Math.random() * 2 + 8);    let numberSeed = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];    let stringSeed = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',        'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',        'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];    const randSeed = stringSeed.concat(numberSeed);    const seedLength = randSeed.length - 1;    for (let i = 0; i < length; i++) {        const index = Math.ceil(Math.random() * seedLength);        result += randSeed[index];    }    return result;}
 |