huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame] | 1 | <template> |
| 2 | <div class="app-container"> |
| 3 | <el-col :span="12"> |
| 4 | <el-card> |
| 5 | <div class="filter-container"> |
| 6 | <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="类型名称/编码" v-model="listQuery.name"> |
| 7 | </el-input> |
| 8 | <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">查询</el-button> |
| 9 | <el-button class="filter-item" style="margin-left: 10px;" @click="handleCreate(null, 'create')" type="primary" icon="el-icon-edit">添加</el-button> |
| 10 | </div> |
| 11 | <el-table :height="height" :data="items" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row> |
| 12 | <el-table-column label="类型编码" align="center"> |
| 13 | <template slot-scope="scope"> |
| 14 | {{scope.row.code}} |
| 15 | </template> |
| 16 | </el-table-column> |
| 17 | <el-table-column label="类型名称" align="center"> |
| 18 | <template slot-scope="scope"> |
| 19 | <span>{{scope.row.name}}</span> |
| 20 | </template> |
| 21 | </el-table-column> |
| 22 | <el-table-column |
| 23 | header-align="center" |
| 24 | align="center" |
| 25 | width="150" |
| 26 | label="操作"> |
| 27 | <template slot-scope="scope"> |
| 28 | <el-button type="text" size="small" @click="handleCreate(scope.row.id, 'update')">修改</el-button> |
| 29 | <el-button type="text" size="small" @click="handleView(scope.row.code)">查看</el-button> |
| 30 | <el-button type="text" size="small" @click="handleDelete(scope.row.id)">删除</el-button> |
| 31 | </template> |
| 32 | </el-table-column> |
| 33 | </el-table> |
| 34 | <div class="pagination-container"> |
| 35 | <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.pageIndex" |
| 36 | :page-sizes="[10,20,30, 50]" :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="recordCount"> |
| 37 | </el-pagination> |
| 38 | </div> |
| 39 | |
| 40 | <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible"> |
| 41 | <el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="150px" style='width: 400px; margin-left:50px;'> |
| 42 | <el-form-item label="类型编码" prop="code"> |
| 43 | <el-input v-model="temp.code"></el-input> |
| 44 | <input type="hidden" v-model="temp.id" /> |
| 45 | </el-form-item> |
| 46 | <el-form-item label="类型名称" prop="name"> |
| 47 | <el-input v-model="temp.name"></el-input> |
| 48 | </el-form-item> |
| 49 | </el-form> |
| 50 | <div slot="footer" class="dialog-footer"> |
| 51 | <el-button @click="dialogFormVisible = false">返回</el-button> |
| 52 | <el-button type="primary" @click="createData">提交</el-button> |
| 53 | </div> |
| 54 | </el-dialog> |
| 55 | </el-card> |
| 56 | </el-col> |
| 57 | <el-col :span="12"> |
| 58 | <el-card> |
| 59 | <div class="filter-container"> |
| 60 | <el-button class="filter-item" style="margin-left: 10px;" @click="handleCreateDic(null, 'create')" type="primary" icon="el-icon-edit">添加</el-button> |
| 61 | </div> |
| 62 | <el-table :height="itemHeight" :data="dicList" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row> |
| 63 | <el-table-column label="字典编码" align="center"> |
| 64 | <template slot-scope="scope"> |
| 65 | {{scope.row.code}} |
| 66 | </template> |
| 67 | </el-table-column> |
| 68 | <el-table-column label="字典名称" align="center"> |
| 69 | <template slot-scope="scope"> |
| 70 | <span>{{scope.row.name}}</span> |
| 71 | </template> |
| 72 | </el-table-column> |
| 73 | <el-table-column |
| 74 | header-align="center" |
| 75 | align="center" |
| 76 | width="150" |
| 77 | label="操作"> |
| 78 | <template slot-scope="scope"> |
| 79 | <el-button type="text" size="small" @click="handleCreateDic(scope.row.id, 'update')">修改</el-button> |
| 80 | <el-button type="text" size="small" @click="handleDeleteDic(scope.row.id)">删除</el-button> |
| 81 | </template> |
| 82 | </el-table-column> |
| 83 | </el-table> |
| 84 | |
| 85 | <el-dialog :title="textMap[dialogStatus]" :visible.sync="dicDialogFormVisible"> |
| 86 | <el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="150px" style='width: 400px; margin-left:50px;'> |
| 87 | <el-form-item label="字典编码" prop="code"> |
| 88 | <el-input v-model="temp.code"></el-input> |
| 89 | <input type="hidden" v-model="temp.id" /> |
| 90 | </el-form-item> |
| 91 | <el-form-item label="字典名称" prop="name"> |
| 92 | <el-input v-model="temp.name"></el-input> |
| 93 | </el-form-item> |
| 94 | </el-form> |
| 95 | <div slot="footer" class="dialog-footer"> |
| 96 | <el-button @click="dicDialogFormVisible = false">返回</el-button> |
| 97 | <el-button type="primary" @click="createDataDic">提交</el-button> |
| 98 | </div> |
| 99 | </el-dialog> |
| 100 | </el-card> |
| 101 | </el-col> |
| 102 | </div> |
| 103 | </template> |
| 104 | |
| 105 | <script> |
| 106 | import { getPage, getType, getDicList, createType, deleteType, getDic, createDic, deleteDic } from '@/api/dictionary-api' |
| 107 | import waves from '@/directive/waves' // 水波纹指令 |
| 108 | import { MessageBox } from 'element-ui' |
| 109 | import { resetForm } from '@/utils' |
| 110 | import { crudPageList, crudGetItem, crudCreate, crudDelete } from '@/utils/crud' |
| 111 | import mixindata from '@/utils/crud' |
| 112 | |
| 113 | const initData = { sex: 'male', zt: 'on' } |
| 114 | export default { |
| 115 | name: 'type', |
| 116 | directives: { |
| 117 | waves |
| 118 | }, |
| 119 | mixins: [mixindata], |
| 120 | data() { |
| 121 | return { |
| 122 | dicDialogFormVisible: false, |
| 123 | dicDialogVisible: false, |
| 124 | dicList: [], |
| 125 | itemHeight: 500, |
| 126 | rules: { |
| 127 | ghxh: [{ required: true, message: '账号(工号/学号)必填', trigger: 'blur' }], |
| 128 | mm: [{ required: true, message: '密码必填', trigger: 'blur' }], |
| 129 | zhlb: [{ required: true, message: '账户类别必填', trigger: 'change' }], |
| 130 | xm: [{ required: true, message: '姓名必填', trigger: 'change' }] |
| 131 | } |
| 132 | } |
| 133 | }, |
| 134 | filters: { |
| 135 | statusFilter(status) { |
| 136 | const statusMap = { |
| 137 | '1': 'success', |
| 138 | '0': 'danger' |
| 139 | } |
| 140 | return statusMap[status] |
| 141 | } |
| 142 | }, |
| 143 | created() { |
| 144 | this.handlePageList() |
| 145 | this.height = window.innerHeight - 256 |
| 146 | this.itemHeight = window.innerHeight - 223 |
| 147 | }, |
| 148 | methods: { |
| 149 | handlePageList() { |
| 150 | crudPageList(this, getPage) |
| 151 | }, |
| 152 | handleCreate(rowid, dialogStatus) { |
| 153 | this.dialogStatus = dialogStatus |
| 154 | crudGetItem(this, getType, rowid, initData) |
| 155 | }, |
| 156 | handleReset() { |
| 157 | resetForm(this.listQuery) |
| 158 | }, |
| 159 | handleFilter() { |
| 160 | this.listQuery.pageIndex = 1 |
| 161 | this.handlePageList() |
| 162 | }, |
| 163 | handleSizeChange(val) { |
| 164 | this.listQuery.pageSize = val |
| 165 | this.handlePageList() |
| 166 | }, |
| 167 | handleCurrentChange(val) { |
| 168 | this.listQuery.pageIndex = val |
| 169 | this.handlePageList() |
| 170 | }, |
| 171 | createData() { |
| 172 | crudCreate(this, createType, this.handlePageList) |
| 173 | }, |
| 174 | handleDelete(rowid) { |
| 175 | crudDelete(this, deleteType, rowid, this.handlePageList) |
| 176 | }, |
| 177 | handleView(type) { |
| 178 | this.temp.type = type |
| 179 | getDicList({ type: type }).then(response => { |
| 180 | if (!response.items) { |
| 181 | MessageBox.alert('数据不存在,请确认是否已删除。', '消息', { |
| 182 | confirmButtonText: '确定' |
| 183 | }) |
| 184 | return |
| 185 | } |
| 186 | this.dicDialogVisible = true |
| 187 | this.dicList = response.items |
| 188 | }) |
| 189 | }, |
| 190 | handleCreateDic(rowid, dialogStatus) { |
| 191 | if (!this.temp.type) { |
| 192 | MessageBox.alert('请先选择字典类型!', '消息', { |
| 193 | confirmButtonText: '确定' |
| 194 | }) |
| 195 | return |
| 196 | } |
| 197 | this.dialogStatus = dialogStatus |
| 198 | const that = this |
| 199 | crudGetItem(this, getDic, rowid, { type: this.temp.type }, function() { |
| 200 | that.dicDialogFormVisible = true |
| 201 | that.dialogFormVisible = false |
| 202 | }) |
| 203 | }, |
| 204 | createDataDic() { |
| 205 | const that = this |
| 206 | crudCreate(this, createDic, function() { |
| 207 | that.handleView(that.temp.type) |
| 208 | that.dicDialogFormVisible = false |
| 209 | }) |
| 210 | }, |
| 211 | handleDeleteDic(rowid) { |
| 212 | const that = this |
| 213 | crudDelete(this, deleteDic, rowid, function() { |
| 214 | that.handleView(that.temp.type) |
| 215 | }) |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | </script> |
| 220 | <style scoped> |
| 221 | .el-card { |
| 222 | margin: 5px; |
| 223 | } |
| 224 | </style> |