index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <div class="body">
  3. <!-- 头部区域 -->
  4. <div class="head">
  5. <div class="head-img">
  6. <img src="../../../public/images/img-1.png" />
  7. </div>
  8. <div class="head-info">用户管理</div>
  9. </div>
  10. <!-- 添加按钮 -->
  11. <div class="switch">
  12. 所有用户
  13. <div class="switch-button">
  14. <el-row>
  15. <el-button type="primary" size="small" @click="handleCreate"
  16. ><img src="../../../public/images/img-3.png" />添加用户
  17. </el-button>
  18. </el-row>
  19. </div>
  20. </div>
  21. <!-- 表格区域 -->
  22. <div class="form">
  23. <el-table :data="list">
  24. <el-table-column label="姓名" align="center">
  25. <template slot-scope="{ row }">
  26. <span>{{ row.name }}</span>
  27. </template>
  28. </el-table-column>
  29. <el-table-column label="卡号" width="300px" align="center">
  30. <template slot-scope="{ row }">
  31. <span>{{ row.cardNumber }}</span>
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="学校" align="center">
  35. <template slot-scope="{ row }">
  36. <span>{{ row.college }}</span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="专业" align="center">
  40. <template slot-scope="{ row }">
  41. <span>{{ row.professor }}</span>
  42. </template>
  43. </el-table-column>
  44. <!-- <el-table-column label="开关" align="center">
  45. <template slot-scope="scope">
  46. <el-switch
  47. v-model="scope.row.status"
  48. active-color="#3BAAFD"
  49. inactive-color="#CCCCCC"
  50. :active-value="1"
  51. :inactive-value="0"
  52. @change="changeSwitch(scope.row.status)"
  53. >
  54. </el-switch>
  55. </template>
  56. </el-table-column> -->
  57. <el-table-column label="操作" width="180px" align="center">
  58. <template slot-scope="{ row, $index }">
  59. <el-button type="text" size="small" @click="handleUpdate(row)"
  60. >编辑</el-button
  61. >
  62. <el-button
  63. @click="handleDelete(row, $index)"
  64. type="text"
  65. size="small"
  66. class="button"
  67. ><img src="../../../public/images/img-2.png" />删除</el-button
  68. >
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. <!-- 底部分页区 -->
  73. <div class="block">
  74. <template>
  75. <pagination
  76. :total="total"
  77. :page.sync="listQuery.page"
  78. :limit.sync="listQuery.limit"
  79. @pagination="getList"
  80. />
  81. </template>
  82. </div>
  83. </div>
  84. <!-- 添加编辑按钮弹窗区域 -->
  85. <el-dialog
  86. :title="textMap[dialogStatus]"
  87. :visible.sync="dialogVisible"
  88. width="30%"
  89. center
  90. >
  91. <el-form ref="dataForm" :model="temp" :rules="rules">
  92. <el-form-item
  93. style="white-space: pre"
  94. label="姓名:"
  95. class="switch-button-item"
  96. prop="name"
  97. >
  98. <el-col :span="12">
  99. <el-input
  100. v-model="temp.name"
  101. autocomplete="off"
  102. placeholder="请输入姓名"
  103. ></el-input>
  104. </el-col>
  105. </el-form-item>
  106. <el-form-item
  107. style="white-space: pre"
  108. label="卡号:"
  109. class="switch-button-item"
  110. prop="cardNumber"
  111. >
  112. <el-col :span="12">
  113. <el-input
  114. v-model="temp.cardNumber"
  115. autocomplete="off"
  116. placeholder="请输入卡号"
  117. ></el-input>
  118. </el-col>
  119. </el-form-item>
  120. <!-- <el-form-item
  121. style="white-space: pre"
  122. label="组 类 型:"
  123. class="switch-button-item"
  124. prop="type"
  125. >
  126. <el-col :span="12">
  127. <el-select
  128. v-model="temp.type"
  129. size="mini"
  130. style="width: 100%"
  131. placeholder="分组类型"
  132. >
  133. <el-option
  134. v-for="item in types"
  135. :key="item.value"
  136. :label="item.label"
  137. :value="item.value"
  138. >
  139. </el-option>
  140. </el-select>
  141. </el-col>
  142. </el-form-item> -->
  143. <el-form-item
  144. style="white-space: pre"
  145. label="学校:"
  146. class="switch-button-item"
  147. prop="college"
  148. >
  149. <el-col :span="12">
  150. <el-input
  151. v-model="temp.college"
  152. autocomplete="off"
  153. placeholder="请输入学校"
  154. ></el-input>
  155. </el-col>
  156. </el-form-item>
  157. <el-form-item
  158. style="white-space: pre"
  159. label="专业:"
  160. class="switch-button-item"
  161. prop="professor"
  162. >
  163. <el-col :span="12">
  164. <el-input
  165. v-model="temp.professor"
  166. autocomplete="off"
  167. placeholder="请输入专业"
  168. ></el-input>
  169. </el-col>
  170. </el-form-item>
  171. </el-form>
  172. <span slot="footer">
  173. <el-button
  174. type="primary"
  175. @click="dialogStatus === 'create' ? createData() : updateData()"
  176. >确 定</el-button
  177. >
  178. <el-button @click="dialogVisible = false">取 消</el-button>
  179. </span>
  180. </el-dialog>
  181. </div>
  182. </template>
  183. <script>
  184. import Pagination from "@/components/Pagination";
  185. import {
  186. fetchList,
  187. createUser,
  188. updateUser,
  189. deletUser,
  190. } from "@/api/usermanagement";
  191. export default {
  192. components: {
  193. Pagination,
  194. },
  195. data() {
  196. return {
  197. list: [],
  198. total: 0, //数据的总数//
  199. listQuery: {
  200. page: 1, //当前在第几页//
  201. limit: 8, //一页几条//
  202. },
  203. sexs: [
  204. {
  205. value: "1",
  206. label: "男",
  207. },
  208. {
  209. value: "2",
  210. label: "女",
  211. },
  212. ],
  213. types: [
  214. { id: "1", value: "0-禁用", label: "0-禁用" },
  215. { id: "2", value: "1-学生宿舍", label: "1-学生宿舍" },
  216. { id: "3", value: "2-教师宿舍", label: "2-教师宿舍" },
  217. { id: "4", value: "3-教学楼", label: "3-教学楼" },
  218. { id: "5", value: "4-大门", label: "4-大门" },
  219. { id: "6", value: "5-行政楼", label: "5-行政楼" },
  220. ],
  221. value: "1",
  222. dialogVisible: false,
  223. dialogStatus: "",
  224. textMap: {
  225. update: "编辑用户",
  226. create: "添加用户",
  227. },
  228. temp: {
  229. id: "",
  230. name: "",
  231. cardNumber: "",
  232. classname: "",
  233. college: "",
  234. type: "",
  235. professor: "",
  236. },
  237. rules: {
  238. cardNumber: [
  239. {
  240. required: true,
  241. message: "请输入卡号",
  242. trigger: "change",
  243. },
  244. ],
  245. name: [
  246. {
  247. required: true,
  248. message: "请输入姓名",
  249. trigger: "change",
  250. },
  251. ],
  252. college: [
  253. {
  254. required: true,
  255. message: "请输入学校",
  256. trigger: "change",
  257. },
  258. ],
  259. professor: [
  260. {
  261. required: true,
  262. message: "请输入专业",
  263. trigger: "change",
  264. },
  265. ],
  266. },
  267. };
  268. },
  269. created() {
  270. this.getList();
  271. },
  272. methods: {
  273. getList() {
  274. fetchList(this.listQuery).then((response) => {
  275. this.list = response.data;
  276. this.total = response.total;
  277. });
  278. },
  279. handleDelete(row, index) {
  280. if (confirm("是否删除?")) {
  281. deletUser({ id: row.id }).then(() => {
  282. this.$notify({
  283. title: "删除成功",
  284. type: "success",
  285. duration: 1500,
  286. });
  287. this.list.splice(index, 1);
  288. });
  289. }
  290. },
  291. resetTemp() {
  292. this.temp = {
  293. id: "",
  294. name: "",
  295. cardNumber: "",
  296. classname: "",
  297. college: "",
  298. type: "",
  299. professor: "",
  300. };
  301. },
  302. handleCreate() {
  303. this.resetTemp();
  304. this.dialogStatus = "create";
  305. this.dialogVisible = true;
  306. this.$nextTick(() => {
  307. this.$refs["dataForm"].clearValidate();
  308. });
  309. },
  310. handleUpdate(row) {
  311. this.temp = Object.assign({}, row);
  312. this.dialogStatus = "update";
  313. this.dialogVisible = true;
  314. this.$nextTick(() => {
  315. this.$refs["dataForm"].clearValidate();
  316. });
  317. },
  318. createData() {
  319. this.$refs["dataForm"].validate((valid) => {
  320. if (valid) {
  321. createUser(this.temp).then(() => {
  322. this.list.push(this.temp);
  323. this.dialogVisible = false;
  324. this.$notify({
  325. title: "添加成功",
  326. type: "success",
  327. duration: 1500,
  328. });
  329. });
  330. }
  331. });
  332. this.getList();
  333. },
  334. updateData() {
  335. this.$refs["dataForm"].validate((valid) => {
  336. if (valid) {
  337. const tempData = Object.assign({}, this.temp);
  338. updateUser(tempData).then(() => {
  339. const index = this.list.findIndex((v) => v.id === this.temp.id);
  340. this.list.splice(index, 1, this.temp);
  341. this.dialogVisible = false;
  342. this.$notify({
  343. title: "编辑成功",
  344. type: "success",
  345. duration: 1500,
  346. });
  347. });
  348. }
  349. });
  350. },
  351. },
  352. };
  353. </script>
  354. <style lang="scss" scoped>
  355. .body {
  356. width: 1551px;
  357. margin: 29px 29px 0 31px;
  358. .head {
  359. display: flex;
  360. width: 1380px;
  361. height: 55px;
  362. margin-left: 40px;
  363. border-bottom: 1px solid #cccccc;
  364. .head-img {
  365. width: 30px;
  366. height: 30px;
  367. img {
  368. width: 30px;
  369. }
  370. }
  371. .head-info {
  372. width: 95px;
  373. height: 22px;
  374. margin-top: 5px;
  375. margin-left: 16px;
  376. font-weight: bold;
  377. }
  378. }
  379. .switch {
  380. display: flex;
  381. width: 1380px;
  382. line-height: 58px;
  383. margin-left: 40px;
  384. font-size: 9px;
  385. .switch-sw {
  386. width: 45px;
  387. margin-left: 19px;
  388. }
  389. .switch-button {
  390. width: 50px;
  391. margin-left: 103px;
  392. img {
  393. width: 10.5px;
  394. margin-right: 8px;
  395. }
  396. }
  397. }
  398. .form {
  399. margin-left: 40px;
  400. width: 1380px;
  401. .button-img {
  402. img {
  403. width: 53.5px;
  404. }
  405. }
  406. .button-info {
  407. margin-top: 39px;
  408. }
  409. .button {
  410. color: red;
  411. }
  412. img {
  413. width: 8.5px;
  414. margin-right: 8px;
  415. }
  416. .block {
  417. float: right;
  418. }
  419. .foot-button {
  420. margin-top: 53px;
  421. }
  422. }
  423. .switch-button-item {
  424. width: 400px;
  425. margin-left: 120px;
  426. margin-top: 30px;
  427. }
  428. }
  429. </style>