quanyawei
2023-09-27 ea9f9a9f6dc6dc88f3916d1d25a0cb3be436d1ba
src/views/personnel/index.vue
@@ -13,7 +13,11 @@
            border
            style="width: 100%"
            :stripe="true"
          >
          ><el-table-column
             prop="unitId"
             label="责任单位"
             :formatter="unitIdFormatter"
           />
            <el-table-column
              prop="account"
              label="员工账号"
@@ -80,6 +84,16 @@
        <el-form-item label="员工名称" :label-width="formLabelWidth" prop="userName">
          <el-input v-model="form.userName" autocomplete="off" />
        </el-form-item>
        <el-form-item label="责任单位" :label-width="formLabelWidth">
          <el-select v-model="form.unitId" placeholder="请选择" size="small" style="width: 100%;">
            <el-option
              v-for="item in unitList"
              :key="item.unitId"
              :label="item.unitName"
              :value="item.unitId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="手机" :label-width="formLabelWidth" prop="mobile">
          <el-input v-model="form.mobile" autocomplete="off" />
        </el-form-item>
@@ -114,6 +128,16 @@
        </el-form-item>
        <el-form-item label="员工名称" :label-width="formLabelWidth" prop="userName">
          <el-input v-model="formEdit.userName" autocomplete="off" />
        </el-form-item>
        <el-form-item label="责任单位" :label-width="formLabelWidth">
          <el-select v-model="formEdit.unitId" placeholder="请选择" size="small" style="width: 100%;">
            <el-option
              v-for="item in unitList"
              :key="item.unitId"
              :label="item.unitName"
              :value="item.unitId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="手机" :label-width="formLabelWidth" prop="mobile">
          <el-input v-model="formEdit.mobile" autocomplete="off" />
@@ -190,6 +214,7 @@
    // 这里存放数据
    return {
      options: [],
      unitList: [],
      radio1: '',
      value: '',
      value1: '',
@@ -202,6 +227,7 @@
      dialogEdit: false,
      dialogRole: false,
      form: {
        unitId: '',
        account: '',
        password: '',
        userName: '',
@@ -212,6 +238,7 @@
      },
      formEdit: {
        id: 0,
        unitId: '',
        account: '',
        password: '',
        userName: '',
@@ -260,6 +287,7 @@
  },
  // 生命周期 - 创建完成(可以访问当前 this 实例)
  created() {
    this.getUnitList()
    this.personnelList()
    this.roleList()
  },
@@ -282,6 +310,7 @@
      this.form.account = ''
      this.form.password = ''
      this.form.userName = ''
      this.form.unitId = ''
      this.form.mobile = ''
      this.form.email = ''
      this.form.wechat = ''
@@ -314,6 +343,19 @@
        })
      })
    },
    unitIdFormatter(val) {
      const data = this.unitList.find(item => item && item.unitId === val.unitId)
      return data ? data.unitName : ''
    },
    // 获取责任单位list
    getUnitList() {
      this.$request({
        url: '/allocation/unit',
        method: 'get'
      }).then((res) => {
        this.unitList = res.data
      })
    },
    // 新建员工方法
    personnelAdd() {
      if (this.form.account && this.form.password && this.form.userName) {
@@ -324,6 +366,7 @@
            account: this.form.account,
            password: this.$encrypt(this.form.password),
            userName: this.form.userName,
            unitId: Number(this.form.unitId),
            mobile: this.form.mobile,
            email: this.form.email,
            wechat: this.form.wechat,
@@ -384,6 +427,7 @@
      this.form.id = row.id
      this.form.account = row.account
      this.form.userName = row.userName
      this.form.unitId = row.unitId
      this.form.mobile = row.mobile
      this.form.email = row.email
      this.form.wechat = row.wechat
@@ -394,6 +438,7 @@
      this.formEdit.userName = ''
      this.formEdit.mobile = ''
      this.formEdit.email = ''
      this.formEdit.unitId = ''
      this.formEdit.wechat = ''
      this.formEdit.expireTime = ''
      this.formEdit.password = ''
@@ -403,7 +448,7 @@
    // 编辑员工方法
    personnelEdit() {
      // return
      if (this.formEdit.userName !== this.form.userName || this.formEdit.password !== this.form.password || this.formEdit.mobile !== this.form.mobile || this.formEdit.wechat !== this.form.wechat || this.formEdit.email !== this.form.email || this.formEdit.expireTime !== this.form.expireTime) {
      if (this.formEdit.unitId !== this.form.unitId || this.formEdit.userName !== this.form.userName || this.formEdit.password !== this.form.password || this.formEdit.mobile !== this.form.mobile || this.formEdit.wechat !== this.form.wechat || this.formEdit.email !== this.form.email || this.formEdit.expireTime !== this.form.expireTime) {
        this.$request({
          url: '/user/update',
          method: 'post',
@@ -412,6 +457,7 @@
            password: this.formEdit.password ? this.$encrypt(this.formEdit.password) : null,
            userName: this.formEdit.userName ? this.formEdit.userName : null,
            mobile: this.formEdit.mobile ? this.formEdit.mobile : null,
            unitId: Number(this.formEdit.unitId) ? Number(this.formEdit.unitId) : null,
            email: this.formEdit.email ? this.formEdit.email : null,
            wechat: this.formEdit.wechat ? this.formEdit.wechat : null,
            expireTime: this.formEdit.expireTime ? this.formEdit.expireTime : null