school.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <div class="pb_content">
  3. <div class="pb_head">
  4. <div>
  5. <span>学校管理</span>
  6. </div>
  7. </div>
  8. <div class="touTop">
  9. <div class="touLeft">
  10. <div>
  11. <el-input v-model="suser" placeholder="请输入手机号或用户名">
  12. </el-input>
  13. <el-button @click="search">查询</el-button>
  14. </div>
  15. </div>
  16. <div class="touRight">
  17. <div></div>
  18. <div>
  19. <el-button @click="addUser">添加账号</el-button>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="pb_content_body" style="margin: 0 auto">
  24. <div class="student_table">
  25. <el-table
  26. ref="table"
  27. :data="tableData"
  28. border
  29. :height="tableHeight"
  30. :fit="true"
  31. v-loading="isLoading"
  32. style="width: 100%"
  33. :header-cell-style="{ background: '#f1f1f1', fontSize: '17px' }"
  34. :row-class-name="tableRowClassName"
  35. >
  36. <el-table-column label="姓名" min-width="10" align="center">
  37. <template slot-scope="scope">
  38. <div class="userImg">
  39. <div>
  40. {{ scope.row.name }}
  41. </div>
  42. </div>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="电话" min-width="10" align="center">
  46. <template slot-scope="scope">
  47. <div>{{ scope.row.phone ? scope.row.phone : "-" }}</div>
  48. </template>
  49. </el-table-column>
  50. <el-table-column
  51. prop="level"
  52. label="权限等级"
  53. min-width="10"
  54. align="center"
  55. ><template slot-scope="scope">
  56. <div>{{ scope.row.schoolName }}</div>
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="操作" min-width="20">
  60. <template slot-scope="scope">
  61. <div class="tableButton">
  62. <el-button @click="upUser(scope.row)">修改</el-button>
  63. <el-button @click="deUser(scope.row.userid)">删除</el-button>
  64. </div>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. </div>
  69. <div class="student_page">
  70. <el-pagination
  71. background
  72. layout="prev, pager, next"
  73. :page-size="10"
  74. :total="total"
  75. v-if="page"
  76. @current-change="handleCurrentChange"
  77. ></el-pagination>
  78. </div>
  79. </div>
  80. <el-dialog
  81. title="添加管理员"
  82. :visible.sync="dialogVisible"
  83. :append-to-body="true"
  84. width="500px"
  85. :before-close="handleClose"
  86. class="dialog_diy"
  87. >
  88. <el-form class="inputClass">
  89. <el-form-item label="名称" :label-width="formLabelWidth">
  90. <span>
  91. <el-input
  92. placeholder="请输入名称"
  93. clearable
  94. v-model="sName"
  95. class="add_input"
  96. ></el-input>
  97. </span>
  98. </el-form-item>
  99. <el-form-item label="手机号" :label-width="formLabelWidth">
  100. <span>
  101. <el-input
  102. placeholder="请输入手机号"
  103. clearable
  104. v-model="sPhone"
  105. class="add_input"
  106. ></el-input>
  107. </span>
  108. </el-form-item>
  109. <el-form-item label="学校选择" :label-width="formLabelWidth">
  110. <el-select
  111. v-model="sSchool"
  112. filterable
  113. clearable
  114. @clear="clearSchoolList"
  115. :allow-create="false"
  116. @focus="remoteMethodclick"
  117. remote
  118. placeholder="请输入学校"
  119. :remote-method="remoteMethod"
  120. :loading="loading"
  121. no-data-text="暂未查询到此学校"
  122. >
  123. <el-option
  124. v-for="item in options"
  125. :key="item.value"
  126. :label="item.label"
  127. :value="item.value"
  128. >
  129. </el-option>
  130. </el-select>
  131. </el-form-item>
  132. <div style="text-align: center; color: #adb3b7">
  133. 注:添加账号账号密码为123456
  134. </div>
  135. </el-form>
  136. <span slot="footer" class="dialog-footer flex">
  137. <el-button class="left" @click="dialogVisible = false">取消</el-button>
  138. <el-button class="right" @click="addRaceUser" v-if="isAddOrUp == false"
  139. >确认</el-button
  140. >
  141. <el-button
  142. class="right"
  143. @click="updateRaceUser"
  144. v-if="isAddOrUp == true"
  145. >修改</el-button
  146. >
  147. </span>
  148. </el-dialog>
  149. </div>
  150. </template>
  151. <script>
  152. export default {
  153. data() {
  154. return {
  155. suser: "",
  156. tableData: [],
  157. tableHeight: "500px",
  158. isLoading: false,
  159. formLabelWidth: "100px",
  160. page: 1,
  161. total: 0,
  162. dialogVisible: false,
  163. isAddOrUp: false,
  164. sName: "",
  165. sPhone: "",
  166. sType: "",
  167. upId: "",
  168. sSchool: "",
  169. checkboxList: [],
  170. checkboxIdList: [],
  171. schoolList: [],
  172. isIndeterminate: false,
  173. checkAll: false,
  174. options: [],
  175. list: [],
  176. loading: false,
  177. };
  178. },
  179. mounted() {
  180. this.$nextTick(function () {
  181. this.tableHeight =
  182. window.innerHeight - this.$refs.table.$el.offsetTop - 200;
  183. if (this.tableHeight <= 530) {
  184. this.tableHeight = 530;
  185. }
  186. // 监听窗口大小变化
  187. let self = this;
  188. window.onresize = function () {
  189. self.tableHeight =
  190. window.innerHeight - self.$refs.table.$el.offsetTop - 200;
  191. if (self.tableHeight <= 530) {
  192. self.tableHeight = 530;
  193. }
  194. };
  195. });
  196. },
  197. methods: {
  198. tableRowClassName({ row, rowIndex }) {
  199. if ((rowIndex + 1) % 2 === 0) {
  200. return "even_row";
  201. } else {
  202. return "";
  203. }
  204. },
  205. remoteMethodclick() {
  206. if (!this.options.length) {
  207. var _option = [];
  208. for (var i = 0; i < 10; i++) {
  209. var _a = this.randomNum(0, 10);
  210. _option.push(this.list[_a]);
  211. }
  212. this.options = _option;
  213. }
  214. },
  215. randomNum(minNum, maxNum) {
  216. switch (arguments.length) {
  217. case 1:
  218. return parseInt(Math.random() * minNum + 1, 10);
  219. break;
  220. case 2:
  221. return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
  222. break;
  223. default:
  224. return 0;
  225. break;
  226. }
  227. },
  228. remoteMethod(query) {
  229. if (query !== "") {
  230. this.loading = true;
  231. setTimeout(() => {
  232. this.loading = false;
  233. this.options = this.list.filter((item) => {
  234. return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
  235. });
  236. }, 200);
  237. } else {
  238. // this.options = [];
  239. var _option = [];
  240. for (var i = 0; i < 10; i++) {
  241. var _a = this.randomNum(0, 10);
  242. _option.push(this.list[_a]);
  243. }
  244. this.options = _option;
  245. }
  246. },
  247. handleClose(done) {
  248. done();
  249. },
  250. handleCurrentChange(val) {
  251. this.page = val;
  252. this.getAdmin();
  253. },
  254. clearSchoolList() {
  255. this.sSchool = "";
  256. },
  257. search() {
  258. this.page = 1;
  259. this.getAdmin();
  260. },
  261. addUser() {
  262. this.sName = "";
  263. this.sPhone = "";
  264. this.sSchool = "";
  265. this.isAddOrUp = false;
  266. this.dialogVisible = true;
  267. },
  268. addRaceUser() {
  269. if (this.sName == "") {
  270. this.$message.error("请输入名称");
  271. return;
  272. } else if (this.sPhone == "") {
  273. this.$message.error("请输入手机号");
  274. return;
  275. } else if (
  276. this.sId != "" &&
  277. !/^[1][3,4,5,7,8][0-9]{9}$/.test(this.sPhone)
  278. ) {
  279. this.$message.error("手机号格式不正确");
  280. return;
  281. } else if (this.sSchool == "") {
  282. this.$message.error("请选择学校");
  283. return;
  284. }
  285. this.isloading = true;
  286. let params = [
  287. {
  288. reg: "",
  289. res: "",
  290. sch: this.sSchool,
  291. n: this.sName,
  292. p: this.sPhone,
  293. t: 4,
  294. parent: this.$store.state.userInfo.userid,
  295. },
  296. ];
  297. this.ajax
  298. .post(this.$store.state.api + "addRaceUser", params)
  299. .then((res) => {
  300. this.$message({
  301. message: "创建成功",
  302. type: "success",
  303. });
  304. this.isloading = false;
  305. this.sName = "";
  306. this.sPhone = "";
  307. this.sType = "";
  308. this.dialogVisible = false;
  309. this.getAdmin();
  310. })
  311. .catch((err) => {
  312. this.isloading = false;
  313. this.$message.error("创建失败");
  314. console.error(err);
  315. });
  316. },
  317. upUser(r) {
  318. this.sName = r.name;
  319. this.sPhone = r.phone;
  320. this.sSchool = r.schoolName;
  321. this.upId = r.userid;
  322. this.isAddOrUp = true;
  323. this.dialogVisible = true;
  324. },
  325. updateRaceUser() {
  326. let params = {
  327. n: this.sName,
  328. p: this.sPhone,
  329. t: 4,
  330. s: this.sSchool,
  331. uid: this.upId,
  332. };
  333. this.ajax
  334. .get(this.$store.state.api + "updateReviewer", params)
  335. .then((res) => {
  336. this.$message({
  337. message: "修改成功",
  338. type: "success",
  339. });
  340. this.sName = "";
  341. this.sPhone = "";
  342. this.sType = "";
  343. this.upId = "";
  344. this.isAddOrUp = false;
  345. this.dialogVisible = false;
  346. this.getAdmin();
  347. })
  348. .catch((err) => {
  349. console.error(err);
  350. });
  351. },
  352. deUser(id) {
  353. this.$confirm("确定删除该账号吗?", "提示", {
  354. confirmButtonText: "确定",
  355. cancelButtonText: "取消",
  356. type: "warning",
  357. })
  358. .then(() => {
  359. let params = {
  360. uid: id,
  361. };
  362. this.ajax
  363. .get(this.$store.state.api + "deleteReviewer", params)
  364. .then((res) => {
  365. this.$message({
  366. message: "删除成功",
  367. type: "success",
  368. });
  369. this.dialogVisible = false;
  370. this.getAdmin();
  371. })
  372. .catch((err) => {
  373. console.error(err);
  374. });
  375. })
  376. .catch(() => {});
  377. },
  378. getAdmin() {
  379. let params = {
  380. uid: this.$store.state.userInfo.userid,
  381. cn: this.suser,
  382. page: this.page,
  383. };
  384. this.ajax
  385. .get(this.$store.state.api + "selectReviewer", params)
  386. .then((res) => {
  387. this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
  388. this.tableData = res.data[0];
  389. this.reviewerBox = res.data[0];
  390. })
  391. .catch((err) => {
  392. console.error(err);
  393. });
  394. },
  395. getSchool() {
  396. this.isloading = true;
  397. let params = {
  398. n: "",
  399. };
  400. this.ajax
  401. .get(this.$store.state.api + "getSchool", params)
  402. .then((res) => {
  403. this.schoolList = res.data[0];
  404. this.list = this.schoolList.map((item) => {
  405. return { value: item.id, label: item.name };
  406. });
  407. var _option = [];
  408. for (var i = 0; i < 10; i++) {
  409. var _a = this.randomNum(0, this.list.length);
  410. _option.push(this.list[_a]);
  411. }
  412. this.options = _option;
  413. this.isloading = false;
  414. })
  415. .catch((err) => {
  416. this.isloading = false;
  417. console.error(err);
  418. });
  419. },
  420. },
  421. created() {
  422. this.getAdmin();
  423. this.getSchool();
  424. },
  425. };
  426. </script>
  427. <style scoped>
  428. .dialog_diy >>> .el-dialog__header,
  429. .dialog_diy1 >>> .el-dialog__header {
  430. background: #3d67bd !important;
  431. padding: 15px 20px;
  432. }
  433. .dialog_diy1 >>> .el-dialog__header {
  434. text-align: center;
  435. }
  436. .dialog_diy >>> .el-dialog__title,
  437. .dialog_diy1 >>> .el-dialog__title {
  438. color: #fff;
  439. }
  440. .dialog_diy >>> .el-dialog__headerbtn,
  441. .dialog_diy1 >>> .el-dialog__headerbtn {
  442. top: 19px;
  443. }
  444. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close,
  445. .dialog_diy1 >>> .el-dialog__headerbtn .el-dialog__close {
  446. color: #fff;
  447. }
  448. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close:hover,
  449. .dialog_diy1 >>> .el-dialog__headerbtn .el-dialog__close:hover {
  450. color: #fff;
  451. }
  452. .dialog_diy >>> .el-dialog__body,
  453. .dialog_diy >>> .el-dialog__footer,
  454. .dialog_diy1 >>> .el-dialog__body,
  455. .dialog_diy1 >>> .el-dialog__footer {
  456. background: #fafafa;
  457. }
  458. /* .inputClass.is-active >>> .el-input__inner,
  459. .inputClass >>> .el-input__inner:focus {
  460. border-color: #5c549f;
  461. }
  462. .inputClass >>> .el-select .el-input.is-focus .el-input__inner {
  463. border-color: #5c549f;
  464. }
  465. .inputClass >>> .el-select .el-input__inner:focus {
  466. border-color: #5c549f;
  467. } */
  468. .left {
  469. background: #fff !important;
  470. color: #000 !important;
  471. }
  472. .right,
  473. .left {
  474. width: 80px;
  475. color: #fff;
  476. background: #409efe;
  477. margin-bottom: 20px;
  478. }
  479. .touTop {
  480. margin: 15px auto;
  481. display: flex;
  482. flex-direction: row;
  483. flex-wrap: nowrap;
  484. align-items: center;
  485. justify-content: space-between;
  486. width: 95%;
  487. }
  488. .touLeft {
  489. display: flex;
  490. flex-direction: row;
  491. flex-wrap: nowrap;
  492. align-items: center;
  493. }
  494. .touLeft > div {
  495. display: flex;
  496. flex-direction: row;
  497. flex-wrap: nowrap;
  498. align-items: center;
  499. }
  500. .touLeft > div > .el-button {
  501. background: #2268bd;
  502. color: #fff;
  503. margin-left: 10px;
  504. }
  505. .touRight > div:nth-child(2) > .el-button {
  506. background: #2268bd;
  507. color: #fff;
  508. }
  509. .student_table >>> .el-table--border td {
  510. border-right: 0px !important;
  511. }
  512. .student_table >>> .el-table,
  513. .student_table >>> .el-table__body-wrapper {
  514. height: auto !important;
  515. }
  516. .student_page {
  517. margin-top: 10px;
  518. }
  519. .tableButton {
  520. display: flex;
  521. flex-direction: row;
  522. flex-wrap: nowrap;
  523. align-items: center;
  524. }
  525. .tableButton > .el-button {
  526. background: #409efe;
  527. color: #fff;
  528. cursor: pointer;
  529. }
  530. .customWidth >>> .el-dialog {
  531. min-width: 500px !important;
  532. }
  533. .t_j_box {
  534. display: flex;
  535. }
  536. .t_j_box span:nth-child(1) {
  537. width: 15%;
  538. overflow: hidden;
  539. margin-right: 10px;
  540. text-overflow: ellipsis;
  541. white-space: nowrap;
  542. }
  543. .t_j_box span:nth-child(2) {
  544. width: 300px;
  545. overflow: hidden;
  546. text-overflow: ellipsis;
  547. margin-right: 10px;
  548. }
  549. .t_j_box span:nth-child(3) {
  550. width: calc(55% - 20px);
  551. overflow: hidden;
  552. text-overflow: ellipsis;
  553. }
  554. .people_name {
  555. display: flex;
  556. flex-direction: column;
  557. flex-wrap: wrap;
  558. align-items: flex-start;
  559. padding: 15px 0 0 15px;
  560. }
  561. .people_name >>> .el-checkbox {
  562. margin-bottom: 10px;
  563. }
  564. </style>