diff --git a/src/pages/nav1/Table.vue b/src/pages/nav1/Table.vue index de84e12..aaca8ed 100644 --- a/src/pages/nav1/Table.vue +++ b/src/pages/nav1/Table.vue @@ -47,16 +47,12 @@ - + - @@ -77,6 +73,34 @@ 提交 + + + + + + + + + + + + + + + + + + + + + + + + + @@ -96,8 +120,14 @@ page: 1, listLoading: false, sels: [],//列表选中列 - editFormVisible: false,//编辑界面显是否显示 - editFormTtile: '编辑',//编辑界面标题 + + editFormVisible: false,//编辑界面是否显示 + editLoading: false, + editFormRules: { + name: [ + { required: true, message: '请输入姓名', trigger: 'blur' } + ] + }, //编辑界面数据 editForm: { id: 0, @@ -107,11 +137,21 @@ birth: '', addr: '' }, - editLoading: false, - editFormRules: { + + addFormVisible: false,//新增界面是否显示 + addLoading: false, + addFormRules: { name: [ { required: true, message: '请输入姓名', trigger: 'blur' } ] + }, + //新增界面数据 + addForm: { + name: '', + sex: -1, + age: 0, + birth: '', + addr: '' } } @@ -142,115 +182,91 @@ }, //删除 handleDel: function (row) { - //console.log(row); - var _this = this; this.$confirm('确认删除该记录吗?', '提示', { - //type: 'warning' + type: 'warning' }).then(() => { - _this.listLoading = true; + this.listLoading = true; NProgress.start(); let para = { id: row.id }; removeUser(para).then((res) => { - _this.listLoading = false; + this.listLoading = false; NProgress.done(); - _this.$notify({ + this.$notify({ title: '成功', message: '删除成功', type: 'success' }); - _this.getUsers(); + this.getUsers(); }); - }).catch(() => { }); }, //显示编辑界面 handleEdit: function (row) { - this.$refs['editForm'].resetFields(); this.editFormVisible = true; - this.editFormTtile = '编辑'; - this.editForm.id = row.id; - this.editForm.name = row.name; - this.editForm.sex = row.sex; - this.editForm.age = row.age; - this.editForm.birth = row.birth; - this.editForm.addr = row.addr; + this.editForm = Object.assign({}, row); }, - //编辑 or 新增 + //显示新增界面 + handleAdd: function () { + this.addFormVisible = true; + this.addForm = { + name: '', + sex: -1, + age: 0, + birth: '', + addr: '' + }; + }, + //编辑 editSubmit: function () { - var _this = this; - - _this.$refs.editForm.validate((valid) => { + this.$refs.editForm.validate((valid) => { if (valid) { - - _this.$confirm('确认提交吗?', '提示', {}).then(() => { - _this.editLoading = true; + this.$confirm('确认提交吗?', '提示', {}).then(() => { + this.editLoading = true; NProgress.start(); - - if (_this.editForm.id == 0) { - //新增 - let para = { - name: _this.editForm.name, - sex: _this.editForm.sex, - age: _this.editForm.age, - birth: _this.editForm.birth == '' ? '' : util.formatDate.format(new Date(_this.editForm.birth), 'yyyy-MM-dd'), - addr: _this.editForm.addr, - }; - addUser(para).then((res) => { - _this.editLoading = false; - NProgress.done(); - _this.$notify({ - title: '成功', - message: '提交成功', - type: 'success' - }); - _this.editFormVisible = false; - _this.getUsers(); + let para = Object.assign({}, this.editForm); + para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd'); + editUser(para).then((res) => { + this.editLoading = false; + NProgress.done(); + this.$notify({ + title: '成功', + message: '提交成功', + type: 'success' }); - } else { - //编辑 - let para = { - id: _this.editForm.id, - name: _this.editForm.name, - sex: _this.editForm.sex, - age: _this.editForm.age, - birth: _this.editForm.birth == '' ? '' : util.formatDate.format(new Date(_this.editForm.birth), 'yyyy-MM-dd'), - addr: _this.editForm.addr, - }; - editUser(para).then((res) => { - _this.editLoading = false; - NProgress.done(); - _this.$notify({ - title: '成功', - message: '提交成功', - type: 'success' - }); - _this.editFormVisible = false; - _this.getUsers(); - }); - - } - + this.$refs['editForm'].resetFields(); + this.editFormVisible = false; + this.getUsers(); + }); }); - } }); - }, - //显示新增界面 - handleAdd: function () { - var _this = this; - - this.editFormVisible = true; - this.editFormTtile = '新增'; - - this.editForm.id = 0; - this.editForm.name = ''; - this.editForm.sex = 1; - this.editForm.age = 0; - this.editForm.birth = ''; - this.editForm.addr = ''; + //新增 + addSubmit: function () { + this.$refs.addForm.validate((valid) => { + if (valid) { + this.$confirm('确认提交吗?', '提示', {}).then(() => { + this.addLoading = true; + NProgress.start(); + let para = Object.assign({}, this.addForm); + para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd'); + addUser(para).then((res) => { + this.addLoading = false; + NProgress.done(); + this.$notify({ + title: '成功', + message: '提交成功', + type: 'success' + }); + this.$refs['addForm'].resetFields(); + this.addFormVisible = false; + this.getUsers(); + }); + }); + } + }); }, selsChange: function (sels) { this.sels = sels; @@ -258,7 +274,9 @@ //批量删除 batchRemove: function () { var ids = this.sels.map(item => item.id).toString(); - this.$confirm('确认删除选中记录吗?', '提示').then(() => { + this.$confirm('确认删除选中记录吗?', '提示', { + type: 'warning' + }).then(() => { this.listLoading = true; NProgress.start(); let para = { ids: ids };