416 lines
13 KiB
Vue
Raw Normal View History

2024-01-23 17:05:40 +08:00
<template>
<a-modal
2024-03-25 11:01:45 +08:00
title='操作'
style='top: 20px;'
:width='800'
v-model='visible'
:confirmLoading='confirmLoading'
@ok='handleSubmit'
2024-01-23 17:05:40 +08:00
>
2024-03-25 11:01:45 +08:00
<a-spin :spinning='spinning'>
<a-form :form='form'>
<a-form-item style='display:none'>
<a-input v-decorator="['id']" />
2024-01-23 17:05:40 +08:00
</a-form-item>
2024-03-25 11:01:45 +08:00
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='用户名'>
<a-input placeholder='用户名'
v-decorator="['username', {rules: [{ required: true, message: '请输入用户名' }]}]" />
2024-01-23 17:05:40 +08:00
</a-form-item>
2024-03-25 11:01:45 +08:00
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='昵称'>
<a-input v-decorator="['nickname', {rules: [{ required: true, message: '请输入昵称' }]}] "
placeholder='起一个名字' />
2024-01-23 17:05:40 +08:00
</a-form-item>
2024-03-25 11:01:45 +08:00
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='手机'>
<a-input placeholder='手机' v-decorator="['mobile', {rules: [{ required: true, message: '请输入手机' }]}]" />
2024-01-23 17:05:40 +08:00
</a-form-item>
2024-03-25 11:01:45 +08:00
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='状态'>
2024-01-23 17:05:40 +08:00
<a-select v-decorator="['status', {initialValue:'0',rules: [{ required: true, message: '请选择状态' }]}]">
<a-select-option :value="'0'">正常</a-select-option>
<a-select-option :value="'1'">禁用</a-select-option>
</a-select>
</a-form-item>
2024-03-25 11:01:45 +08:00
<a-form-item v-if='tenantId !== null' :labelCol='labelCol' :wrapperCol='wrapperCol' label='部门'>
2024-01-23 17:05:40 +08:00
<a-tree-select
v-decorator="['deptId', {rules: [{ required: true, message: '请选择部门' }]}]"
:dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
2024-03-25 11:01:45 +08:00
:treeData='deptTree'
@change='onChange'
placeholder='部门'
2024-01-23 17:05:40 +08:00
treeDefaultExpandAll
>
</a-tree-select>
</a-form-item>
2024-03-25 11:01:45 +08:00
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='拥有角色' hasFeedback>
2024-01-23 17:05:40 +08:00
<a-select
2024-03-25 11:01:45 +08:00
style='width: 100%'
2024-01-23 17:05:40 +08:00
v-decorator="['roleIds', {rules: [{ required: true, message: '请选择角色' }]}]"
2024-03-25 11:01:45 +08:00
:allowClear='true'
mode='multiple'
@change='roleSelectChange'
2024-01-23 17:05:40 +08:00
>
<a-select-option v-for='(action) in roleAll' :key='action.id' :disabled='selectRoleEnable'>
{{ action.roleName
}}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item v-if='tenantShow' :labelCol='labelCol' :wrapperCol='wrapperCol' label='所属地区'>
<a-select v-decorator="['tenantId', {rules: [{ required: true, message: '请选择所属地区' }]}]"
@change='selectTenant'>
<a-select-option v-for='item in tenantData' :key='item.value'>{{ item.text }}</a-select-option>
2024-01-23 17:05:40 +08:00
</a-select>
</a-form-item>
<a-form-item v-if='parkShow' :labelCol='labelCol' :wrapperCol='wrapperCol' label='所属园区'>
<a-select v-decorator="['parkId', {rules: [{ required: true, message: '请选择所属园区' }]}]"
@change='selectPark'>
<a-select-option v-for='item in parkData' :key='item.value'>{{ item.text }}</a-select-option>
</a-select>
</a-form-item>
<a-form-item v-if='customerShow' :labelCol='labelCol' :wrapperCol='wrapperCol' label='选择企业'>
<a-select v-decorator="['customerId', {rules: [{ required: true, message: '请选择企业' }]}]"
@change='selectEnterprise'>
2024-03-25 11:01:45 +08:00
<a-select-option v-for='item in customerList' :key='item.value'>{{ item.text }}</a-select-option>
</a-select>
</a-form-item>
<a-form-item v-if='selectUserShow' :labelCol='labelCol' :wrapperCol='wrapperCol' label='选择用户'>
<a-select
show-search
v-decorator="['staffId', {rules: [{required: true, message: '请选择手机号码'}]}]"
2024-03-25 11:01:45 +08:00
placeholder='请选择手机号码'
style='width: 100%'
2024-03-25 11:01:45 +08:00
:default-active-first-option='false'
:show-arrow='false'
:filter-option='false'
:not-found-content='null'
@search='handleSearch'
@change='handleChange'
>
<a-select-option v-for='item in searchUserList' :value='item.id' :key='item.id'>
2024-03-25 11:01:45 +08:00
{{ item.username }} -{{ item.mobile }}
</a-select-option>
</a-select>
</a-form-item>
2024-01-23 17:05:40 +08:00
2024-03-25 11:01:45 +08:00
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='描述'>
<a-textarea :rows='3' placeholder='...' v-decorator="['remark']" />
2024-01-23 17:05:40 +08:00
</a-form-item>
</a-form>
</a-spin>
</a-modal>
</template>
<script>
import { getRoleAll, saveUser, getUser } from '@/api/system'
2024-04-08 13:50:14 +08:00
import { saveCustomerContacts, getStaffList, getStaffListByUser } from '@/api/admin/customer'
import {
getCustomerList
} from '@/api/admin/meeting/roomContent'
2024-01-23 17:05:40 +08:00
import { getTenantList } from '@/api/tenant'
import { getParkList } from '@/api/admin/park'
import pick from 'lodash.pick'
import { mapGetters } from 'vuex'
2024-03-25 11:01:45 +08:00
2024-01-23 17:05:40 +08:00
export default {
name: 'UserModal',
props: {
deptTree: {
type: Array,
required: true
}
},
computed: {
...mapGetters(['parkId', 'tenantId'])
},
2024-03-25 11:01:45 +08:00
data() {
2024-01-23 17:05:40 +08:00
return {
description: '列表使用场景:后台管理中的权限管理以及角色管理,可用于基于 RBAC 设计的角色权限控制,颗粒度细到每一个操作类型。',
visible: false,
labelCol: {
xs: { span: 24 },
sm: { span: 5 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 }
},
confirmLoading: false,
roleAll: [],
mdl: {},
searchUserList: [],
2024-03-25 11:01:45 +08:00
customerList: [],
2024-01-23 17:05:40 +08:00
deptCheck: true,
spinning: false,
tenantData: [],
parkData: [],
form: this.$form.createForm(this),
selectRoleEnable: false,
tenantShow: false,
parkShow: false,
customerShow: false,
selectUserShow: false
2024-01-23 17:05:40 +08:00
}
},
2024-03-25 11:01:45 +08:00
beforeCreate() {
2024-01-23 17:05:40 +08:00
},
2024-03-25 11:01:45 +08:00
created() {
// 地区
2024-01-23 17:05:40 +08:00
getTenantList().then(res => {
if (res.code === 0) {
res.rows.forEach(r => {
this.tenantData.push({ value: r.id, text: r.name })
})
}
})
this.loadRoleAll()
},
methods: {
// 选择角色
roleSelectChange(value) {
console.log('roleSelectChange', value)
// 清空数据
this.searchUserList = []
// 赋值
this.mdl.roleIds = value
// 角色判断
if (value.length > 0) {
this.selectRoleEnable = true
// 判断角色
if (value[0] == 4) { // 企业4
this.tenantShow = true
this.parkShow = true
this.customerShow = true
} else if (value[0] == 5) { // 园区5
this.tenantShow = true
this.parkShow = true
} else {
this.tenantShow = false
this.parkShow = false
this.customerShow = false
this.selectUserShow = false
}
} else {
this.selectRoleEnable = false
//
this.tenantShow = false
this.parkShow = false
this.customerShow = false
this.selectUserShow = false
}
},
// 选择地区 -> 查询园区
selectTenant(id) {
console.log('selectTenant', id)
getParkList({
tenantId: id
}).then(res => {
this.parkData = res.rows.map(item => {
return {
value: item.id,
text: item.name
}
})
})
// 赋值
this.mdl.tenantId = id
// 清空数据
this.searchUserList = []
// 隐藏用户搜索
this.selectUserShow = false
// 清空园区、企业、用户
this.mdl.parkId = null
this.mdl.customerId = null
this.mdl.staffId = null
this.form.setFieldsValue({
parkId: null,
customerId: null,
staffId: null
})
},
// 选择园区 -> 查询企业
selectPark(id) {
getCustomerList({
parkId: id
}).then(res => {
this.customerList = res.data.map(item => {
return {
value: item.id,
text: item.name
}
})
})
// 赋值
this.mdl.parkId = id
// 清空数据
this.searchUserList = []
// 清空企业、用户
this.mdl.customerId = null
this.mdl.staffId = null
this.form.setFieldsValue({
customerId: null,
staffId: null
})
// 园区角色显示用户并且查询用户
console.log('this.mdl.roleIds', this.mdl.roleIds)
if (this.mdl.roleIds[0] == 5) {
2024-04-15 16:52:45 +08:00
this.selectUserShow = false
} else {
// 隐藏用户搜索
this.selectUserShow = false
}
},
// 选择企业
selectEnterprise(id) {
// 赋值
this.mdl.customerId = id
// 显示搜索用户
this.selectUserShow = true
// 清空数据
this.searchUserList = []
// 清空用户
this.mdl.staffId = null
this.form.setFieldsValue({
staffId: null
})
},
2024-03-25 11:01:45 +08:00
handleSearch(value) {
let param = {
2024-03-25 11:01:45 +08:00
mobile: value
}
// 判断角色
if (this.mdl.roleIds[0] == 4) { // 企业4
param.customerId = this.mdl.customerId
} else if (this.mdl.roleIds[0] == 5) { // 园区5
param.parkId = this.mdl.parkId
} else {
}
2024-03-25 11:01:45 +08:00
getStaffList(param).then(res => {
this.searchUserList = res.rows
})
},
2024-03-25 11:01:45 +08:00
handleChange() {
},
2024-03-25 11:01:45 +08:00
add() {
2024-01-23 17:05:40 +08:00
this.form.resetFields()
this.mdl = Object.assign({}, { id: 0, deptId: '' })
this.visible = true
this.$nextTick(() => {
2024-03-25 11:01:45 +08:00
this.form.setFieldsValue(pick(this.mdl, 'id', 'username', 'nickname', 'status', 'mobile', 'roleIds', 'staffId', 'customerId', 'remark', 'deptId', 'parkId', 'tenantId'))
2024-01-23 17:05:40 +08:00
})
// 初始化显示
this.selectRoleEnable = false
this.tenantShow = false
this.parkShow = false
this.customerShow = false
this.selectUserShow = false
2024-01-23 17:05:40 +08:00
},
2024-03-25 11:01:45 +08:00
edit(record) {
2024-01-23 17:05:40 +08:00
if (record.id > 0) {
2024-03-25 11:01:45 +08:00
//
2024-01-23 17:05:40 +08:00
this.spinning = true
getUser(record.id).then(res => {
this.mdl = Object.assign({}, res)
let copyMdl = JSON.parse(JSON.stringify(this.mdl))
2024-01-23 17:05:40 +08:00
this.visible = true
this.$nextTick(() => {
2024-03-25 11:01:45 +08:00
this.form.setFieldsValue(pick(this.mdl, 'id', 'username', 'nickname', 'status', 'mobile', 'roleIds', 'customerId', 'staffId', 'remark', 'deptId', 'parkId', 'tenantId'))
2024-01-23 17:05:40 +08:00
this.spinning = false
// this.form.setFieldsValue({ ...record })
})
// 判断角色
if (this.mdl.roleIds[0] == 4) { // 企业4
// 选择地区 -> 查询园区
this.mdl = JSON.parse(JSON.stringify(copyMdl))
this.selectTenant(copyMdl.tenantId)
// 选择园区 -> 查询企业
this.mdl = JSON.parse(JSON.stringify(copyMdl))
this.selectPark(copyMdl.parkId)
// 查询用户
this.mdl = JSON.parse(JSON.stringify(copyMdl))
this.handleSearch(copyMdl.staffPhone)
// 赋值
this.mdl.customerId = copyMdl.customerId
this.mdl.staffId = copyMdl.staffId
// 显示
this.tenantShow = true
this.parkShow = true
this.customerShow = true
this.selectUserShow = true
} else if (this.mdl.roleIds[0] == 5) { // 园区5
// 选择地区 -> 查询园区
this.mdl = JSON.parse(JSON.stringify(copyMdl))
this.selectTenant(copyMdl.tenantId)
// 查询用户
this.mdl = JSON.parse(JSON.stringify(copyMdl))
this.handleSearch(copyMdl.staffPhone)
// 赋值
this.mdl.staffId = copyMdl.staffId
// 显示
this.tenantShow = true
this.parkShow = true
this.customerShow = false
this.selectUserShow = true
2024-03-25 10:30:28 +08:00
} else {
this.tenantShow = false
this.parkShow = false
this.customerShow = false
this.selectUserShow = false
}
2024-01-23 17:05:40 +08:00
})
}
},
2024-03-25 11:01:45 +08:00
onChange(value, label, extra) {
2024-01-23 17:05:40 +08:00
if (extra.triggerNode.$children.length > 0) {
this.$message.error('不能选择父节点' + `${label}`)
this.deptCheck = false
} else {
this.deptCheck = true
}
},
2024-03-25 11:01:45 +08:00
loadRoleAll() {
2024-01-23 17:05:40 +08:00
getRoleAll().then(res => {
this.roleAll = res.rows
})
},
2024-03-25 11:01:45 +08:00
handleSubmit(e) {
2024-01-23 17:05:40 +08:00
e.preventDefault()
if (!this.deptCheck) {
this.$message.error('不能选择父节点')
return
}
this.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values)
this.confirmLoading = true
saveUser(values).then(res => {
if (res.code === 0) {
this.$message.success('保存成功')
this.$emit('ok')
this.visible = false
} else {
this.$message.success(res.msg)
}
}).catch(() => {
this.$message.error('系统错误,请稍后再试')
}).finally(() => {
this.confirmLoading = false
})
}
})
}
}
}
</script>