| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <template>
- <div class="full-container-p24">
- <div style="display: flex; justify-content: space-between">
- <div style="display: flex">
- <el-input
- placeholder="请输入姓名/手机号"
- prefix-icon="el-icon-search"
- v-model="term"
- clearable
- style="height: 32px; width: 330px; line-height: 32px"
- ></el-input>
- <div class="seach-btn" @click="getSubAccountList">查询</div>
- </div>
- <el-button v-auth="'ADDACCOUNT'" type="primary" @click="showAddModal"
- >添加账号</el-button
- >
- </div>
- <el-dialog
- v-model="visable"
- :title="accountId ? '修改角色' : '添加账号'"
- width="550px"
- @close="resetForm()"
- >
- <template v-slot:default>
- <div class="df jcc">
- <el-form
- :model="ruleForm"
- :rules="rules"
- ref="form"
- label-width="110px"
- label-position="left"
- >
- <el-form-item prop="name" label="姓名">
- <el-input style="width: 280px" v-model="ruleForm.name"></el-input>
- </el-form-item>
- <el-form-item prop="phone" label="手机号">
- <el-input
- style="width: 280px"
- v-model="ruleForm.phone"
- ></el-input>
- </el-form-item>
- <el-form-item prop="deptId" label="部门">
- <el-select
- style="width: 280px"
- v-model="ruleForm.deptId"
- placeholder="请选择部门"
- @change="getRoleSelect"
- >
- <el-option
- v-for="item in departmentSelect"
- :key="item"
- :label="item.value"
- :value="item.key"
- />
- </el-select>
- </el-form-item>
- <el-form-item v-if="ruleForm.deptId" prop="roleId" label="角色">
- <el-select
- style="width: 280px"
- v-model="ruleForm.roleId"
- placeholder="请选择角色"
- >
- <el-option
- v-for="item in roleSelect"
- :key="item"
- :label="item.value"
- :value="item.key"
- />
- </el-select>
- </el-form-item>
- </el-form>
- </div>
- </template>
- <template v-slot:footer>
- <div class="dialog-footer">
- <el-button @click="resetForm">取 消</el-button>
- <el-button type="primary" @click="addSubAccount(ruleForm)">
- 确 定
- </el-button>
- </div>
- </template>
- </el-dialog>
- <div style="margin-top: 24px">
- <el-table :data="tableData" stripe style="width: 100%">
- <el-table-column
- type="index"
- label="序号"
- min-width="40"
- align="center"
- ></el-table-column>
- <el-table-column
- prop="userName"
- label="姓名"
- min-width="80"
- align="center"
- ></el-table-column>
- <el-table-column
- prop="phone"
- label="手机号"
- min-width="100"
- align="center"
- ></el-table-column>
- <el-table-column
- prop="password"
- label="密码"
- min-width="80"
- align="center"
- ></el-table-column>
- <el-table-column
- prop="deptName"
- label="部门"
- min-width="80"
- align="center"
- ></el-table-column>
- <el-table-column
- prop="roleName"
- label="角色权限"
- min-width="80"
- align="center"
- ></el-table-column>
- <el-table-column
- v-auth="'ADDACCOUNT'"
- label="操作"
- min-width="120"
- align="center"
- >
- <template v-slot="scope">
- <div class="df aic jcsa">
- <!-- <el-switch
- v-model="scope.row.accountStatus"
- active-color="#13ce66"
- inactive-color="#ff4949"
- active-text="启用"
- inactive-text="禁用"
- :active-value="1"
- :inactive-value="0"
- />
- <div
- style="
- color: red;
- margin-left: 10px;
- font-size: 14px;
- text-decoration: underline;
- cursor: pointer;
- "
- >
- 删除
- </div> -->
- <el-button
- @click="showUpdateModal(scope.row)"
- size="small"
- type="primary"
- >修改角色权限</el-button
- >
- </div>
- </template>
- </el-table-column>
- </el-table>
- <div style="width: 100%; text-align: right; margin-top: 43px">
- <el-pagination
- background
- layout="prev, pager, next"
- :total="total"
- @current-change="pageChange"
- ></el-pagination>
- </div>
- </div>
- </div>
- </template>
- <script setup>
- import api from "../../apis/fetch";
- import { ref, onMounted, reactive } from "vue";
- import { ElNotification, ElMessageBox } from "element-plus";
- import store from "../../store/index";
- let tableData = ref([]);
- let currentPage = ref(1);
- let total = ref(0);
- let term = ref("");
- let loginAccountId = ref(0);
- let accountId = ref("");
- let ruleForm = ref({
- name: "",
- phone: "",
- roleId: "",
- deptId: "",
- });
- const rules = reactive({
- name: [
- {
- required: true,
- message: "请填写名称",
- trigger: "blur",
- },
- ],
- phone: [
- {
- required: true,
- message: "请填写手机号",
- trigger: "blur",
- },
- ],
- roleId: [
- {
- required: true,
- message: "请选择角色",
- trigger: "blur",
- },
- ],
- deptId: [
- {
- required: true,
- message: "请选择部门",
- trigger: "blur",
- },
- ],
- });
- function showAddModal() {
- visable.value = true;
- ruleForm.value = {
- name: "",
- phone: "",
- roleId: "",
- deptId: "",
- };
- }
- async function getSubAccountList() {
- let res = await api.getSubAccountList({
- term: term.value,
- currentPage: currentPage.value,
- size: 10,
- loginAccountId: loginAccountId.value,
- });
- if (res.data.status == 0) {
- tableData.value = res.data.result;
- for (let i of tableData.value) {
- if (i.roleId == 0) {
- i.roleId = "";
- }
- }
- total.value = res.data.total;
- } else {
- tableData.value = [];
- total.value = 0;
- }
- }
- function pageChange(e) {
- currentPage.value = e;
- getSubAccountList();
- }
- let visable = ref(false);
- let form = ref(null);
- async function addSubAccount() {
- let postData = {
- ...ruleForm.value,
- loginAccountId: loginAccountId.value,
- };
- if (accountId.value) {
- postData.accountId = accountId.value;
- }
- let res = await api[accountId.value ? "updateSubAccount" : "addSubAccount"](
- postData
- );
- let status = res.data.status == 0;
- ElNotification({
- title: status ? "成功" : "失败",
- duration: 1500,
- message: res.data.msg,
- type: status ? "success" : "error",
- });
- store.dispatch("GetBasePermissionData", localStorage.loginAccountId);
- store.dispatch("GetUserPermission", localStorage.loginAccountId);
- resetForm();
- getSubAccountList();
- }
- function resetForm() {
- visable.value = false;
- accountId.value = "";
- form.value.resetFields();
- }
- function showUpdateModal(item) {
- visable.value = true;
- accountId.value = item.id;
- ruleForm.value = {
- name: item.userName,
- phone: item.phone,
- deptId: item.deptId,
- roleId: item.roleId,
- };
- getRoleSelect();
- }
- let roleSelect = ref([]);
- async function getRoleSelect() {
- roleSelect.value = [];
- if (!ruleForm.value.deptId) return;
- let res = await api.getRoleSelect({
- loginAccountId: loginAccountId.value,
- deptId: ruleForm.value.deptId,
- });
- roleSelect.value = res.data.result;
- }
- let departmentSelect = ref([]);
- async function getDepartmentSelect() {
- let res = await api.getDepartmentSelect({
- loginAccountId: loginAccountId.value,
- });
- departmentSelect.value = res.data.result;
- }
- onMounted(() => {
- loginAccountId.value = localStorage.loginAccountId;
- getSubAccountList();
- getDepartmentSelect();
- });
- </script>
- <style scoped>
- .seach-btn {
- display: inline-block;
- width: 60px;
- height: 38px;
- background: #0094fe;
- border-radius: 2px;
- font-size: 14px;
- font-family: PingFangSC-Regular, PingFang SC;
- font-weight: 400;
- color: #ffffff;
- text-align: center;
- line-height: 38px;
- margin-left: 10px;
- cursor: pointer;
- }
- </style>
|