石广澎
2024-01-02 0cd1631ceaa93e6483908fd692d2cb693b85324b
admin-web/src/views/systemManger/server/user/edit.vue
@@ -1,5 +1,5 @@
<template>
  <win-sm :title="setting.title" @close="close" :width="'800px'">
  <win-sm :title="setting.title" @close="close" :width="'800px'" :loading="loading">
    <el-alert
      style="margin-bottom: 10px"
      title="温馨提示:用户初始密码为123456"
@@ -13,13 +13,14 @@
      </el-form-item>
      <el-form-item label="部门" prop="sysDeptId">
        <el-select v-model="formData.sysDeptId">
            <el-option v-for="(item,index) in deptmentOptions" :key="index" :label="item.name" :value="item.id"></el-option>
          <el-option v-for="(item,index) in deptmentOptions" :key="index" :label="item.name"
                     :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="人员姓名" prop="userName">
        <el-input v-model="formData.userName" clearable maxlength="20" show-word-limit style="width: 250px"/>
      </el-form-item>
      <el-form-item label="员工编号" prop="userCode">
      <el-form-item label="登录名" prop="userCode">
        <el-input v-model="formData.userCode" clearable maxlength="20" show-word-limit style="width: 250px"/>
      </el-form-item>
      <el-form-item label="手机号" prop="userPhone">
@@ -86,8 +87,19 @@
            }
        },
        data() {
    // 参数1: rule 对象, 是校验规则, 一般不用
    // 参数2: value 校验项的数据
    // 参数3: callback 回调函数, 决定是否校验通过
    const checkedListCheck = (rule, value, callback) => {
      if (this.checkedList.length < 1) {
        callback(new Error('至少选择一个'))
      } else {
        callback()
      }
    }
            return {
                deptmentOptions:[],
      loading: true,
                checkAll: false,
                checkedList: [],
                roleList: [
@@ -127,7 +139,7 @@
                        {required: true, message: '请输入人员姓名', trigger: 'blur'}
                    ],
                    userCode: [
                        {required: true, message: '请输入员工编号', trigger: 'blur'}
          {required: true, message: '请输入登录名', trigger: 'blur'}
                    ],
                    userPhone: [
                        {required: true, message: '请输入手机号', trigger: 'blur'}
@@ -138,30 +150,28 @@
                    seq: [
                        {required: true, message: '请输入顺序号', trigger: 'blur'}
                    ],
        // 角色配置的验证
        roleSetting: [
          {validator: checkedListCheck, required: true, trigger: 'blur'},
        ],
                }
            }
        },
        created() {
            this.getInfo()
            this.getAllRole()
            this.getDeptmentOptions()
  async created() {
    this.title = this.setting.title
    if (this.setting.id != null) {
      await this.getInfo()
    }
    await this.getAllRole()
    await this.getDeptmentOptions()
    this.loading = false
        },
        methods: {
            // 获取所有角色
            getAllRole() {
              // const user = this.$store.getters.userInfo
              // this.data_scope = 1
              // if (user.lv == 1) {
              //   this.data_scope = 1
              // }
              // if (user.lv == 2) {
              //   this.data_scope = 2
              // }
              // if (user.lv == 3) {
              //   this.data_scope = 3
              // }
              this.data_scope = 1
              role.listRoleByDataScope({dataScope: this.data_scope}).then(response => {
    async getAllRole() {
      this.data_scope = this.$store.getters.userInfo ? this.$store.getters.userInfo.lv : ''
      await role.listRoleByDataScope({dataScope: this.setting.data_scope}).then(response => {
                  if (response) {
                    this.roleOptions = response;
                  } else {
@@ -171,8 +181,8 @@
                    }
                );
            },
            getDeptmentOptions(){
                departmentListAll({tenantId:this.setting.tenantId}).then(res=>{
    async getDeptmentOptions() {
      await departmentListAll({tenantId: this.setting.tenantId}).then(res => {
                    this.deptmentOptions = res
                })
            },
@@ -189,11 +199,10 @@
                let checkedCount = value.length;
                this.checkAll = checkedCount === this.roleOptions.length;
            },
            getInfo() {
    async getInfo() {
                this.title = this.setting.title
                if (this.setting.id != null) {
                    // 查询数据
                    user.getUser({id: this.setting.id}).then(res => {
      await user.getUser({id: this.setting.id}).then(res => {
                        const data = res.data
                        this.formData = Object.assign(this.formData, data)
                        if (this.formData.projectStart != null && this.formData.projectStart > 0) {
@@ -209,21 +218,18 @@
                            this.handleCheckedCitiesChange(res.list)
                        }
                    })
                }
            },
            close() {
                this.formData = {
                    projectName: '',
                    projectSubName: '',
                    projectCode: '',
                    projectContact: '',
                    projectTel: '',
                    projectEmail: '',
                    projectStart: null,
                    projectEnd: null,
                    projectDesc: '',
                    status: 1
                },
        sysDeptId: '',
        userName: '',
        userCode: '',
        userPhone: '',
        sex: 1,
        status: 1,
        remark: '',
        seq: null,
      }
                    this.$emit('close')
            },
            save() {
@@ -253,8 +259,11 @@
                            this.$message.error('服务开始时间和服务结束时间必须成对出现')
                            return
                        }
          if (this.loading) return;
          this.loading = true
                        if (params.id) {
                            user.upd(params).then(res => {
              this.loading = false
                                if (res) {
                                    this.$message.success('保存成功!')
                                    this.close()
@@ -262,9 +271,12 @@
                                } else {
                                    this.$message.error('保存失败')
                                }
            }).catch(() => {
              this.loading = false
                            })
                        } else {
                            user.add(params).then(res => {
              this.loading = false
                                if (res) {
                                    this.$message.success('保存成功!')
                                    this.close()
@@ -272,6 +284,8 @@
                                } else {
                                    this.$message.error('保存失败')
                                }
            }).catch(() => {
              this.loading = false
                            })
                        }
                    } else {