class.vue 6.6 KB

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