1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
| <template> <div class="app-container">
<div class="search-div"> <el-form label-width="70px" size="small"> <el-row> <el-col :span="8"> <el-form-item label="关 键 字"> <el-input style="width: 95%" v-model="searchObj.keyword" placeholder="用户名/姓名/手机号码"></el-input> </el-form-item> </el-col> <el-col :span="8"> <el-form-item label="操作时间"> <el-date-picker v-model="createTimes" type="datetimerange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss" style="margin-right: 10px;width: 100%;" /> </el-form-item> </el-col> </el-row> <el-row style="display:flex"> <el-button type="primary" icon="el-icon-search" size="mini" @click="fetchData()">搜索</el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button> </el-row> </el-form> </div>
<div class="tools-div"> <el-button type="success" icon="el-icon-plus" size="mini" @click="add">添 加</el-button> </div>
<el-table v-loading="listLoading" :data="list" stripe border style="width: 100%;margin-top: 10px;">
<el-table-column label="序号" width="70" align="center"> <template slot-scope="scope"> {{ (page - 1) * limit + scope.$index + 1 }} </template> </el-table-column>
<el-table-column prop="username" label="用户名" width="180"/> <el-table-column prop="name" label="姓名" width="110"/> <el-table-column prop="phone" label="手机" /> <el-table-column label="状态" width="80"> <template slot-scope="scope"> <el-switch v-model="scope.row.status === 1" @change="switchStatus(scope.row)"> </el-switch> </template> </el-table-column> <el-table-column prop="createTime" label="创建时间" />
<el-table-column label="操作" align="center" fixed="right"> <template slot-scope="scope"> <el-button type="primary" icon="el-icon-edit" size="mini" @click="edit(scope.row.id)" title="修改"/> <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeDataById(scope.row.id)" title="删除" /> </template> </el-table-column> </el-table>
<el-pagination :current-page="page" :total="total" :page-size="limit" style="padding: 30px 0; text-align: center;" layout="total, prev, pager, next, jumper" @current-change="fetchData" />
<el-dialog title="添加/修改" :visible.sync="dialogVisible" width="40%" > <el-form ref="dataForm" :model="sysUser" label-width="100px" size="small" style="padding-right: 40px;"> <el-form-item label="用户名" prop="username"> <el-input v-model="sysUser.username"/> </el-form-item> <el-form-item v-if="!sysUser.id" label="密码" prop="password"> <el-input v-model="sysUser.password" type="password"/> </el-form-item> <el-form-item label="姓名" prop="name"> <el-input v-model="sysUser.name"/> </el-form-item> <el-form-item label="手机" prop="phone"> <el-input v-model="sysUser.phone"/> </el-form-item> </el-form> <span slot="footer" class="dialog-footer"> <el-button @click="dialogVisible = false" size="small" icon="el-icon-refresh-right">取 消</el-button> <el-button type="primary" icon="el-icon-check" @click="saveOrUpdate()" size="small">确 定</el-button> </span> </el-dialog> </div> </template>
<script> import api from '@/api/system/sysUser' const defaultForm = { id: '', username: '', password: '', name: '', phone: '', status: 1 } export default { data() { return { listLoading: true, list: null, total: 0, page: 1, limit: 10, searchObj: {},
createTimes: [],
dialogVisible: false, sysUser: defaultForm, saveBtnDisabled: false, } },
created() { console.log('list created......') this.fetchData() },
mounted() { console.log('list mounted......') },
methods: { fetchData(page = 1) { debugger this.page = page if(this.createTimes && this.createTimes.length ==2) { this.searchObj.createTimeBegin = this.createTimes[0] this.searchObj.createTimeEnd = this.createTimes[1] }
api.getPageList(this.page, this.limit, this.searchObj).then( response => { this.list = response.data.records this.total = response.data.total
this.listLoading = false } ) },
resetData() { console.log('重置查询表单') this.searchObj = {} this.createTimes = [] this.fetchData() },
removeDataById(id) { this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { return api.removeById(id) }).then((response) => { this.fetchData(this.page) this.$message.success(response.message || '删除成功') }).catch(() => { this.$message.info('取消删除') }) },
add(){ this.dialogVisible = true this.sysUser = {} }, edit(id) { this.dialogVisible = true api.getById(id).then(response => { this.sysUser = response.data }) }, saveOrUpdate() { if (!this.sysUser.id) { this.save() } else { this.update() } },
save() { api.save(this.sysUser).then(response => { this.$message.success('操作成功') this.dialogVisible = false this.fetchData(this.page) }) },
update() { api.updateById(this.sysUser).then(response => { this.$message.success(response.message || '操作成功') this.dialogVisible = false this.fetchData(this.page) }) } } } </script>
|