classGM.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <div
  3. class="pb_content"
  4. style="background: unset; overflow: auto; height: 100%"
  5. >
  6. <div
  7. class="pb_content_body"
  8. style="
  9. background: #fff;
  10. padding: 0px 25px;
  11. box-sizing: border-box;
  12. margin: 10px auto 0;
  13. "
  14. >
  15. <div class="pb_head top">
  16. <span>班级管理</span>
  17. <div class="student_button">
  18. <el-button
  19. type="primary"
  20. class="bgColor btnClassGM"
  21. @click="dialogVisible = true"
  22. >添加班级</el-button
  23. >
  24. </div>
  25. </div>
  26. <div class="student_head">
  27. <div class="student_search">
  28. <span>
  29. <el-input
  30. placeholder="请输入班级名称"
  31. v-model="sClassName"
  32. clearable
  33. >
  34. </el-input>
  35. </span>
  36. <el-button class="btnClassGM" type="primary" @click="searchClass">查询</el-button>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="pb_content_body" style="margin:0 auto">
  41. <div class="student_table">
  42. <el-table
  43. ref="table"
  44. :data="tableData"
  45. border
  46. :height="tableHeight"
  47. :fit="true"
  48. v-loading="isLoading"
  49. style="width: 100%; height: 60%"
  50. :header-cell-style="{ background: '#f1f1f1' }"
  51. :row-class-name="tableRowClassName"
  52. >
  53. <el-table-column
  54. prop="name"
  55. label="班级名称"
  56. min-width="40%"
  57. align="center"
  58. >
  59. </el-table-column>
  60. <el-table-column
  61. prop="pnum"
  62. label="人数"
  63. min-width="40%"
  64. align="center"
  65. >
  66. </el-table-column>
  67. <el-table-column label="操作" min-width="20%">
  68. <template slot-scope="scope">
  69. <el-button
  70. class="btnClassGM"
  71. type="primary"
  72. size="small"
  73. @click="deleteClass(scope.row.id)"
  74. >删除</el-button
  75. >
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. </div>
  80. <div class="student_page">
  81. <el-pagination
  82. background
  83. layout="prev, pager, next"
  84. :page-size="10"
  85. :total="total"
  86. v-if="page"
  87. @current-change="handleCurrentChange"
  88. >
  89. </el-pagination>
  90. </div>
  91. </div>
  92. <el-dialog
  93. title="添加学生"
  94. :visible.sync="dialogVisible"
  95. :append-to-body="true"
  96. width="25%"
  97. :before-close="handleClose"
  98. class="dialog_diy"
  99. >
  100. <el-form>
  101. <el-form-item label="班级名称" :label-width="formLabelWidth">
  102. <el-input
  103. v-model="className"
  104. auto-complete="off"
  105. placeholder="请输入班级..."
  106. ></el-input>
  107. </el-form-item>
  108. </el-form>
  109. <span slot="footer" class="dialog-footer">
  110. <el-button class="cancelbtnGM" @click="dialogVisible = false">取 消</el-button>
  111. <el-button class="btnClassGM" type="primary" @click="insertClass">确 定</el-button>
  112. </span>
  113. </el-dialog>
  114. </div>
  115. </template>
  116. <script>
  117. export default {
  118. data() {
  119. return {
  120. tableHeight: "500px",
  121. isLoading: false,
  122. formLabelWidth: "100px",
  123. sClassName: "",
  124. className: "",
  125. dialogVisible: false,
  126. tableData: [],
  127. page: 1,
  128. total: 0,
  129. userid: this.$route.query.userid,
  130. oid: this.$route.query.oid,
  131. };
  132. },
  133. created() {
  134. this.page = 1;
  135. this.getClass();
  136. },
  137. mounted() {
  138. this.$nextTick(function () {
  139. this.tableHeight =
  140. window.innerHeight - this.$refs.table.$el.offsetTop - 200;
  141. if (this.tableHeight <= 530) {
  142. this.tableHeight = 530;
  143. }
  144. // 监听窗口大小变化
  145. let self = this;
  146. window.onresize = function () {
  147. self.tableHeight =
  148. window.innerHeight - self.$refs.table.$el.offsetTop - 200;
  149. if (self.tableHeight <= 530) {
  150. self.tableHeight = 530;
  151. }
  152. };
  153. });
  154. },
  155. methods: {
  156. tableRowClassName({ row, rowIndex }) {
  157. if ((rowIndex + 1) % 2 === 0) {
  158. return "even_row";
  159. } else {
  160. return "";
  161. }
  162. },
  163. handleCurrentChange(val) {
  164. this.page = val;
  165. this.getClass();
  166. },
  167. handleClose(done) {
  168. done();
  169. },
  170. time() {
  171. if (!this.now) {
  172. this.now = new Date().getTime();
  173. return true;
  174. } else {
  175. let time = new Date().getTime();
  176. if (time - this.now > 3000) {
  177. this.now = time;
  178. return true;
  179. } else {
  180. return false;
  181. }
  182. }
  183. },
  184. searchClass() {
  185. this.page = 1;
  186. this.getClass();
  187. },
  188. //新增班级
  189. insertClass() {
  190. let params = {
  191. name: this.className,
  192. oid: this.oid,
  193. uid: this.userid,
  194. };
  195. this.ajax
  196. .get(this.$store.state.api + "insertClass", params)
  197. .then((res) => {
  198. this.$message({
  199. message: "新增成功",
  200. type: "success",
  201. });
  202. this.dialogVisible = false;
  203. this.sClassName = "";
  204. this.getClass();
  205. this.className = "";
  206. })
  207. .catch((err) => {
  208. this.$message({
  209. message: "新增失败",
  210. type: "error",
  211. });
  212. console.error(err);
  213. });
  214. },
  215. //获取班级列表
  216. getClass() {
  217. this.isLoading = true;
  218. let params = {
  219. // username: this.$store.state.userInfo.userid,
  220. cu: "",
  221. oid: this.oid,
  222. cn: this.sClassName,
  223. page: this.page,
  224. };
  225. this.ajax
  226. .get(this.$store.state.api + "selectClass", params)
  227. .then((res) => {
  228. this.isLoading = false;
  229. this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
  230. this.tableData = res.data[0];
  231. })
  232. .catch((err) => {
  233. this.isLoading = false;
  234. console.error(err);
  235. });
  236. },
  237. //删除班级
  238. deleteClass(id) {
  239. let params = {
  240. id: id,
  241. };
  242. if (this.time()) {
  243. this.$confirm("确定删除此课程吗?", "提示", {
  244. confirmButtonText: "确定",
  245. cancelButtonText: "取消",
  246. type: "warning",
  247. })
  248. .then(() => {
  249. this.ajax
  250. .get(this.$store.state.api + "deleteClass", params)
  251. .then((res) => {
  252. this.$message({
  253. message: "删除成功",
  254. type: "success",
  255. });
  256. if (this.page != 1 && this.tableData.length == 1) {
  257. this.page - 1;
  258. }
  259. this.getClass();
  260. })
  261. .catch((err) => {
  262. this.$message.error("删除失败");
  263. console.error(err);
  264. });
  265. })
  266. .catch(() => {});
  267. }
  268. },
  269. },
  270. };
  271. </script>
  272. <style scoped>
  273. .dialog_diy >>> .el-dialog__header {
  274. background: #454545 !important;
  275. padding: 15px 20px;
  276. }
  277. .dialog_diy >>> .el-dialog__title {
  278. color: #fff;
  279. }
  280. .student_table >>> .el-table--border td {
  281. border-right: 0px !important;
  282. }
  283. .dialog_diy >>> .el-dialog__headerbtn {
  284. top: 19px;
  285. }
  286. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close {
  287. color: #fff;
  288. }
  289. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close:hover {
  290. color: #fff;
  291. }
  292. .student_head >>> .el-button--primary {
  293. /* background-color: #2268bc; */
  294. }
  295. .xls_button {
  296. font-size: 14px;
  297. cursor: pointer;
  298. text-decoration: underline;
  299. color: rgb(34, 104, 188);
  300. }
  301. .pb_head {
  302. margin: 0 !important;
  303. width: 100% !important;
  304. }
  305. .student_page {
  306. margin-top: 10px;
  307. }
  308. .student_head {
  309. margin-top: 10px;
  310. padding-bottom: 15px;
  311. display: flex;
  312. justify-content: space-between;
  313. }
  314. .student_search {
  315. display: flex;
  316. width: 300px;
  317. }
  318. .student_search span {
  319. margin: 0 10px 0 0;
  320. }
  321. .student_button {
  322. display: flex;
  323. overflow: hidden;
  324. height: 40px;
  325. }
  326. .student_button .el-button--primary {
  327. /* margin-right: 10px; */
  328. }
  329. .upload-demo {
  330. display: flex;
  331. flex-direction: column;
  332. align-items: end;
  333. /* position: relative; */
  334. width: 100px;
  335. overflow: hidden;
  336. }
  337. .student_table {
  338. /* margin: 20px 0; */
  339. }
  340. .el-table >>> .even_row {
  341. background-color: #f1f1f1;
  342. }
  343. .top {
  344. display: flex;
  345. justify-content: space-between;
  346. }
  347. .bgColor {
  348. /* background: #2167bc; */
  349. }
  350. .student_table >>> .el-table,
  351. .student_table >>> .el-table__body-wrapper {
  352. height: auto !important;
  353. }
  354. .student_page
  355. >>> .el-pagination.is-background
  356. .el-pager
  357. li:not(.disabled).active {
  358. background-color: #5c549f;
  359. color: #fff !important;
  360. }
  361. .student_page
  362. >>> .el-pagination.is-background
  363. .el-pager
  364. li:not(.disabled):hover {
  365. color: #5c549f;
  366. }
  367. </style>