//组件 var Usercomponent = { template: `
搜索 新增
取 消 确 定
`, data() { // 获取当前屏幕的分辨率 let screenW = window.screen.width; let screenH = window.innerHeight; console.log("screen width:", screenW); console.log("screen height:", screenH); return { tHeight: screenH - 40 - 232, tableData: [], input: '', currentPage: 1, pagesize: 50, recordTotal: 0, form: { id: '', username: '', password: '', role: '', department: '', state: '', }, dialogVisible: false, oper_type: 0, rules: { username: [ { required: true, message: '用户不可为空', trigger: 'blur' } ], password: [ { required: true, message: '密码不可为空', trigger: 'blur' } ], role: [ { required: true, message: '用户角色不可为空', trigger: 'blur' } ], state: [ { required: true, message: '用户状态不可为空', trigger: 'blur' } ] }, state_dis: false, } }, mounted() { var _this = this; var objs; axios.post('/pp/getUsers', { opuser: localStorage.getItem("online_user"), opuser_uuid: localStorage.getItem("uuid"), id: '', index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, methods: { handleCheckboxChange(row) { var flag = row.if_buyer; if (flag == 0) { flag = 1 } else { flag = 0 } var _this = this; var objs; axios.post('/pp/update_user_buyer', { opuser: localStorage.getItem("online_user"), opuser_uuid: localStorage.getItem("uuid"), id: row.userid, if_buyer: flag, }) .then(function (response) { let r = response.data.r; let s = "" let errType = "" if (r == 0) { errType = "success" // 操作日志 if (flag == 1) { _this.add_operation_log("设置" + row.username + "为采购人员"); } else { _this.add_operation_log("取消" + row.username + "为采购人员"); } } else { errType = "error" } if (r == 0) { s = "修改用户成功!"; } else { s = "修改用户失败!"; } _this.$message({ message: s, type: errType, duration: 1500 }); //更新页面 _this.getUser(_this.$data.input); }) .catch(function (error) { console.log(error); }); }, input_change(value) { console.log(value); this.getUser(this.$data.input); }, postUser() { this.$refs['userform'].validate((valid) => { if (valid) { this.$data.dialogVisible = false; var _this = this; console.log(_this.$data.form); var objs; axios.post('/pp/postUser', { opuser: localStorage.getItem("online_user"), opuser_uuid: localStorage.getItem("uuid"), id: _this.$data.form.id, username: _this.$data.form.username, password: _this.$data.form.password, role: _this.$data.form.role, department: _this.$data.form.department, oper_type: _this.$data.oper_type, state: _this.$data.form.state, if_buyer: 0 }) .then(function (response) { let r = response.data.r; let s = "" let errType = "" if (r == 0) { errType = "success" } else { errType = "error" } if (_this.$data.oper_type == 1) { if (r == 0) { s = "新增用户成功!"; // 操作日志 _this.add_operation_log("新增用户:" + _this.$data.form.username); } else if (r == 1) { s = "已存在相同用户名!"; } else { s = "新增用户失败!"; } } else if (_this.$data.oper_type == 2) { if (r == 0) { s = "修改用户成功!"; _this.add_operation_log("修改用户:" + _this.$data.form.username); } else { s = "修改用户失败!"; } } _this.$message({ message: s, type: errType, duration: 1500 }); //更新页面 _this.getUser(_this.$data.input); }) .catch(function (error) { console.log(error); }); } }); }, delUser(userinfo) { this.$data.oper_type = 3; var _this = this; var objs; axios.post('/pp/postUser', { opuser: localStorage.getItem("online_user"), opuser_uuid: localStorage.getItem("uuid"), id: userinfo.userid, username: userinfo.username, password: userinfo.password, role: userinfo.rolename, department: userinfo.user_department, oper_type: _this.$data.oper_type }) .then(function (response) { let r = response.data.r; let s = "" let errType = "" if (r == 0) { s = "删除用户成功!"; errType = "success" // 操作日志 // _this.add_operation_log("删除用户:" + userinfo.username); } else { s = "删除用户失败!"; errType = "error" } _this.$message({ message: s, type: errType, duration: 1500 }); if (r == 0) { _this.getUser("");//更新页面 } }) .catch(function (error) { console.log(error); }); }, addUser() { document.getElementById("bt_add").blur(); this.$data.oper_type = 1; this.$data.form = { id: '', username: '', password: '', role: '', department: '', state: '状态1' }; this.$data.state_dis = true; this.$nextTick(() => { this.$refs['userform'].clearValidate() }); this.$data.dialogVisible = true; }, updateUser(userinfo) { this.$data.oper_type = 2; this.$data.form = { id: userinfo.userid, username: userinfo.username, password: userinfo.password, role: userinfo.rolename, department: userinfo.department, state: userinfo.state, }; this.$data.state_dis = false; this.$nextTick(() => { this.$refs['userform'].clearValidate() }); this.$data.dialogVisible = true; }, getUser(_search_name) { document.getElementById("bt_search").blur(); this.$data.currentPage = 1; var _this = this; var objs; axios.post('/pp/getUsers', { opuser: localStorage.getItem("online_user"), opuser_uuid: localStorage.getItem("uuid"), id: _search_name, index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, handleSizeChange(val) { this.$data.pagesize = val; var _this = this; var objs; axios.post('/pp/getUsers', { opuser: localStorage.getItem("online_user"), opuser_uuid: localStorage.getItem("uuid"), id: this.$data.input, index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, handleCurrentChange(val) { this.$data.currentPage = val; var _this = this; var objs; axios.post('/pp/getUsers', { opuser: localStorage.getItem("online_user"), opuser_uuid: localStorage.getItem("uuid"), id: this.$data.input, index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, // 根据内容设置列表宽度 flexColumnWidth(str, arr1, fontNum = 4, flag = 'max') { return window.flexColumnWidth(str, arr1, fontNum, flag); }, // 操作日志 add_operation_log(operation) { axios.post('/pp/add_operation_log', { opuser: localStorage.getItem("online_user"), opuser_uuid: localStorage.getItem("uuid"), operation: operation, }).then(function (response) { console.log(response); }).catch(function (error) { console.log(error); }) } } }