class.vue 8.0 KB

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