| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683 |
- <template>
- <div id="usermanagement">
- <el-row :gutter="20">
- <el-col :span="4">
- <el-input
- v-model="filterText"
- size="small"
- placeholder="请输入内容"
- clearable
- prefix-icon="el-icon-search"
- ></el-input>
- <el-tree
- class="filter-tree"
- :data="dataDs"
- :props="defaultProps"
- default-expand-all
- :filter-node-method="filterNode"
- ref="tree"
- :expand-on-click-node="false"
- @node-click="getTreeDepart"
- >
- </el-tree>
- </el-col>
- <el-col :span="20">
- <search-box :formList="formList" @search="search" @init="init" />
- <table-list
- :tableSets="tableSet"
- :tableData="tableData"
- :navText="navText"
- @addClick="addClick"
- :loading="loading"
- >
- <template slot="btn" slot-scope="props">
- <!-- <el-button type="text" @click="addClick(props.scope.row, 2)"
- >详情</el-button
- > -->
- <el-button type="text" @click="addClick(props.scope.row, 0)"
- >修改</el-button
- >
- <el-button type="text" @click="del(props.scope.row)"
- >删除</el-button
- >
- <el-button type="text" @click="Reset(props.scope.row)"
- >重置</el-button
- >
- </template>
- </table-list>
- <pagination
- :total="total"
- :pageSize="pageSize"
- :currentPage="currentPage"
- @handleSizeChange="handleSizeChange"
- @handleCurrentChange="handleCurrentChange"
- />
- <el-dialog
- :visible.sync="dialogVisible"
- width="560px"
- :show-close="false"
- :close-on-click-modal="false"
- >
- <div slot="title" class="hearders">
- <div class="leftTitle">
- {{ statusPop === 1 ? "添加" : statusPop === 0 ? "修改" : "详情" }}
- </div>
- <div class="rightBoxs">
- <img src="@/assets/images/Close@2x.png" alt="" @click="close" />
- </div>
- </div>
- <div>
- <el-form
- label-position="right"
- label-width="80px"
- :model="listData"
- :rules="rules"
- ref="listData"
- >
- <el-form-item
- v-for="(items, indexs) in listitem"
- :key="indexs"
- :label="items.label"
- :prop="items.prop"
- >
- <el-radio-group
- v-if="items.scope === 'status'"
- v-model="listData[items.prop]"
- >
- <el-radio
- v-for="(item, index) in items.options"
- :key="index"
- :label="item.value"
- :disabled="statusPop === 2"
- >{{ item.label }}</el-radio
- >
- </el-radio-group>
- <treeselect
- v-else-if="items.scope === 'selectMore'"
- v-model="listData[items.prop]"
- :options="dataDs"
- :show-count="true"
- placeholder="选择上级菜单"
- />
- <el-input
- :disabled="statusPop === 2"
- v-else-if="items.scope === 'textarea'"
- type="textarea"
- v-model="listData[items.prop]"
- ></el-input>
- <el-select
- v-else-if="items.scope === 'moreSelect'"
- v-model="listData[items.prop]"
- multiple
- placeholder="请选择"
- >
- <el-option
- v-for="item in items.options"
- :key="item[items.option.value]"
- :label="item[items.option.label]"
- :value="item[items.option.value]"
- >
- </el-option>
- </el-select>
- <el-select
- v-else-if="items.scope === 'select'"
- v-model="listData[items.prop]"
- placeholder="请选择"
- >
- <el-option
- v-for="item in items.options"
- :key="item[items.option.value]"
- :label="item[items.option.label]"
- :value="item[items.option.value]"
- >
- </el-option>
- </el-select>
- <el-input
- :disabled="statusPop === 2 || statusPop === 0"
- v-else-if="items.scope === 'userNames'"
- v-model="listData[items.prop]"
- ><template slot="append">登入账号</template></el-input
- >
- <el-input
- :disabled="statusPop === 2"
- v-else
- v-model="listData[items.prop]"
- ></el-input>
- </el-form-item>
- </el-form>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button @click="close">取 消</el-button>
- <el-button
- type="primary"
- v-if="statusPop !== 2"
- @click="submit('listData')"
- >确 定</el-button
- >
- </span>
- </el-dialog>
- </el-col>
- </el-row>
- </div>
- </template>
- <script>
- import Treeselect from "@riophae/vue-treeselect";
- import "@riophae/vue-treeselect/dist/vue-treeselect.css";
- import searchBox from "@/components/searchBox";
- import tableList from "@/components/tableList";
- import pagination from "@/components/pagination";
- export default {
- components: { Treeselect, searchBox, tableList, pagination },
- data() {
- return {
- loading: false, //当前表单加载是否加载动画
- navText: {
- title: "用户信息",
- index: 0,
- ch: "条",
- num: false,
- choice: true,
- addHide: false,
- backFatherBtn: {
- status: false,
- title: "未定义",
- },
- },
- filterText: "",
- dataDs: [],
- defaultProps: {
- children: "children",
- label: "label",
- },
- deptId: "",
- //搜索
- formList: [
- {
- label: "用户名称",
- prop: "userName",
- placeholder: "请输入用户名称",
- },
- {
- label: "手机号码",
- prop: "phonenumber",
- placeholder: "请输入手机号码",
- },
- {
- label: "状态",
- prop: "status",
- placeholder: "请选择状态",
- scope: "select",
- options: [
- {
- label: "启用",
- value: 1,
- },
- {
- label: "停用",
- value: 0,
- },
- ],
- },
- ],
- // 表单
- tableSet: [
- {
- label: "用户编号",
- prop: "userId",
- hidden: true,
- },
- {
- label: "用户名称",
- prop: "userName",
- hidden: true,
- },
- {
- label: "用户昵称",
- prop: "nickName",
- hidden: true,
- },
- {
- label: "部门",
- prop: "deptName",
- hidden: true,
- },
- {
- label: "手机号码",
- prop: "phonenumber",
- hidden: true,
- },
- {
- label: "状态",
- prop: "status",
- hidden: true,
- scope: "status",
- },
- ],
- tableData: [], //表单数据
- optionsCascader: [], //弹窗分类数据
- total: 0, //一共多少条
- pageSize: 10, //每页多少条数据
- currentPage: 1, //当前页码
- // 弹窗字段
- listitem: [
- {
- label: "归属部门",
- prop: "deptId",
- scope: "selectMore",
- },
- {
- label: "用户名称",
- prop: "userName",
- scope: "userNames",
- },
- {
- label: "用户昵称",
- prop: "nickName",
- },
- {
- label: "手机号码",
- prop: "phonenumber",
- },
- {
- label: "邮箱",
- prop: "email",
- },
- {
- label: "用户性别",
- prop: "sex",
- scope: "select",
- option: {
- label: "dictLabel",
- value: "dictCode",
- },
- options: [],
- },
- {
- label: "状态",
- prop: "status",
- scope: "status",
- options: [
- {
- label: "启用",
- value: "1",
- },
- {
- label: "关闭",
- value: "0",
- },
- ],
- },
- {
- label: "岗位",
- prop: "postIds",
- option: {
- label: "postName",
- value: "postId",
- },
- options: [],
- scope: "moreSelect",
- show: true,
- },
- {
- label: "角色",
- prop: "roleIds",
- option: {
- label: "roleName",
- value: "roleId",
- },
- options: [],
- scope: "moreSelect",
- show: true,
- },
- {
- label: "备注",
- prop: "remark",
- scope: "textarea",
- },
- ],
- listData: {},
- statusPop: -1,
- dialogVisible: false,
- //表单验证
- rules: {
- deptId: [
- { required: true, message: "请选择归属部门", trigger: "blur" },
- ],
- userName: [
- { required: true, message: "请输入用户名称", trigger: "blur" },
- ],
- nickName: [
- { required: true, message: "请输入用户昵称", trigger: "blur" },
- ],
- phonenumber: [
- { required: true, message: "请输入手机号码", trigger: "blur" },
- ],
- email: [{ required: true, message: "请输入邮箱", trigger: "blur" }],
- sex: [{ required: true, message: "请选择性别", trigger: "change" }],
- status: [{ required: true, message: "请选择状态", trigger: "change" }],
- postIds: [{ required: true, message: "请选择岗位", trigger: "change" }],
- roleIds: [{ required: true, message: "请选择角色", trigger: "change" }],
- remark: [{ required: true, message: "请填写备注", trigger: "blur" }],
- },
- };
- },
- watch: {
- filterText(val) {
- this.$refs.tree.filter(val);
- },
- },
- mounted() {
- this.search();
- this.initTree();
- },
- methods: {
- //重置密码
- Reset(v) {
- this.$prompt("请输入新密码", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- })
- .then(({ value }) => {
- var data = {
- deptId: v.deptId,
- userName: v.userName,
- nickName: v.nickName,
- userId: v.userId,
- password: value,
- };
- this.$api.editUser(data).then((res) => {
- if (res.code === 200) {
- this.$message({
- type: "success",
- message: "密码已重置",
- });
- this.search();
- }
- });
- })
- .catch(() => {
- this.$message({
- type: "info",
- message: "取消输入",
- });
- });
- },
- // 获取部门
- initTree() {
- var data = {
- statusArray: "0,1",
- };
- this.$api.obtainDeptTreeselect(data).then((res) => {
- this.dataDs = res.data;
- });
- },
- // 对树节点进行筛选时执行的方法
- filterNode(value, data) {
- if (!value) return true;
- return data.label.indexOf(value) !== -1;
- },
- //点击菜单栏
- getTreeDepart(options) {
- this.deptId = options.id;
- this.search();
- },
- //搜索
- search(v) {
- this.loading = true;
- if (v === undefined) {
- v = {
- statusArray: "0,1",
- pageSize: this.pageSize,
- pageNum: this.currentPage,
- };
- }
- var data = {
- deptId: this.deptId || "",
- userName: v.userName || "",
- phonenumber: v.phonenumber || "",
- statusArray: v.status === undefined ? "0,1" : v.status,
- pageSize: this.pageSize,
- pageNum: this.currentPage,
- };
- this.$api.obtainUserList(data).then((res) => {
- this.tableData = res.rows;
- this.total = res.total;
- this.navText.index = res.total;
- res.rows.forEach((item, index) => {
- if (item.dept) {
- this.tableData[index].deptName = item.dept.deptName;
- }
- });
- });
- this.loading = false;
- },
- //重置
- init() {
- this.search();
- },
- //删除用户信息
- del(v) {
- this.$confirm("此操作将删除该用户信息, 是否继续?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- var data = {
- deptId: v.deptId,
- userName: v.userName,
- nickName: v.nickName,
- userId: v.userId,
- status: "-1",
- };
- this.$api.editUser(data).then((res) => {
- if (res.code === 200) {
- this.$message.success("删除成功");
- this.search();
- }
- });
- })
- .catch(() => {
- this.$message({
- type: "info",
- message: "已取消删除",
- });
- });
- },
- //初始数据
- getOptionsRole() {
- var data = {
- statusArray: "0,1",
- };
- this.$api.inquiresystempostList(data).then((res) => {
- this.listitem.forEach((item, index) => {
- if (item.prop === "postIds") {
- item.options = res.rows;
- }
- });
- });
- this.$api.obtainRoleList(data).then((res) => {
- this.listitem.forEach((item, index) => {
- if (item.prop === "roleIds") {
- item.options = res.rows;
- }
- });
- });
- var arays = [];
- arays = this.$store.state.UserDict.filter((item, index) => {
- return item.dictType == "sys_user_sex";
- });
- this.listitem.forEach((item, index) => {
- if (item.label === "用户性别") {
- item.options = arays;
- }
- });
- },
- //开启窗口
- addClick(v, int) {
- this.getOptionsRole();
- if (v === undefined) {
- this.statusPop = 1;
- this.listData = {};
- } else {
- this.statusPop = int;
- var data = v.userId;
- this.$api.obtainUserDetails(data).then((res) => {
- this.listData = res.data;
- this.listData.roleIds = res.roleIds;
- this.listData.postIds = res.postIds;
- this.listData.sex = Number(res.data.sex);
- });
- }
- this.$nextTick(()=>{
- this.$refs.listData.clearValidate();
- })
- this.dialogVisible = true;
- },
- //表单验证
- submit(formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- this.rulesTableSumbit();
- } else {
- return false;
- }
- });
- },
- //提交表单
- rulesTableSumbit() {
- if (this.statusPop === 1) {
- this.$api.addUser(this.listData).then((res) => {
- if (res.code === 200) {
- this.search();
- this.$message.success("新增成功");
- this.dialogVisible = false;
- this.resetForm();
- }
- });
- }
- if (this.statusPop === 0) {
- this.$api.editUser(this.listData).then((res) => {
- if (res.code === 200) {
- this.search();
- this.$message.success("修改成功");
- this.dialogVisible = false;
- this.resetForm();
- }
- });
- }
- },
- // 关闭窗口
- close() {
- this.dialogVisible = false;
- this.resetForm();
- },
- //重置表单验证
- resetForm() {
- this.$refs["listData"].resetFields();
- },
- handleSizeChange(v) {
- this.pageSize = v;
- this.currentPage = 1;
- this.search();
- },
- handleCurrentChange(v) {
- this.currentPage = v;
- this.search();
- },
- },
- };
- </script>
- <style lang="less" scoped>
- /deep/.el-button {
- border-radius: 8px;
- }
- /deep/.el-dialog {
- border-radius: 8px;
- .el-dialog__header {
- padding: 0;
- .hearders {
- height: 40px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0px 18px 0px 20px;
- border-bottom: 1px solid #e2e2e2;
- .leftTitle {
- font-size: 14px;
- font-weight: bold;
- color: #2f4378;
- }
- .rightBoxs {
- display: flex;
- align-items: center;
- img {
- width: 14px;
- height: 14px;
- margin-left: 13px;
- cursor: pointer;
- }
- }
- }
- }
- .el-dialog__footer {
- padding: 0;
- .dialog-footer {
- padding: 0px 40px;
- height: 70px;
- border-top: 1px solid #e2e2e2;
- display: flex;
- align-items: center;
- justify-content: flex-end;
- }
- }
- }
- .imgBox {
- width: 100%;
- // height: 210px;
- border: 1px solid #e2e2e2;
- border-radius: 8px;
- padding: 8px 8px 3px;
- display: flex;
- flex-direction: column;
- align-items: center;
- .imgLabel {
- flex: 1;
- width: 100%;
- border: 1px dotted #e2e2e2;
- color: #999;
- font-size: 14px;
- cursor: pointer;
- border-radius: 8px;
- .msPhoto {
- display: flex;
- justify-content: center;
- align-items: center;
- max-width: 100%;
- max-height: 270px;
- img {
- max-width: 100%;
- max-height: 270px;
- }
- }
- .imgbbx {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 100%;
- i {
- font-weight: bold;
- margin: 14px 0;
- font-size: 24px;
- }
- }
- }
- p {
- margin: 5px 0px;
- }
- }
- </style>
|