|
|
@ -2,23 +2,23 @@ |
|
|
|
<section> |
|
|
|
<!--工具条--> |
|
|
|
<el-col :span="24" class="toolbar"> |
|
|
|
<el-form :inline="true" :model="formInline"> |
|
|
|
<el-form :inline="true" :model="filters"> |
|
|
|
<el-form-item> |
|
|
|
<el-input v-model="formInline.user" placeholder="姓名"></el-input> |
|
|
|
<el-input v-model="filters.name" placeholder="姓名"></el-input> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item> |
|
|
|
<el-button>查询</el-button> |
|
|
|
<el-button type="primary" v-on:click="getUsers">查询</el-button> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item> |
|
|
|
<el-button @click="handleAdd">新增</el-button> |
|
|
|
<el-button type="primary" @click="handleAdd">新增</el-button> |
|
|
|
</el-form-item> |
|
|
|
</el-form> |
|
|
|
</el-col> |
|
|
|
|
|
|
|
<!--列表--> |
|
|
|
<template> |
|
|
|
<el-table :data="tableData" highlight-current-row v-loading="listLoading" style="width: 100%;"> |
|
|
|
<el-table-column type="index" width="50"> |
|
|
|
<el-table :data="users" highlight-current-row v-loading="listLoading" style="width: 100%;"> |
|
|
|
<el-table-column type="index" width="60"> |
|
|
|
</el-table-column> |
|
|
|
<el-table-column prop="name" label="姓名" width="180" sortable> |
|
|
|
</el-table-column> |
|
|
@ -30,10 +30,10 @@ |
|
|
|
</el-table-column> |
|
|
|
<el-table-column prop="addr" label="地址" sortable> |
|
|
|
</el-table-column> |
|
|
|
<el-table-column inline-template :context="_self" label="操作" width="100"> |
|
|
|
<el-table-column inline-template :context="_self" label="操作" width="140"> |
|
|
|
<span> |
|
|
|
<el-button type="text" size="small" @click="handleEdit(row)">编辑</el-button> |
|
|
|
<el-button type="text" size="small" @click="handleDel(row)">删除</el-button> |
|
|
|
<el-button size="small" @click="handleEdit(row)">编辑</el-button> |
|
|
|
<el-button type="danger" size="small" @click="handleDel(row)">删除</el-button> |
|
|
|
</span> |
|
|
|
</el-table-column> |
|
|
|
</el-table> |
|
|
@ -41,8 +41,7 @@ |
|
|
|
|
|
|
|
<!--分页--> |
|
|
|
<el-col :span="24" class="toolbar" style="padding-bottom:10px;"> |
|
|
|
<el-pagination :current-page="1" :page-sizes="[100, 200, 300, 400]" :page-size="100" layout="total, sizes, prev, pager, next, jumper" |
|
|
|
:total="400" style="float:right"> |
|
|
|
<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="20" :total="total" style="float:right;"> |
|
|
|
</el-pagination> |
|
|
|
</el-col> |
|
|
|
|
|
|
@ -83,19 +82,18 @@ |
|
|
|
<script> |
|
|
|
import util from '../../common/util' |
|
|
|
import NProgress from 'nprogress' |
|
|
|
import { getUserListPage, removeUser, editUser, addUser } from '../../api/api'; |
|
|
|
|
|
|
|
export default { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
formInline: { |
|
|
|
user: '' |
|
|
|
filters: { |
|
|
|
name: '' |
|
|
|
}, |
|
|
|
pickerOptions0: { |
|
|
|
disabledDate(time) { |
|
|
|
return time.getTime() < Date.now() - 8.64e7; |
|
|
|
} |
|
|
|
}, |
|
|
|
value1:'', |
|
|
|
users: [], |
|
|
|
total: 0, |
|
|
|
page: 1, |
|
|
|
listLoading: false, |
|
|
|
editFormVisible: false,//编辑界面显是否显示 |
|
|
|
editFormTtile: '编辑',//编辑界面标题 |
|
|
|
//编辑界面数据 |
|
|
@ -113,65 +111,8 @@ |
|
|
|
name: [ |
|
|
|
{ required: true, message: '请输入姓名', trigger: 'blur' } |
|
|
|
] |
|
|
|
}, |
|
|
|
tableData: [{ |
|
|
|
id:1000, |
|
|
|
name: 'lanqy1', |
|
|
|
sex: 1, |
|
|
|
age: 20, |
|
|
|
birth:'1996-03-02', |
|
|
|
addr:'广东广州天河体育中心' |
|
|
|
}, { |
|
|
|
id:1001, |
|
|
|
name: 'lanqy2', |
|
|
|
sex: 1, |
|
|
|
age: 20, |
|
|
|
birth:'1996-03-02', |
|
|
|
addr:'广东广州天河体育中心' |
|
|
|
}, { |
|
|
|
id:1002, |
|
|
|
name: 'lanqy3', |
|
|
|
sex: 0, |
|
|
|
age: 20, |
|
|
|
birth:'1996-03-02', |
|
|
|
addr:'广东广州天河体育中心' |
|
|
|
}, { |
|
|
|
id:1003, |
|
|
|
name: 'lanqy4', |
|
|
|
sex: 1, |
|
|
|
age: 20, |
|
|
|
birth:'1996-03-02', |
|
|
|
addr:'广东广州天河体育中心' |
|
|
|
}, { |
|
|
|
id:1004, |
|
|
|
name: 'lanqy5', |
|
|
|
sex: 1, |
|
|
|
age: 20, |
|
|
|
birth:'1996-03-02', |
|
|
|
addr:'广东广州天河体育中心' |
|
|
|
}, { |
|
|
|
id:1005, |
|
|
|
name: 'lanqy6', |
|
|
|
sex: 1, |
|
|
|
age: 20, |
|
|
|
birth:'1996-03-02', |
|
|
|
addr:'广东广州天河体育中心' |
|
|
|
}, { |
|
|
|
id:1006, |
|
|
|
name: 'lanqy7', |
|
|
|
sex: 1, |
|
|
|
age: 20, |
|
|
|
birth:'1996-03-02', |
|
|
|
addr:'广东广州天河体育中心' |
|
|
|
}, { |
|
|
|
id:1007, |
|
|
|
name: 'lanqy8', |
|
|
|
sex: 1, |
|
|
|
age: 20, |
|
|
|
birth:'1996-03-02', |
|
|
|
addr:'广东广州天河体育中心' |
|
|
|
}], |
|
|
|
listLoading:false |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
methods: { |
|
|
@ -179,7 +120,26 @@ |
|
|
|
formatSex: function (row, column) { |
|
|
|
return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知'; |
|
|
|
}, |
|
|
|
//删除记录 |
|
|
|
handleCurrentChange(val) { |
|
|
|
this.page = val; |
|
|
|
this.getUsers(); |
|
|
|
}, |
|
|
|
//获取用户列表 |
|
|
|
getUsers() { |
|
|
|
let para = { |
|
|
|
page: this.page, |
|
|
|
name: this.filters.name |
|
|
|
}; |
|
|
|
this.listLoading = true; |
|
|
|
NProgress.start(); |
|
|
|
getUserListPage(para).then((res) => { |
|
|
|
this.total = res.data.total; |
|
|
|
this.users = res.data.users; |
|
|
|
this.listLoading = false; |
|
|
|
NProgress.done(); |
|
|
|
}); |
|
|
|
}, |
|
|
|
//删除 |
|
|
|
handleDel: function (row) { |
|
|
|
//console.log(row); |
|
|
|
var _this = this; |
|
|
@ -188,11 +148,8 @@ |
|
|
|
}).then(() => { |
|
|
|
_this.listLoading = true; |
|
|
|
NProgress.start(); |
|
|
|
setTimeout(function(){ |
|
|
|
for(var i=0;i<_this.tableData.length;i++){ |
|
|
|
if(_this.tableData[i].id==row.id){ |
|
|
|
_this.tableData.splice(i,1); |
|
|
|
|
|
|
|
let para = { id: row.id }; |
|
|
|
removeUser(para).then((res) => { |
|
|
|
_this.listLoading = false; |
|
|
|
NProgress.done(); |
|
|
|
_this.$notify({ |
|
|
@ -200,11 +157,9 @@ |
|
|
|
message: '删除成功', |
|
|
|
type: 'success' |
|
|
|
}); |
|
|
|
_this.getUsers(); |
|
|
|
}); |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
},1000); |
|
|
|
}).catch(() => { |
|
|
|
|
|
|
|
}); |
|
|
@ -231,7 +186,17 @@ |
|
|
|
_this.editLoading = true; |
|
|
|
NProgress.start(); |
|
|
|
_this.btnEditText = '提交中'; |
|
|
|
setTimeout(function(){ |
|
|
|
|
|
|
|
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.btnEditText = '提 交'; |
|
|
@ -241,31 +206,32 @@ |
|
|
|
type: 'success' |
|
|
|
}); |
|
|
|
_this.editFormVisible = false; |
|
|
|
|
|
|
|
if(_this.editForm.id==0){ |
|
|
|
//新增 |
|
|
|
_this.tableData.push({ |
|
|
|
id:new Date().getTime(), |
|
|
|
_this.getUsers(); |
|
|
|
}); |
|
|
|
} 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 |
|
|
|
addr: _this.editForm.addr, |
|
|
|
}; |
|
|
|
editUser(para).then((res) => { |
|
|
|
_this.editLoading = false; |
|
|
|
NProgress.done(); |
|
|
|
_this.btnEditText = '提 交'; |
|
|
|
_this.$notify({ |
|
|
|
title: '成功', |
|
|
|
message: '提交成功', |
|
|
|
type: 'success' |
|
|
|
}); |
|
|
|
}else{ |
|
|
|
//编辑 |
|
|
|
for(var i=0;i<_this.tableData.length;i++){ |
|
|
|
if(_this.tableData[i].id==_this.editForm.id){ |
|
|
|
_this.tableData[i].name=_this.editForm.name; |
|
|
|
_this.tableData[i].sex=_this.editForm.sex; |
|
|
|
_this.tableData[i].age=_this.editForm.age; |
|
|
|
_this.tableData[i].birth=_this.editForm.birth==''?'':util.formatDate.format(new Date(_this.editForm.birth),'yyyy-MM-dd'); |
|
|
|
_this.tableData[i].addr=_this.editForm.addr; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
_this.editFormVisible = false; |
|
|
|
_this.getUsers(); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
},1000); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
@ -287,6 +253,9 @@ |
|
|
|
this.editForm.birth = ''; |
|
|
|
this.editForm.addr = ''; |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
this.getUsers(); |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|