Преглед на файлове

修改公司、部门、岗位、员工的修改添加验证

wangh преди 2 години
родител
ревизия
b4bab0575b
променени са 4 файла, в които са добавени 348 реда и са изтрити 299 реда
  1. 122 109
      src/components/system/Company.vue
  2. 92 85
      src/components/system/Department.vue
  3. 79 60
      src/components/system/JobPost.vue
  4. 55 45
      src/components/system/User.vue

+ 122 - 109
src/components/system/Company.vue

@@ -152,14 +152,12 @@ export default {
     data() {
         var isnumber = (rule, value, callback) => {
             debugger
-            var reg = "^[1]+[2,3,4,5,6,7,8,9]+\d{9}";//小数点左边最高16位,小数点右边最多4位
+            var reg = /^1[3456789]\d{9}$/;//小数点左边最高16位,小数点右边最多4位
             if (reg.test(value)) {
                 callback();
-            } else if (value == "" && value == null && value == undefined) {
-                callback(new Error("请输入加价百分比"));
-            } else {
-                callback(new Error("输入正确的数字,小数点后可1到2位"));
-            }
+            } else
+                callback(new Error("请输入正确的手机号"));
+
 
         };
         return {
@@ -216,7 +214,7 @@ export default {
                     { required: true, message: '公司地址不能为空', trigger: 'change' }
                 ],
                 ContactUserId: [
-                    { required: true, message: '公司地址不能为空', trigger: 'change' }
+                    { required: true, message: '负责人不能为空', trigger: 'change' }
                 ],
                 Tel: [
                     { validator: isnumber, message: '请输入正确的手机号', trigger: 'change' }
@@ -295,50 +293,57 @@ export default {
         upDateBtn() {
             debugger
             var that = this
-            if (that.updata.Id != 0) {
-                if (that.updata.CompanyName == "" || that.updata.CompanyName == undefined) {
-                    that.$message.error("公司名称不能为空");
-                    return
-                }
-                if (that.updata.CompanyCode == "") {
-                    that.$message.error("公司code不能为空");
-                    return
-                }
-                if (that.updata.Address == "") {
-                    that.$message.error("公司地址不能为空");
-                    return
-                }
-                if (that.updata.ContactUserId == 0) {
-                    that.$message.error("请选择公司负责人");
-                    return
-                }
+            that.$refs.updata.validate((valid) => {
+                if (valid) {
 
-                debugger;
-                var url = "http://localhost:5256/api/System/EditCompany"
-                var that = this
-                that.$axios({
-                    method: 'post',
-                    url: url,
-                    headers: {
-                        Authorization: 'Bearer ' + that.token
-                    },
-                    data: that.updata
-                }).then(function (res) {
-                    console.log(res)
-                    debugger
-                    if (res.data.code == 200) {
-                        that.$message({
-                            message: '修改成功!',
-                            type: 'success'
-                        });
-                        that.upDataVisible = false
-                        that.company();
-                    } else {
-                        that.$message.error('保修改失败!');
-                    }
-                })
-            }
+                    if (that.updata.Id != 0) {
+                        if (that.updata.CompanyName == "" || that.updata.CompanyName == undefined) {
+                            that.$message.error("公司名称不能为空");
+                            return
+                        }
+                        if (that.updata.CompanyCode == "") {
+                            that.$message.error("公司code不能为空");
+                            return
+                        }
+                        if (that.updata.Address == "") {
+                            that.$message.error("公司地址不能为空");
+                            return
+                        }
+                        if (that.updata.ContactUserId == 0) {
+                            that.$message.error("请选择公司负责人");
+                            return
+                        }
 
+                        debugger;
+                        var url = "http://localhost:5256/api/System/EditCompany"
+                        var that = this
+                        that.$axios({
+                            method: 'post',
+                            url: url,
+                            headers: {
+                                Authorization: 'Bearer ' + that.token
+                            },
+                            data: that.updata
+                        }).then(function (res) {
+                            console.log(res)
+                            debugger
+                            if (res.data.code == 200) {
+                                that.$message({
+                                    message: '修改成功!',
+                                    type: 'success'
+                                });
+                                that.upDataVisible = false
+                                that.company();
+                            } else {
+                                that.$message.error('保修改失败!');
+                            }
+                        })
+                    }
+                } else {
+                    this.$message.error('请完善信息在保存!');
+                    return false;
+                }
+            })
         },
         //关闭修改框
         handleClose(done) {
@@ -390,71 +395,79 @@ export default {
             this.addDataVisible = true
 
         },
+
         addDateBtn() {
             debugger
-            var that = this
-            this.adddata.ContactUserId = this.valueUserValue
-            this.adddata.ParentCompanyId = this.valueCompanyValue
-            this.adddata.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
-            if (that.adddata.CompanyName == "" || that.updata.CompanyName == undefined) {
-                that.$message.error("公司名称不能为空");
-                return
-            }
-            if (that.adddata.CompanyCode == "") {
-                that.$message.error("公司code不能为空");
-                return
-            }
-            if (that.adddata.Address == "") {
-                that.$message.error("公司地址不能为空");
-                return
-            }
-            if (that.adddata.ContactUserId == 0) {
-                that.$message.error("请选择公司负责人");
-                return
-            }
-            if (that.adddata.Tel == "") {
-                that.$message.error("请输入手机号");
-                return
-            } else {
-                var reg = /^1[3456789]\d{9}$/;
-                if (!reg.test(that.adddata.Tel)) {
-                    that.$message.error("请输入有效的手机号");
-                    return
-                }
-            }
+            this.$refs.adddata.validate((valid) => {
+                if (valid) {
+                    var that = this
+                    this.adddata.ContactUserId = this.valueUserValue
+                    this.adddata.ParentCompanyId = this.valueCompanyValue
+                    this.adddata.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
+                    if (that.adddata.CompanyName == "" || that.updata.CompanyName == undefined) {
+                        that.$message.error("公司名称不能为空");
+                        return
+                    }
+                    if (that.adddata.CompanyCode == "") {
+                        that.$message.error("公司code不能为空");
+                        return
+                    }
+                    if (that.adddata.Address == "") {
+                        that.$message.error("公司地址不能为空");
+                        return
+                    }
+                    if (that.adddata.ContactUserId == 0) {
+                        that.$message.error("请选择公司负责人");
+                        return
+                    }
+                    if (that.adddata.Tel == "") {
+                        that.$message.error("请输入手机号");
+                        return
+                    } else {
+                        var reg = /^1[3456789]\d{9}$/;
+                        if (!reg.test(that.adddata.Tel)) {
+                            that.$message.error("请输入有效的手机号");
+                            return
+                        }
+                    }
 
-            var url = "http://localhost:5256/api/System/AddCompany"
+                    var url = "http://localhost:5256/api/System/AddCompany"
 
-            that.$axios({
-                method: 'post',
-                url: url,
-                headers: {
-                    Authorization: 'Bearer ' + that.token
-                },
-                data: that.adddata
-            }).then(function (res) {
-                console.log(res)
-                debugger
-                if (res.data.code == 200) {
-                    that.$message({
-                        message: '添加成功!',
-                        type: 'success'
-                    });
-                    debugger
-                    that.addDataVisible = false;
-                    that.adddata.CreateUserId = 0
-                    that.adddata.CompanyCode = ""
-                    that.adddata.CompanyName = ""
-                    that.adddata.Address = ""
-                    that.adddata.ContactUserId = 0
-                    that.adddata.Tel = ""
-                    that.adddata.ParentCompanyId = 0
-                    that.adddata.Remark = ""
-                    that.valueUserValue = 0
-                    that.valueCompanyValue = 0
-                    that.company();
+                    that.$axios({
+                        method: 'post',
+                        url: url,
+                        headers: {
+                            Authorization: 'Bearer ' + that.token
+                        },
+                        data: that.adddata
+                    }).then(function (res) {
+                        console.log(res)
+                        debugger
+                        if (res.data.code == 200) {
+                            that.$message({
+                                message: '添加成功!',
+                                type: 'success'
+                            });
+                            debugger
+                            that.addDataVisible = false;
+                            that.adddata.CreateUserId = 0
+                            that.adddata.CompanyCode = ""
+                            that.adddata.CompanyName = ""
+                            that.adddata.Address = ""
+                            that.adddata.ContactUserId = 0
+                            that.adddata.Tel = ""
+                            that.adddata.ParentCompanyId = 0
+                            that.adddata.Remark = ""
+                            that.valueUserValue = 0
+                            that.valueCompanyValue = 0
+                            that.company();
+                        } else {
+                            that.$message.error('添加失败!');
+                        }
+                    })
                 } else {
-                    that.$message.error('添加失败!');
+                    this.$message.error('请完善信息在保存!');
+                    return false;
                 }
             })
         },

+ 92 - 85
src/components/system/Department.vue

@@ -135,7 +135,7 @@ export default {
             upDepVisible: false,
             upData: {
                 Id: 0,
-                CompanyId: 0,
+                CompanyId: '',
                 DepCode: "",
                 DepName: "",
                 ParentDepId: 0,
@@ -143,7 +143,7 @@ export default {
             },
             //添加参数
             addData: {
-                CompanyId: 0,
+                CompanyId: '',
                 DepCode: "",
                 DepName: "",
                 ParentDepId: 0,
@@ -158,20 +158,14 @@ export default {
                 DepName: [
                     { required: true, message: '请输入部门名称', trigger: 'blur' },
                 ],
-                CompanyValue: [
+                CompanyId: [
                     { required: true, message: '请选择所属公司', trigger: 'change' }
                 ],
             },
-            optionsDepartment: [{
-                value: 0,
-                label: '请选择上级部门'
-            }],
-            ParentDepId: 0,
-            optionsCompanys: [{
-                value: 0,
-                label: '请选择所属公司'
-            }],
-            CompanyId: 0
+            optionsDepartment: [],
+            ParentDepId: '',
+            optionsCompanys: [],
+            CompanyId: ''
         }
     },
     methods: {
@@ -299,43 +293,49 @@ export default {
         upDateBtn() {
             debugger
             var that = this
-            that.upData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
-            if (that.upData.DepName == "" || that.upData.DepName == undefined) {
-                that.$message.error("部门名称不能为空");
-                return
-            }
-            if (that.upData.DepCode == "") {
-                that.$message.error("部门code不能为空");
-                return
-            }
-            if (that.upData.CompanyId == 0) {
-                that.$message.error("请选择所属公司");
-                return
-            }
-            var url = "http://localhost:5256/api/System/EditDepartment"
+            this.$refs.upData.validate((valid) => {
+                if (valid) {
+                    that.upData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
+                    if (that.upData.DepName == "" || that.upData.DepName == undefined) {
+                        that.$message.error("部门名称不能为空");
+                        return
+                    }
+                    if (that.upData.DepCode == "") {
+                        that.$message.error("部门code不能为空");
+                        return
+                    }
+                    if (that.upData.CompanyId == 0) {
+                        that.$message.error("请选择所属公司");
+                        return
+                    }
+                    var url = "http://localhost:5256/api/System/EditDepartment"
 
-            that.$axios({
-                method: 'post',
-                url: url,
-                headers: {
-                    Authorization: 'Bearer ' + that.token
-                },
-                data: that.upData
-            }).then(function (res) {
-                console.log(res)
-                debugger
-                if (res.data.code == 200) {
-                    that.$message({
-                        message: '修改成功',
-                        type: 'success'
-                    });
-                    that.upDepVisible = false;
-                    that.Department();
+                    that.$axios({
+                        method: 'post',
+                        url: url,
+                        headers: {
+                            Authorization: 'Bearer ' + that.token
+                        },
+                        data: that.upData
+                    }).then(function (res) {
+                        console.log(res)
+                        debugger
+                        if (res.data.code == 200) {
+                            that.$message({
+                                message: '修改成功',
+                                type: 'success'
+                            });
+                            that.upDepVisible = false;
+                            that.Department();
+                        } else {
+                            that.$message.error('修改失败!');
+                        }
+                    })
                 } else {
-                    that.$message.error('修改失败!');
+                    this.$message.error('请完善信息在保存!');
+                    return false;
                 }
             })
-
         },
         //关闭修改框
         handleClose(done) {
@@ -389,47 +389,54 @@ export default {
         },
         Addbtn() {
             debugger
-            var that = this
-            that.addData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
-            if (that.addData.DepName == "" || that.addData.DepName == undefined) {
-                that.$message.error("部门名称不能为空");
-                return
-            }
-            if (that.addData.DepCode == "") {
-                that.$message.error("部门code不能为空");
-                return
-            }
-            if (that.addData.CompanyId == 0) {
-                that.$message.error("请选择所属公司");
-                return
-            }
-            var url = "http://localhost:5256/api/System/AddDepartment"
+            this.$refs.addData.validate((valid) => {
+                if (valid) {
+                    var that = this
+                    that.addData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
+                    if (that.addData.DepName == "" || that.addData.DepName == undefined) {
+                        that.$message.error("部门名称不能为空");
+                        return
+                    }
+                    if (that.addData.DepCode == "") {
+                        that.$message.error("部门code不能为空");
+                        return
+                    }
+                    if (that.addData.CompanyId == 0) {
+                        that.$message.error("请选择所属公司");
+                        return
+                    }
+                    var url = "http://localhost:5256/api/System/AddDepartment"
 
-            that.$axios({
-                method: 'post',
-                url: url,
-                headers: {
-                    Authorization: 'Bearer ' + that.token
-                },
-                data: that.addData
-            }).then(function (res) {
-                console.log(res)
-                debugger
-                if (res.data.code == 200) {
-                    that.$message({
-                        message: '添加成功!',
-                        type: 'success'
-                    });
-                    that.addDepVisible = false;
-                    that.Department();
-                    that.addData.CompanyId = 0;
-                    that.addData.DepCode = "";
-                    that.addData.DepName = "";
-                    that.addData.ParentDepId = 0;
-                    that.addData.CreateUserId = this.userId;
-                    that.addData.Remark = "";
+                    that.$axios({
+                        method: 'post',
+                        url: url,
+                        headers: {
+                            Authorization: 'Bearer ' + that.token
+                        },
+                        data: that.addData
+                    }).then(function (res) {
+                        console.log(res)
+                        debugger
+                        if (res.data.code == 200) {
+                            that.$message({
+                                message: '添加成功!',
+                                type: 'success'
+                            });
+                            that.addDepVisible = false;
+                            that.Department();
+                            that.addData.CompanyId = 0;
+                            that.addData.DepCode = "";
+                            that.addData.DepName = "";
+                            that.addData.ParentDepId = 0;
+                            that.addData.CreateUserId = this.userId;
+                            that.addData.Remark = "";
+                        } else {
+                            that.$message.error('添加失败!');
+                        }
+                    })
                 } else {
-                    that.$message.error('添加失败!');
+                    this.$message.error('请完善信息在保存!');
+                    return false;
                 }
             })
         },

+ 79 - 60
src/components/system/JobPost.vue

@@ -141,7 +141,13 @@ export default {
             userId: 0,
             rules: {
                 JobName: [
-                    { required: true, message: '请输入公司名称', trigger: 'blur' },
+                    { required: true, message: '请输入岗位名称', trigger: 'blur' },
+                ],
+                CompanyId: [
+                    { required: true, message: '请选择所属公司', trigger: 'blur' },
+                ],
+                DepId: [
+                    { required: true, message: '请选择所属部门', trigger: 'blur' },
                 ],
             },
         }
@@ -262,39 +268,45 @@ export default {
         },
         upDateBtn() {
             debugger
-            var that = this
-            that.upData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
+            this.$refs.upData.validate((valid) => {
+                if (valid) {
+                    var that = this
+                    that.upData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
 
-            if (that.upData.JobName == "" || that.upData.JobName == undefined) {
-                that.$message.error("部门名称不能为空");
-                return
-            }
-            if (that.upData.Remark == null || that.upData.Remark == undefined) that.upData.Remark = ''
+                    if (that.upData.JobName == "" || that.upData.JobName == undefined) {
+                        that.$message.error("部门名称不能为空");
+                        return
+                    }
+                    if (that.upData.Remark == null || that.upData.Remark == undefined) that.upData.Remark = ''
 
-            var url = "http://localhost:5256/api/System/EditJobPost"
+                    var url = "http://localhost:5256/api/System/EditJobPost"
 
-            that.$axios({
-                method: 'post',
-                url: url,
-                headers: {
-                    Authorization: 'Bearer ' + that.token
-                },
-                data: that.upData
-            }).then(function (res) {
-                console.log(res)
-                debugger
-                if (res.data.code == 200) {
-                    that.$message({
-                        message: '修改成功',
-                        type: 'success'
-                    });
-                    that.upJobVisible = false;
-                    that.jobPost();
+                    that.$axios({
+                        method: 'post',
+                        url: url,
+                        headers: {
+                            Authorization: 'Bearer ' + that.token
+                        },
+                        data: that.upData
+                    }).then(function (res) {
+                        console.log(res)
+                        debugger
+                        if (res.data.code == 200) {
+                            that.$message({
+                                message: '修改成功',
+                                type: 'success'
+                            });
+                            that.upJobVisible = false;
+                            that.jobPost();
+                        } else {
+                            that.$message.error('修改失败!');
+                        }
+                    })
                 } else {
-                    that.$message.error('修改失败!');
+                    this.$message.error('请完善信息在保存!');
+                    return false;
                 }
             })
-
         },
         //关闭修改框
         handleClose(done) {
@@ -348,39 +360,46 @@ export default {
         },
         Addbtn() {
             debugger
-            var that = this
-            that.addData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
-            if (that.addData.JobName == "" || that.addData.JobName == undefined) {
-                that.$message.error("岗位名称不能为空");
-                return
-            }
-            if (that.addData.Remark == null) that.addData.Remark = '';
-            var url = "http://localhost:5256/api/System/AddJobPost"
-            that.$axios({
-                method: 'post',
-                url: url,
-                headers: {
-                    Authorization: 'Bearer ' + that.token
-                },
-                data: that.addData
-            }).then(function (res) {
-                console.log(res)
-                debugger
-                if (res.data.code == 200) {
-                    that.$message({
-                        message: '添加成功!',
-                        type: 'success'
-                    });
-                    that.addJobVisible = false;
-                    that.Department();
-                    that.addData.CompanyId = '';
-                    that.addData.DepId = '';
-                    that.addData.JobName = ''
-                    that.addData.CreateUserId = this.userId;
-                    that.addData.Remark = "";
-                    that.jobPost();
+            this.$refs.addData.validate((valid) => {
+                if (valid) {
+                    var that = this
+                    that.addData.CreateUserId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
+                    if (that.addData.JobName == "" || that.addData.JobName == undefined) {
+                        that.$message.error("岗位名称不能为空");
+                        return
+                    }
+                    if (that.addData.Remark == null) that.addData.Remark = '';
+                    var url = "http://localhost:5256/api/System/AddJobPost"
+                    that.$axios({
+                        method: 'post',
+                        url: url,
+                        headers: {
+                            Authorization: 'Bearer ' + that.token
+                        },
+                        data: that.addData
+                    }).then(function (res) {
+                        console.log(res)
+                        debugger
+                        if (res.data.code == 200) {
+                            that.$message({
+                                message: '添加成功!',
+                                type: 'success'
+                            });
+                            that.addJobVisible = false;
+                            that.Department();
+                            that.addData.CompanyId = '';
+                            that.addData.DepId = '';
+                            that.addData.JobName = ''
+                            that.addData.CreateUserId = this.userId;
+                            that.addData.Remark = "";
+                            that.jobPost();
+                        } else {
+                            that.$message.error('添加失败!');
+                        }
+                    })
                 } else {
-                    that.$message.error('添加失败!');
+                    this.$message.error('请完善信息在保存!');
+                    return false;
                 }
             })
         },

+ 55 - 45
src/components/system/User.vue

@@ -112,14 +112,17 @@ export default {
     data() {
         return {
             rules: {
-                DepCode: [
-                    { required: true, message: '请输入部门Code', trigger: 'blur' },
+                Number: [
+                    { required: true, message: '请输入工号', trigger: 'blur' },
                 ],
-                DepName: [
-                    { required: true, message: '请输入部门名称', trigger: 'blur' },
+                CompanyId: [
+                    { required: true, message: '请选择所属公司', trigger: 'blur' },
                 ],
-                CompanyValue: [
-                    { required: true, message: '请选择所属公司', trigger: 'change' }
+                DepId: [
+                    { required: true, message: '请选择所属部门', trigger: 'change' }
+                ],
+                JobPostId: [
+                    { required: true, message: '请选择所属职位', trigger: 'change' }
                 ],
             },
             tableDatas: [],
@@ -308,47 +311,54 @@ export default {
         },
         upBtn() {
             debugger
-            var that = this
-            if (that.upData.DepId == "" || that.upData.DepId == undefined) {
-                that.$message.error("部门不能为空");
-                return
-            }
-            if (that.upData.CompanyId == "") {
-                that.$message.error("公司不能为空");
-                return
-            }
-            if (that.upData.JobPostId == "") {
-                that.$message.error("岗位不能为空");
-                return
-            }
-            if (that.upData.Number == "") {
-                that.$message.error("工号不能为空");
-                return
-            }
-            console.log(that.upData.Ext)
-            if (that.upData.Ext == null || that.upData.Ext == undefined) that.upData.Ext = ""
-            if (that.upData.UsePeriod == null || that.upData.UsePeriod == undefined) that.upData.UsePeriod = ""
-            var url = "http://localhost:5256/api/System/EditUser"
+            this.$refs.upData.validate((valid) => {
+                if (valid) {
+                    var that = this
+                    if (that.upData.DepId == "" || that.upData.DepId == undefined) {
+                        that.$message.error("部门不能为空");
+                        return
+                    }
+                    if (that.upData.CompanyId == "") {
+                        that.$message.error("公司不能为空");
+                        return
+                    }
+                    if (that.upData.JobPostId == "") {
+                        that.$message.error("岗位不能为空");
+                        return
+                    }
+                    if (that.upData.Number == "") {
+                        that.$message.error("工号不能为空");
+                        return
+                    }
+                    console.log(that.upData.Ext)
+                    if (that.upData.Ext == null || that.upData.Ext == undefined) that.upData.Ext = ""
+                    if (that.upData.UsePeriod == null || that.upData.UsePeriod == undefined) that.upData.UsePeriod = ""
+                    var url = "http://localhost:5256/api/System/EditUser"
 
-            that.$axios({
-                method: 'post',
-                url: url,
-                headers: {
-                    Authorization: 'Bearer ' + that.token
-                },
-                data: that.upData
-            }).then(function (res) {
-                console.log(res)
-                debugger
-                if (res.data.code == 200) {
-                    that.$message({
-                        message: '修改成功',
-                        type: 'success'
-                    });
-                    that.upUserVisible = false;
-                    that.user();
+                    that.$axios({
+                        method: 'post',
+                        url: url,
+                        headers: {
+                            Authorization: 'Bearer ' + that.token
+                        },
+                        data: that.upData
+                    }).then(function (res) {
+                        console.log(res)
+                        debugger
+                        if (res.data.code == 200) {
+                            that.$message({
+                                message: '修改成功',
+                                type: 'success'
+                            });
+                            that.upUserVisible = false;
+                            that.user();
+                        } else {
+                            that.$message.error('修改失败!');
+                        }
+                    })
                 } else {
-                    that.$message.error('修改失败!');
+                    this.$message.error('请完善信息在保存!');
+                    return false;
                 }
             })
         },