123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- layui.config({
- base: '../js/module/'
- }).extend({
- 'constants': '{/}../js/util/constants',
- 'ajax': '{/}../js/util/ajax',
- 'customUtil': '{/}../js/util/util',
- 'api': '{/}../js/api/user.api'
- }).use(['jquery', 'layer', 'form', 'api', 'constants', 'customUtil'], () => {
- const $ = layui.jquery
- layui.api.init((json) => {
- let templet = '<option value="">选择或搜索角色</option>'
- for (var i = 0; i < json.result.role.length; i++) {
- templet += `<option value="${json.result.role[i].roleId}">${json.result.role[i].roleName}</option>`
- }
- $('select[name="roleId"]').empty().append(templet)
- templet = '<option value="">选择或搜索单位</option>'
- for (var i = 0; i < json.result.corp.length; i++) {
- templet += `<option value="${json.result.corp[i].deptId}">${json.result.corp[i].deptName}</option>`
- }
- $('select[name="deptId"]').empty().append(templet)
- layui.form.render()
- initTable(json.result)
- })
- initClick()
- })
- const initTable = (result) => {
- let roleObj = {}
- for (let i = 0; i < result.role.length; i++) {
- roleObj[result.role[i].roleId] = result.role[i].roleName
- }
- let deptObj = {}
- for (let i = 0; i < result.corp.length; i++) {
- deptObj[result.corp[i].deptId] = result.corp[i].deptName
- }
- const templet = `
- <div>
- <span class="fast-span" lay-event="edit">编辑</span>
- <span class="fast-span fast-span-del" lay-event="del">删除</span>
- </div>
- `
- layui.customUtil.table({
- elem: '#table',
- url: '/user/paging',
- cols: [[
- {type: 'numbers', title: '序号'},
- {field: 'userName', width : 280, title: '姓名'},
- {field: 'account', title: '账号'},
- {title: '角色', templet: (res) => {
- return roleObj[res.roleId] || ''
- }},
- {title: '单位', width : 280, templet: (res) => {
- return deptObj[res.deptId] || ''
- }},
- {field: 'phone', title: '手机号'},
- {field: 'createTime', title: '创建时间'},
- {title: '操作', templet}
- ]]
- })
- }
- const initClick = () => {
- const $ = layui.jquery
- $('.brume-main').on('click', '#addBtn', () => {
- $('#form-title').text('新增')
- layui.form.val('form', {
- userId: '',
- userName: '',
- account: '',
- password: '',
- repeatPass: '',
- phone: '',
- roleId: '',
- deptId: '',
- })
- layui.customUtil.autoView('.brume-main', '.brume-form')
- })
- $('.brume-form').on('click', '#back', () => {
- layui.customUtil.autoView('.brume-main', '.brume-form')
- })
- $('.brume-main').on('click', '.search', () => {
- layui.table.reload('table', {
- where: {
- roleId: $('#RoleSel').val(),
- deptId: $('#deptSel').val(),
- queryVal: $('input[name="search"]').val()
- },
- page: { curr: 1 }
- })
- })
- layui.form.on('submit(formBtn)', (data) => {
- if (data.field?.userId) {
- if (data.field.password && data.field.repeatPass) {
- if (data.field.password != data.field.repeatPass) {
- layui.layer.msg('两次密码输入不一致', {icon: 5})
- return false
- }
- }
- layui.api.update(data.field,
- (json) => {
- if (json.code == layui.constants.SUCCESS_CODE) {
- layui.customUtil.autoView('.brume-main', '.brume-form')
- }
- layui.customUtil.refush(json.code == layui.constants.SUCCESS_CODE, '编辑成功', json.msg, {
- roleId: $('#RoleSel').val(),
- deptId: $('#deptSel').val(),
- queryVal: $('input[name="search"]').val()
- })
- }
- )
- } else {
- if (!(data.field.password && data.field.repeatPass)) {
- layui.layer.msg('请输入密码', {icon: 5})
- return false
- }
- if (data.field.password != data.field.repeatPass) {
- layui.layer.msg('两次密码输入不一致', {icon: 5})
- return false
- }
- layui.api.save(data.field,
- (json) => {
- if (json.code == layui.constants.SUCCESS_CODE) {
- layui.customUtil.autoView('.brume-main', '.brume-form')
- }
- layui.customUtil.refush(json.code == layui.constants.SUCCESS_CODE, '新增成功', json.msg, {
- roleId: $('#RoleSel').val(),
- deptId: $('#deptSel').val(),
- queryVal: $('input[name="search"]').val()
- })
- }
- )
- }
- return false
- })
-
- layui.table.on('tool(table)', function(obj) {
- if (obj.event == 'edit') {
- layui.api.one(obj.data.userId,
- (json) => {
- if (json.result) {
- $('#form-title').text('编辑')
- layui.form.val('form', json.result)
- layui.customUtil.autoView('.brume-main', '.brume-form')
- }
- })
- } else if (obj.event == 'del') {
- layui.layer.confirm('确认要删除吗?', {
- btn: ['删除', '取消']
- }, (index) => {
- layui.api.delete(obj.data.userId,
- (json) => {
- layui.customUtil.refush(json.result, '删除成功', '删除失败', {
- roleId: $('#RoleSel').val(),
- deptId: $('#deptSel').val(),
- queryVal: $('input[name="search"]').val()
- })
- }
- )
- })
- }
- })
- }
|