user.vue 10.4 KB
Newer Older
姜雷 committed
1
<template>
姜雷 committed
2
  <div class="manage-account main-wrap">
姜雷 committed
3 4
    <el-form class="search-bar">
      <div class="grid-content">
姜雷 committed
5
        <el-input v-model.trim="filters.name" :maxlength="20" placeholder="请输入姓名" clearable></el-input>
姜雷 committed
6 7
      </div>
      <div class="grid-content">
姜雷 committed
8
        <el-input v-model.trim="filters.department" :maxlength="20" placeholder="请输入科室" clearable></el-input>
姜雷 committed
9 10 11 12 13 14 15
      </div>
      <div class="grid-content">
        <el-select v-model="filters.isFrozen" filterable clearable placeholder="账号状态">
          <el-option v-for="item in accountStatusOptions" :key="item.id" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </div>
姜雷 committed
16 17
      <el-button type="primary" icon="el-icon-search" @click="searchList">搜索</el-button>
      <el-button class="margin-css" type="primary" icon="el-icon-upload" @click="showEditDialog(0)">新增</el-button>
姜雷 committed
18 19 20 21 22
    </el-form>
    <div class="tabel-wrap">
      <el-table border v-loading="loading" :data="userList" style="width: 100%">
        <el-table-column type="index" label="序号" width="50">
        </el-table-column>
姜雷 committed
23
        <el-table-column prop="name" label="姓名" min-width="80">
姜雷 committed
24
        </el-table-column>
姜雷 committed
25
        <el-table-column prop="department" label="部门科室" min-width="100">
姜雷 committed
26
        </el-table-column>
姜雷 committed
27
        <el-table-column prop="duty" label="职务" min-width="100">
姜雷 committed
28
        </el-table-column>
姜雷 committed
29
        <el-table-column prop="title" label="职称" min-width="80">
姜雷 committed
30
        </el-table-column>
姜雷 committed
31
        <el-table-column prop="sex" :formatter="getSexValue" label="性别" min-width="50">
姜雷 committed
32
        </el-table-column>
33
        <el-table-column prop="birthday" :formatter="(c,r,val) => val ? $formatDate(new Date(val),'yyyy-MM-dd') : ''" label="出生年月" min-width="80">
姜雷 committed
34
        </el-table-column>
姜雷 committed
35
        <el-table-column prop="cellphone" label="手机号" min-width="100">
姜雷 committed
36
        </el-table-column>
姜雷 committed
37
        <el-table-column fixed="right" label="操作" min-width="130" align="center">
姜雷 committed
38
          <template slot-scope="scope">
姜雷 committed
39 40
            <el-button type="primary" size="mini" class="operationBtnWidth" @click="showEditDialog(1, scope)">修改</el-button>
            <el-button type="primary" size="mini" class="operationBtnWidth" @click="toggleTeacherStatus(scope)">{{scope.row.isFrozen?'账户解冻':'账户冻结'}}</el-button>
姜雷 committed
41 42 43 44 45 46 47
          </template>
        </el-table-column>
      </el-table>
      <el-pagination layout="prev, pager, next" :current-page="pagination.pageNum" :page-size="pagination.pageSize" :total="pagination.total" @current-change="changePage">
      </el-pagination>
    </div>
    <!-- 新增/编辑账号 -->
姜雷 committed
48
    <drag-dialog :title="editType ? '编辑用户' : '新增用户'" :visible.sync="dialogEditVisible" :before-close="resetEditDialog" width="70%">
姜雷 committed
49 50 51
      <el-form class="editForm" :disabled="loading">
        <el-form-item class="editItem" label="姓名" label-width="100px">
          <el-input v-model.trim="selected.name" placeholder="请输入姓名" :maxlength="20" clearable></el-input>
姜雷 committed
52
        </el-form-item>
姜雷 committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        <el-form-item class="editItem" label="部门科室" label-width="100px">
          <el-input v-model.trim="selected.department" placeholder="请输入部门科室" :maxlength="20" clearable></el-input>
        </el-form-item>
        <el-form-item class="editItem" label="职务" label-width="100px">
          <el-input v-model.trim="selected.duty" placeholder="请输入职务" :maxlength="20" clearable></el-input>
        </el-form-item>
        <el-form-item class="editItem" label="职称" label-width="100px">
          <el-input v-model.trim="selected.title" placeholder="请输入职称" :maxlength="20" clearable></el-input>
        </el-form-item>
        <el-form-item class="editItem" label="性别" label-width="100px">
          <el-radio v-for="(sex, index) in sexOptions" :key="index" v-model="selected.sex" :label="sex.value">{{sex.label}}</el-radio>
        </el-form-item>
        <el-form-item class="editItem" label="出生年月" label-width="100px">
          <el-date-picker v-model="selected.birthday" type="date" placeholder="请输入出生年月" clearable>
          </el-date-picker>
        </el-form-item>
        <el-form-item class="editItem" label="工号" label-width="100px">
姜雷 committed
70
          <el-input v-model.trim="selected.jobNumber" placeholder="请输入工号" :maxlength="8" clearable></el-input>
姜雷 committed
71 72 73
        </el-form-item>
        <el-form-item class="editItem" label="手机号" label-width="100px">
          <el-input v-model="selected.cellphone" ref="telInput" :maxlength="11" placeholder="请输入手机号" clearable></el-input>
姜雷 committed
74 75 76 77
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetEditDialog">取 消</el-button>
姜雷 committed
78
        <el-button type="primary" @click="updateTeacher">确 定</el-button>
姜雷 committed
79 80 81 82 83 84
      </div>
    </drag-dialog>
  </div>
</template>

<script>
姜雷 committed
85
import listMixin from '@/mixin/listPage.js';
姜雷 committed
86 87
import { mapGetters, mapActions } from 'vuex';
import store from './store.js';
姜雷 committed
88 89 90 91 92 93
import {
  addTeacher,
  updateTeacher,
  toggleTeacherStatus,
} from '@/api/management/user.js';
import { sexOptions } from '@/config';
姜雷 committed
94 95 96 97 98 99

export default {
  beforeRouteEnter(to, from, next) {
    store.install();
    next();
  },
姜雷 committed
100
  mixins: [listMixin],
姜雷 committed
101 102 103 104 105 106 107
  data() {
    return {
      filters: {
        name: '',
        department: '',
        isFrozen: '',
      },
姜雷 committed
108
      selected: {},
姜雷 committed
109 110 111 112 113 114 115 116 117 118
      accountStatusOptions: [
        {
          label: '解冻',
          value: 0,
        },
        {
          label: '冻结',
          value: 1,
        },
      ],
姜雷 committed
119
      sexOptions: sexOptions,
姜雷 committed
120 121 122 123 124 125 126
    };
  },
  computed: {
    ...mapGetters('management/user', ['userList', 'pagination']),
    ...mapGetters(['loading']),
  },
  methods: {
姜雷 committed
127
    ...mapActions('management/user', { fetchList: 'fetchUserList' }),
姜雷 committed
128
    ...mapActions(['fetchAllAuthUserList']),
姜雷 committed
129 130 131 132 133 134 135
    initfilters() {
      this.filters = {
        name: '',
        department: '',
        isFrozen: '',
      };
    },
姜雷 committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    initSelected() {
      this.selected = {
        userId: '',
        name: '',
        department: '',
        duty: '',
        title: '',
        sex: '',
        birthday: '',
        jobNumber: '',
        cellphone: '',
      };
    },
    getSexValue(c, r, val) {
      let item = this.sexOptions.find(item => item.value == val);
      return item ? item.label : val;
    },
    getFilters() {
      let filters = {
        ...this.$getFilters(this.filters),
        isFrozen: this.filters.isFrozen,
      };
      return filters;
姜雷 committed
159 160 161 162 163
    },
    showEditDialog(type, data) {
      this.editType = type;
      if (type) {
        this.selected = {
姜雷 committed
164 165 166 167 168 169 170 171 172
          userId: data.row.userId,
          name: data.row.name,
          department: data.row.department,
          duty: data.row.duty,
          title: data.row.title,
          sex: data.row.sex,
          birthday: data.row.birthday,
          jobNumber: data.row.jobNumber,
          cellphone: data.row.cellphone,
姜雷 committed
173 174
        };
      } else {
姜雷 committed
175
        this.initSelected();
姜雷 committed
176 177 178
      }
      this.dialogEditVisible = true;
    },
姜雷 committed
179 180 181 182 183 184 185 186 187
    validateSelect() {
      if (!this.selected.name) {
        this.$message.error('请输入姓名!');
        return;
      }
      if (!this.selected.department) {
        this.$message.error('请输入部门科室!');
        return;
      }
188 189 190 191 192 193 194 195
      // if (!this.selected.duty) {
      //   this.$message.error('请输入职务!');
      //   return;
      // }
      // if (!this.selected.title) {
      //   this.$message.error('请输入职称!');
      //   return;
      // }
姜雷 committed
196 197 198 199
      if (!this.selected.sex) {
        this.$message.error('请输入性别!');
        return;
      }
200 201 202 203
      // if (!this.selected.birthday) {
      //   this.$message.error('请输入出生年月!');
      //   return;
      // }
姜雷 committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
      return true;
    },
    formatCellphone(val) {
      return val.replace(/\D/g, '');
    },
    updateCellphone(val) {
      console.log(this.$refs.telInput);
      // this.selected.cellphone = val.replace(/\D/g, '');
      this.$refs.telInput.value = val.replace(/\D/g, '');
    },
    updateTeacher() {
      if (!this.validateSelect()) {
        return;
      }
      const entity = {
        userId: this.selected.userId,
        name: this.selected.name,
        department: this.selected.department,
        duty: this.selected.duty,
        title: this.selected.title,
        sex: this.selected.sex,
        birthday: this.selected.birthday,
        jobNumber: this.selected.jobNumber,
        cellphone: this.selected.cellphone,
      };
姜雷 committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
      this.$confirm(`确认要${this.editType ? '编辑' : '新增'}吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          if (this.editType) {
            updateTeacher(entity)
              .then(res => {
                this.fetchList();
                this.resetEditDialog();
                this.$message.success(res.msg);
              })
              .catch(err => {
                this.$message.error(err.msg || '更新失败!');
              });
          } else {
            addTeacher(entity)
              .then(res => {
                this.fetchList();
                this.fetchAllAuthUserList();
                this.resetEditDialog();
                this.$message.success(res.msg);
              })
              .catch(err => {
                this.$message.error(err.msg || '新增失败!');
              });
          }
        })
        .catch(action => {
          console.log(action);
        });
姜雷 committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
    },
    toggleTeacherStatus(data) {
      this.$confirm(
        `确认要${data.row.isFrozen ? '解冻' : '冻结'} ${data.row.name} 吗?`,
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }
      )
        .then(() => {
          const entity = {
            userId: data.row.userId,
            isFrozen: data.row.isFrozen ? 0 : 1,
          };
          toggleTeacherStatus(entity)
            .then(res => {
              this.fetchList();
              this.$message.success(res.msg);
            })
            .catch(err => {
              this.$message.error('删除失败!');
            });
        })
        .catch(action => {
          console.log(action);
        });
    },
姜雷 committed
290 291 292
  },
};
</script>
姜雷 committed
293 294 295 296 297 298 299 300 301 302 303 304

<style lang="scss">
.manage-account {
  .editForm {
    display: flex;
    flex-wrap: wrap;
  }
  .editItem {
    width: 45%;
  }
}
</style>