account.vue 11.8 KB
Newer Older
姜雷 committed
1
<template>
姜雷 committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  <div class="system-account main-wrap">
    <el-form class="search-bar">
      <div class="grid-content">
        <el-input v-model.trim="filters.name" placeholder="请输入姓名" clearable></el-input>
      </div>
      <div class="grid-content">
        <el-input v-model.trim="filters.department" placeholder="请输入科室" clearable></el-input>
      </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>
      <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>
    </el-form>
    <div class="tabel-wrap">
      <el-table border v-loading="loading" :data="list" style="width: 100%">
        <el-table-column type="index" label="序号" width="50">
        </el-table-column>
        <el-table-column prop="name" label="姓名" min-width="120">
        </el-table-column>
        <el-table-column prop="department" label="部门科室" min-width="120">
        </el-table-column>
        <el-table-column prop="cellphone" label="手机号" min-width="120">
        </el-table-column>
        <el-table-column prop="sex" :formatter="getSexValue" label="性别" min-width="120">
        </el-table-column>
        <el-table-column prop="account" label="登陆账号" min-width="120">
        </el-table-column>
        <el-table-column prop="isFrozen" :formatter="getStatusValue" label="状态" min-width="120">
        </el-table-column>
        <el-table-column fixed="right" label="操作" min-width="80" align="center">
          <template slot-scope="scope">
            <el-dropdown trigger="click">
              <el-button type="primary" size="mini">
                <i class="el-icon-setting"></i>
              </el-button>
              <el-dropdown-menu class="AccountIndex" slot="dropdown">
                <el-dropdown-item>
                  <el-button type="primary" size="mini" class="operationBtnWidth" @click="showEditDialog(1, scope)">修改</el-button>
                </el-dropdown-item>
                <el-dropdown-item>
                  <el-button type="primary" size="mini" class="operationBtnWidth" @click="showUserAuth(scope)">授权</el-button>
                </el-dropdown-item>
                <el-dropdown-item>
                  <el-button type="primary" size="mini" class="operationBtnWidth" @click="showResetUserPwd(scope)">重置密码</el-button>
                </el-dropdown-item>
                <el-dropdown-item>
                  <el-button type="primary" size="mini" class="operationBtnWidth" @click="freezeUser(scope)">{{scope.row.isFrozen?'账户解冻':'账户冻结'}}</el-button>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </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>
    <drag-dialog class="rateDialog" :title="editType?'修改':'新增'" :visible.sync="dialogEditVisible" :before-close="resetEditDialog">
      <el-form :disabled="loading">
        <el-form-item label="姓名" label-width="200px">
          <el-input v-model.trim="selected.name" placeholder="请输入姓名" :maxlength="20" clearable></el-input>
        </el-form-item>
        <el-form-item label="部门科室" label-width="200px">
姜雷 committed
68
          <el-input v-model.trim="selected.department" placeholder="请输入部门科室" :maxlength="20" clearable></el-input>
姜雷 committed
69 70 71
        </el-form-item>
        <el-form-item label="登陆账号" label-width="200px">
          <span v-if="editType">{{selected.account}}</span>
姜雷 committed
72
          <el-input v-else v-model.trim="selected.account" placeholder="请输入登陆账号" :maxlength="20" clearable></el-input>
姜雷 committed
73 74
        </el-form-item>
        <el-form-item label="手机号" label-width="200px">
姜雷 committed
75
          <el-input :value="selected.cellphone" @change="updateCellphone" type="number" placeholder="请输入手机号" clearable></el-input>
姜雷 committed
76 77
        </el-form-item>
        <el-form-item label="性别" label-width="200px">
姜雷 committed
78
          <el-radio v-for="(sex, index) in sexOptions" :key="index" v-model="selected.sex" :label="sex.value">{{sex.label}}</el-radio>
姜雷 committed
79 80 81 82 83 84 85
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetEditDialog">取 消</el-button>
        <el-button type="primary" @click="updateAccount">确 定</el-button>
      </div>
    </drag-dialog>
姜雷 committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99
    <drag-dialog class="rateDialog" title="权限" :visible.sync="dialogAuthVisible" :before-close="resetAuthDialog">
      <el-checkbox-group class="menuList" v-model="selected.menuList">
        <div class="menuItem" v-for="(menu, index) in menuList" :key="index">
          <div class="menuName">{{menu.menuName}}</div>
          <div class="subMenuList">
            <el-checkbox class="subMenuItem" v-for="(subMenu, index) in menu.childList" :key="index" :label="subMenu.id">{{subMenu.menuName}}</el-checkbox>
          </div>
        </div>
      </el-checkbox-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetAuthDialog">取 消</el-button>
        <el-button type="primary" @click="updateUserAuth">确 定</el-button>
      </span>
    </drag-dialog>
姜雷 committed
100
  </div>
姜雷 committed
101
</template>
姜雷 committed
102 103 104 105 106 107 108 109 110 111 112

<script>
import listMixin from '../../../mixin/listPage.js';
import { accountStatusOptions } from '@/config';
import { mapGetters, mapActions } from 'vuex';
import store from './store.js';
import {
  resetPwd,
  toggleUserFreezeState,
  addAccount,
  updateAccount,
姜雷 committed
113 114 115
  fetchMenuList,
  fetchUserMenuList,
  updateUserAuthMenu,
姜雷 committed
116
} from '@/api/system/account';
姜雷 committed
117
import { sexOptions } from '@/config';
姜雷 committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

export default {
  beforeRouteEnter(to, from, next) {
    store.install();
    next();
  },
  mixins: [listMixin],
  data() {
    return {
      filters: {
        name: '',
        department: '',
        isFrozen: '',
      },
      accountStatusOptions: accountStatusOptions,
姜雷 committed
133 134
      dialogAuthVisible: false,
      menuList: [],
姜雷 committed
135
      sexOptions: sexOptions,
姜雷 committed
136 137 138 139 140 141 142 143 144 145 146 147
    };
  },
  computed: {
    ...mapGetters('system/account', {
      list: 'accountList',
      pagination: 'pagination',
    }),
  },
  methods: {
    ...mapActions('system/account', { fetchList: 'fetchList' }),
    initSelected() {
      this.selected = {
姜雷 committed
148
        id: '',
姜雷 committed
149 150 151 152 153
        name: '',
        account: '',
        department: '',
        cellphone: '',
        sex: '',
姜雷 committed
154
        menuList: [],
姜雷 committed
155 156 157
      };
    },
    getSexValue(c, r, val) {
姜雷 committed
158 159
      let item = this.sexOptions.find(item => item.value == val);
      return item ? item.label : val;
姜雷 committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 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 229 230 231 232 233 234 235 236
    },
    getStatusValue(c, r, val) {
      let item = this.accountStatusOptions.find(item => item.value == val);
      return item ? item.label : val;
    },
    showEditDialog(type, data) {
      this.editType = type;
      if (type) {
        this.selected = {
          id: data.row.id,
          name: data.row.name,
          account: data.row.account,
          department: data.row.department,
          cellphone: data.row.cellphone,
          sex: data.row.sex,
        };
      } else {
        this.initSelected();
      }
      this.dialogEditVisible = true;
    },
    showResetUserPwd(data) {
      this.$confirm(`是否要重置密码?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          const entity = {
            id: data.row.id,
          };
          resetPwd(entity)
            .then(res => {
              this.fetchList();
              this.$message.success('密码已重置为123456!');
            })
            .catch(err => {
              this.$message.error('重置密码失败!');
            });
        })
        .catch(action => {
          console.log(action);
        });
    },
    freezeUser(data) {
      this.$confirm(
        `确认要${data.row.isFrozen ? '解冻' : '冻结'} ${data.row.name} 用户吗?`,
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }
      )
        .then(() => {
          const entity = {
            id: data.row.id,
            isFrozen: data.row.isFrozen ? 0 : 1,
          };
          toggleUserFreezeState(entity)
            .then(res => {
              this.fetchList();
              this.$message.success(res.msg);
            })
            .catch(err => {
              this.$message.error('冻结/解冻失败!');
            });
        })
        .catch(action => {
          console.log(action);
        });
    },
    validateSelect() {
      if (!this.selected.name) {
        this.$message.error('请输入姓名!');
        return;
      }
姜雷 committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
      if (!this.selected.department) {
        this.$message.error('请选择部门科室!');
        return;
      }
      if (!this.selected.account) {
        this.$message.error('请选择登陆账号!');
        return;
      }
      if (!this.selected.cellphone) {
        this.$message.error('请输入手机号!');
        return;
      }
      if (this.selected.cellphone.length !== 11) {
        this.$message.error('请输入正确手机号!');
        return;
      }
      if (!this.selected.sex) {
        this.$message.error('请选择性别!');
姜雷 committed
255 256 257 258
        return;
      }
      return true;
    },
姜雷 committed
259 260 261 262
    updateCellphone(val) {
      console.log(val);
      this.selected.cellphone = val.slice(0, 11);
    },
姜雷 committed
263 264 265 266
    updateAccount() {
      if (!this.validateSelect()) {
        return;
      }
姜雷 committed
267 268 269 270 271 272 273 274
      const entity = {
        id: this.selected.id,
        account: this.selected.account,
        name: this.selected.name,
        department: this.selected.department,
        cellphone: this.selected.cellphone,
        sex: this.selected.sex,
      };
姜雷 committed
275 276
      if (this.editType) {
        updateAccount(entity)
姜雷 committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
          .then(res => {
            this.fetchList();
            this.resetEditDialog();
            this.$message.success(res.msg);
          })
          .catch(err => {
            this.$message.error(err.msg || '更新失败!');
          });
      } else {
        addAccount(entity)
          .then(res => {
            this.fetchList();
            this.resetEditDialog();
            this.$message.success(res.msg);
          })
          .catch(err => {
            this.$message.error(err.msg || '新增失败!');
          });
姜雷 committed
295 296
      }
    },
姜雷 committed
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
    showUserAuth(data) {
      if (this.menuList.length == 0) {
        fetchMenuList().then(res => {
          this.menuList = res.data;
        });
      }
      fetchUserMenuList({
        id: data.row.id,
      })
        .then(res => {
          this.selected = {
            id: data.row.id,
            menuList: res.data,
          };
          this.dialogAuthVisible = true;
        })
        .catch(err => {
          this.$message.error(err.msg || '请求失败');
        });
    },
    resetAuthDialog(done) {
      this.selected = {};
      done && typeof done == 'function'
        ? done()
        : (this.dialogAuthVisible = false);
    },
    updateUserAuth() {
      const entity = {
        id: this.selected.id,
        author: this.selected.menuList.join(','),
      };
      updateUserAuthMenu(entity)
        .then(res => {
          this.$message.success(res.msg);
          this.resetAuthDialog();
        })
        .catch(err => {
          this.$message.success(err.msg || '更新失败!');
        });
    },
姜雷 committed
337 338 339
  },
};
</script>
姜雷 committed
340 341 342 343 344

<style lang="scss">
.system-account {
  .menuItem {
    padding: 5px 24px;
姜雷 committed
345
    border-bottom: 1px solid #ccc;
姜雷 committed
346 347
  }
  .menuName {
姜雷 committed
348
    margin: 20px 0 5px;
姜雷 committed
349 350 351 352 353 354 355
    font-size: 18px;
  }
  .subMenuList {
    line-height: 40px;
  }
}
</style>