123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <template>
- <el-dialog
- :title="!dataForm.id ? '新增' : '修改'"
- :close-on-click-modal="false"
- :visible.sync="visible">
- <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
- <el-form-item label="用户名" prop="userName">
- <el-input v-model="dataForm.userName" :disabled="dataForm.id !== 0" placeholder="登录帐号"></el-input>
- </el-form-item>
- <el-form-item label="姓名" prop="name">
- <el-input v-model="dataForm.name" :disabled="dataForm.id !== 0" placeholder="姓名"></el-input>
- </el-form-item>
- <el-form-item label="密码" prop="password" :class="{ 'is-required': !dataForm.id }">
- <el-input v-model="dataForm.password" type="password" placeholder="密码"></el-input>
- </el-form-item>
- <el-form-item label="确认密码" prop="confirmPassword" :class="{ 'is-required': !dataForm.id }">
- <el-input v-model="dataForm.confirmPassword" type="password" placeholder="确认密码"></el-input>
- </el-form-item>
- <el-form-item label="所属机构" prop="orgId">
- <org-component v-model="dataForm.orgId" @orgSelected="validateField('orgId')"/>
- </el-form-item>
- <el-form-item label="邮箱" prop="email">
- <el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
- </el-form-item>
- <el-form-item label="手机号" prop="mobile">
- <el-input v-model="dataForm.mobile" placeholder="手机号"></el-input>
- </el-form-item>
- <el-form-item label="角色" size="mini" prop="roleIdList">
- <el-checkbox-group v-model="dataForm.roleIdList">
- <el-checkbox v-for="role in roleList" :key="role.roleId" :label="role.roleId">{{ role.roleName }}</el-checkbox>
- </el-checkbox-group>
- </el-form-item>
- <el-form-item label="状态" size="mini" prop="status">
- <el-radio-group v-model="dataForm.status">
- <el-radio :label="0">禁用</el-radio>
- <el-radio :label="1">正常</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="visible = false">取消</el-button>
- <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
- </span>
- </el-dialog>
- </template>
- <script>
- import { isEmail, isMobile } from '@/utils/validate'
- import OrgComponent from '../common/org-component'
- export default {
- components: {OrgComponent},
- data () {
- let validatePassword = (rule, value, callback) => {
- if (!this.dataForm.id && !/\S/.test(value)) {
- callback(new Error('密码不能为空'))
- } else {
- callback()
- }
- }
- let validateConfirmPassword = (rule, value, callback) => {
- if (!this.dataForm.id && !/\S/.test(value)) {
- callback(new Error('确认密码不能为空'))
- } else if (this.dataForm.password !== value) {
- callback(new Error('确认密码与密码输入不一致'))
- } else {
- callback()
- }
- }
- let validateEmail = (rule, value, callback) => {
- if (value !== '' && !isEmail(value)) {
- callback(new Error('邮箱格式错误'))
- } else {
- callback()
- }
- }
- let validateMobile = (rule, value, callback) => {
- if (!isMobile(value)) {
- callback(new Error('手机号格式错误'))
- } else {
- callback()
- }
- }
- return {
- visible: false,
- roleList: [],
- orgList: [],
- dataForm: {
- id: 0,
- userName: '',
- name: '',
- password: '',
- confirmPassword: '',
- salt: '',
- email: '',
- mobile: '',
- roleIdList: [],
- status: 1,
- orgId: ''
- },
- dataRule: {
- userName: [
- { required: true, message: '用户名不能为空', trigger: 'blur' }
- ],
- password: [
- { validator: validatePassword, trigger: 'blur' }
- ],
- confirmPassword: [
- { validator: validateConfirmPassword, trigger: 'blur' }
- ],
- email: [
- { validator: validateEmail, trigger: 'blur' }
- ],
- name: [
- { required: true, message: '手机号不能为空', trigger: 'blur' }
- ],
- mobile: [
- { required: true, message: '手机号不能为空', trigger: 'blur' },
- { validator: validateMobile, trigger: 'blur' }
- ],
- orgId: [
- { required: true, message: '所属机构不能为空', trigger: 'blur' }
- ]
- }
- }
- },
- methods: {
- init (id) {
- this.dataForm.id = id || 0
- this.$http({
- url: this.$http.adornUrl('/user-service/role/listAll'),
- method: 'get',
- params: this.$http.adornParams()
- }).then(({data}) => {
- if (data.code === '200') {
- this.roleList = data && data.code === '200' ? data.data : []
- } else {
- this.$message.error(data.msg)
- }
- }).then(() => {
- this.visible = true
- this.$nextTick(() => {
- this.$refs['dataForm'].resetFields()
- })
- }).then(() => {
- if (this.dataForm.id) {
- this.$http({
- url: this.$http.adornUrl(`/user-service/user/info/${this.dataForm.id}`),
- method: 'get',
- params: this.$http.adornParams()
- }).then(({data}) => {
- if (data && data.code === '200') {
- this.dataForm.userName = data.data.username
- this.dataForm.salt = data.data.salt
- this.dataForm.email = data.data.email
- this.dataForm.mobile = data.data.mobile
- this.dataForm.roleIdList = data.data.roleIdList
- this.dataForm.status = Number(data.data.status)
- this.dataForm.name = data.data.name
- this.dataForm.orgId = data.data.orgId
- }
- })
- }
- })
- },
- // 表单提交
- dataFormSubmit () {
- this.$refs['dataForm'].validate((valid) => {
- if (valid) {
- this.$http({
- url: this.$http.adornUrl(`/user-service/user/${!this.dataForm.id ? 'save' : 'update'}`),
- method: !this.dataForm.id ? 'post' : 'put',
- data: this.$http.adornData(!this.dataForm.id ? {
- 'userId': undefined,
- 'username': this.dataForm.userName,
- 'password': this.dataForm.password,
- // 'salt': this.dataForm.salt,
- 'email': this.dataForm.email,
- 'mobile': this.dataForm.mobile,
- 'status': this.dataForm.status,
- 'roleIdList': this.dataForm.roleIdList,
- 'name': this.dataForm.name,
- 'orgId': this.dataForm.orgId
- } : {
- 'userId': this.dataForm.id,
- 'password': this.dataForm.password,
- 'email': this.dataForm.email,
- 'mobile': this.dataForm.mobile,
- 'status': this.dataForm.status,
- 'roleIdList': this.dataForm.roleIdList,
- 'name': this.dataForm.name,
- 'orgId': this.dataForm.orgId
- })
- }).then(({data}) => {
- if (data && data.code === '200') {
- this.$message({
- message: '操作成功',
- type: 'success',
- duration: 1500,
- onClose: () => {
- this.visible = false
- this.$emit('refreshDataList')
- }
- })
- } else {
- this.$message.error(data.msg)
- }
- })
- }
- })
- },
- validateField (type) {
- this.$refs.dataForm.validateField(type)
- }
- }
- }
- </script>
|