var _this, dataObj=[], _Tok = null; new Vue({ el: '#app', data: function() { return { parentName: { deptName: "请选择", deptId: null }, defaultProps: { children: 'children', label: 'label' }, tableData: [], nowForm:{ postIds: [], roleIds: [] }, dialogVisible:false, inpKey:"", sexOptions:[], postOptions:[], deptOptions :[], roleOptions:[], readonlyInput: true, pwdDialog:false, pwdInfo:{ userId:null, newPwd:"", pwdName:null }, loading: false, curPage: 1, allTotal: 0, } }, created() { _this = this; _Tok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : ""; _this.reSet(); _this.getList(); _this.getSex(); _this.getTree(); }, methods: { cancelReadOnly() { _this.readonlyInput= false; }, getList() { _this.loading = true; let data1 = { pageNum:_this.curPage, pageSize:20 }; let _opts = { url: baseUrl + "/system/user/list", type:"GET" }; let _head = { "Authorization":"Bearer "+_Tok }; getAxios(_opts, data1, _head) .then(function(res) { if (res.code == 200) { _this.tableData = res.rows; _this.allTotal = res.total; dataObj = res.rows; }else{ _this.$message.error(res.msg); } _this.loading = false; }) }, handleCurrentChange(val) { if(val != _this.curPage){ _this.curPage = val; _this.getList(); } }, getSex(){ let data1 = {}; let _head = { "Authorization":"Bearer "+_Tok }; let _opts = { url: baseUrl + "/system/dict/data/type/sys_user_sex", type:"GET" }; getAxios(_opts, data1,_head) .then(function(res) { if (res.code == 200) { _this.sexOptions = res.data; } }) }, getTree(){ let data1 = {}; let _opts = { url: baseUrl + "/system/dept/treeselect", type:"GET" }; let _head = { "Authorization":"Bearer "+_Tok }; getAxios(_opts, data1,_head) .then(function(res) { if (res.code == 200) { _this.deptOptions = res.data; } }) }, Search(_key){ let newArr = [],_ovj = dataObj; if(_key == ""){ newArr = dataObj; }else{ for(var i=0;i<_ovj.length;i++){ if( JSON.stringify(_ovj[i]).indexOf(_key) != -1){ newArr.push(_ovj[i]) } } } _this.tableData = newArr; }, reSet() { _this.nowForm = { deptId: 0, userName: "", nickName: "", password: "", phonenumber: "", email: "", sex: "2", status: "0", remark: "", postIds: [], roleIds: [], userId: null }; }, newAdd(){ let data1 = {}; let _opts = { url: baseUrl + "/system/user/", type:"GET" }; let _head = { "Authorization":"Bearer "+_Tok }; getAxios(_opts, data1,_head) .then(function(res) { if (res.code == 200) { _this.postOptions = res.posts; _this.roleOptions = res.roles; _this.parentName = { deptName: _this.deptOptions[0].label, deptId: _this.deptOptions[0].id }; _this.reSet(); _this.dialogVisible = true; } }) }, Edit(_row){ let data1 = {}; let _opts = { url: baseUrl + "/system/user/" + _row.userId, type:"GET" }; let _head = { "Authorization":"Bearer "+_Tok }; getAxios(_opts, data1,_head) .then(function(res) { if (res.code == 200) { _this.nowForm = res.data; if(res.data.deptId == null){ _this.parentName = { deptName: _this.deptOptions[0].label, deptId: _this.deptOptions[0].id }; }else{ _this.parentName = res.data.dept; } _this.postOptions = res.posts; _this.roleOptions = res.roles; _this.nowForm.postIds = res.postIds; _this.nowForm.roleIds = res.roleIds; _this.dialogVisible = true; } }) }, Delete(_row){ _this.$confirm('是否确认删除编号为"'+_row.userId+'"的数据项?', '温馨提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { let data1 = {}; let _opts = { url: baseUrl + "/system/user/"+_row.userId, type:"DELETE" }; let _head = { "Authorization":"Bearer "+_Tok }; getAxios(_opts, data1,_head) .then(function(res) { if(res.code == 200){ _this.$message({ type: 'success', message: '删除成功!' }); _this.getList(); }else{ _this.$message.error(res.msg); } }) }).catch(() => { }); }, RePwd(_row){ if(_row.userId != null&&_row.userId != undefined){ _this.pwdInfo.pwdName = _row.nickName; _this.pwdInfo.userId = _row.userId; _this.pwdDialog = true; } }, conPwd(){ if(_this.pwdInfo.newPwd == ""){ _this.$message({ type: 'warning', message: "请输入新密码" }); return; } let data1 = JSON.stringify({ password: _this.pwdInfo.newPwd, userId: _this.pwdInfo.userId }); let _opts = { url:baseUrl + "/system/user/resetPwd", type: "PUT" }; let _head = { "Authorization":"Bearer "+_Tok, "Content-Type": 'application/json; charset=UTF-8', }; postAxios(_opts,data1,_head) .then(function(res){ if(res.code == 200){ _this.$message({ type: 'success', message: '操作成功!' }); _this.pwdDialog = false; }else{ _this.$message.error(res.msg); } }) }, conFirm(){ if(_this.nowForm.nickName == ""){ _this.$message({ type: 'warning', message: "请输入用户昵称" }); return; } if(_this.nowForm.userName == ""&&_this.nowForm.userId == undefined){ _this.$message({ type: 'warning', message: "请输入用户账号" }); return; } if(_this.nowForm.password == ""&&_this.nowForm.userId == undefined){ _this.$message({ type: 'warning', message: "请输入密码" }); return; } if(!_this.nowForm.roleIds.length){ _this.$message({ type: 'warning', message: "请选择用户角色" }); return; } if(_this.nowForm.phonenumber != ""&&_this.nowForm.phonenumber != null&&(!(/^1[3456789]\d{9}$/.test(_this.nowForm.phonenumber)))){ _this.$message({ type: 'warning', message: '请输入正确的手机号码', }) return; } if(_this.nowForm.email != ""&&_this.nowForm.email != null&&(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(_this.nowForm.email)))){ _this.$message({ type: 'warning', message: '请输入正确的邮箱格式', }) return; } _this.nowForm.deptId = _this.parentName.deptId; let data1 = JSON.stringify(_this.nowForm); let _opts = { url:baseUrl + "/system/user", type: _this.nowForm.userId == null?"POST":"PUT" }; let _he = { "Authorization":"Bearer "+_Tok, "Content-Type": 'application/json; charset=UTF-8', }; postAxios(_opts,data1,_he) .then(function(res){ if(res.code == 200){ _this.$message({ type: 'success', message: '操作成功!' }); _this.getList(); _this.dialogVisible = false; }else{ _this.$message.error(res.msg); } }) }, nodeClick(_e){ _this.parentName = { deptName: _e.label, deptId: _e.id }; this.$refs.conSelect.blur(); }, clearSel(_row){ _this.nowForm[_row] = []; } } })