index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <div class="box">
  3. <div class="rigbox">
  4. <div class="centerCss">
  5. <img src="../../../assets/stuImg/riqi.svg" alt="" />
  6. <span style="color: #86909c; font-size: 12px">年级管理</span>
  7. </div>
  8. <!-- v-if="orglist.includes(org)" -->
  9. <template v-loading="boxLoading">
  10. <div style="display: flex; gap: 10px;">
  11. <div v-if="orglist.includes(org)" class="Clabtn" @click="openaddClass(1)">
  12. <img src="../../../assets/stuImg/jia.svg" alt="" />
  13. <span>新年级</span>
  14. </div>
  15. <div class="Clabtn" @click="openaddClass(0)">
  16. <img src="../../../assets/stuImg/jia.svg" alt="" />
  17. <span>新班级</span>
  18. </div>
  19. </div>
  20. <el-menu
  21. :default-active="activeId"
  22. class="el-menu-vertical-demo"
  23. >
  24. <el-submenu v-for="item in tableData" :index="item.id" :key="item.id">
  25. <template slot="title">
  26. <span>{{ item.name }}</span>
  27. <img
  28. class="grade-submenu-arrow"
  29. src="../../../assets/stuImg/zankai.svg"
  30. alt=""
  31. />
  32. </template>
  33. <el-menu-item-group
  34. v-for="k in item.children"
  35. :key="k.id"
  36. :title="k.name"
  37. >
  38. <el-menu-item :index="k.id" style="font-weight: normal;" @click="handleClick(k.id, 0,k)">
  39. <span>{{ k.name }}</span>
  40. <span>({{ k.pnum }}人)</span>
  41. </el-menu-item>
  42. </el-menu-item-group>
  43. </el-submenu>
  44. </el-menu>
  45. </template>
  46. <div class="line"></div>
  47. <div class="centerCss">
  48. <img src="../../../assets/stuImg/inf.svg" alt="" />
  49. <span style="color: #86909c; font-size: 12px">兴趣班管理</span>
  50. </div>
  51. <div
  52. class="por"
  53. :class="{ active: boxType == 1 }"
  54. @click="handleClick('1', 1)"
  55. >
  56. 兴趣班列表
  57. </div>
  58. <div class="line"></div>
  59. <div class="centerCss">
  60. <img src="../../../assets/stuImg/per.svg" alt="" />
  61. <span style="color: #86909c; font-size: 12px">学生管理</span>
  62. </div>
  63. <div
  64. class="por"
  65. :class="{ active: boxType == 2 }"
  66. @click="handleClick('2', 2)"
  67. >
  68. 学生列表
  69. </div>
  70. </div>
  71. <!-- 右侧table区域 -->
  72. <div class="leftbox">
  73. <tableL
  74. :activeIdL="activeId"
  75. :boxType="boxType"
  76. :GrapTableData="cascaderData"
  77. :activeinfoData="activeinfo"
  78. @getGrade="getGrade"
  79. ></tableL>
  80. </div>
  81. <!-- 新增班级 -->
  82. <el-dialog
  83. title="添加班级"
  84. :visible.sync="addClassVisible"
  85. width="427px"
  86. :show-close="false"
  87. class="addClassDialog"
  88. >
  89. <div class="addcla_box">
  90. <div class="addcla_box_item">
  91. <span>所属年级:</span>
  92. <el-select v-model="addclaGrade" placeholder="请选择年级">
  93. <el-option
  94. v-for="item in tableData"
  95. :key="item.id"
  96. :label="item.name"
  97. :value="item.id"
  98. ></el-option>
  99. </el-select>
  100. </div>
  101. <div class="addcla_box_item">
  102. <span>班级名称:</span>
  103. <el-input
  104. v-model="addclaName"
  105. placeholder="请输入班级名称"
  106. ></el-input>
  107. </div>
  108. </div>
  109. <div slot="footer" class="dialog-footer">
  110. <div @click="addClassVisible = false">取消</div>
  111. <div @click="addClass" style="background: #3681FC; color: #E3EDFF;">确认</div>
  112. </div>
  113. </el-dialog>
  114. <el-dialog
  115. title="添加年级"
  116. :visible.sync="addgraVisible"
  117. width="500px"
  118. :show-close="false"
  119. class="addClassDialog"
  120. >
  121. <div class="addcla_box">
  122. <div class="addcla_box_item">
  123. <span>年级:</span>
  124. <el-input v-model.trim="addgraName" placeholder="请输入年级"></el-input>
  125. </div>
  126. </div>
  127. <div slot="footer" class="dialog-footer">
  128. <div @click="addgraVisible = false" style="color: #363636;">取消</div>
  129. <div @click="addgra" style="background: #3681FC; color: #E6FFFFFF;">确认</div>
  130. </div>
  131. </el-dialog>
  132. </div>
  133. </template>
  134. <script>
  135. import tableL from "./component/table.vue";
  136. export default {
  137. components: {
  138. tableL,
  139. },
  140. data() {
  141. return {
  142. userid: this.$route.query.userid,
  143. org: this.$route.query.org,
  144. oid: this.$route.query.oid,
  145. role: this.$route.query.role,
  146. boxLoading: false, //年级区域loading
  147. addClassVisible: false,
  148. addgraVisible:false,
  149. addclaName: "", // 新增班级名称
  150. addclaGrade: "", // 新增班级所属年级
  151. addgraName:'',
  152. orglist:[
  153. "1973f6c7-1561-11ee-91d8-005056b86db5",
  154. "16ace517-b5c7-4168-a9bb-a9e0035df840"
  155. ],
  156. tableData: [], //年级列表
  157. cascaderData: [], //年级列表加兴趣班列表
  158. activeId: "", // 当前选中的班级id
  159. activeinfo: {}, // 当前选中的班级信息
  160. boxType: 0, // 0:年级, 1:兴趣班, 2:学生
  161. };
  162. },
  163. methods: {
  164. // 添加年级
  165. addgra(){
  166. if (!this.addgraName) {
  167. this.$message.error('请输入年级名称')
  168. }
  169. this.boxLoading = true;
  170. let params = {
  171. name: this.addgraName,
  172. oid: this.oid,
  173. uid: this.userid,
  174. };
  175. this.ajax
  176. .get(this.$store.state.api + "insertGrade", params)
  177. .then((res) => {
  178. if (res.data[0] && res.data[0][0].classname == 1) {
  179. this.$message({
  180. message: this.lang.Cannotsameother,
  181. type: "error",
  182. });
  183. this.boxLoading = false;
  184. } else {
  185. this.$message({
  186. message: this.lang.AddSuccessful,
  187. type: "success",
  188. });
  189. this.addgraVisible = false;
  190. this.addgraName = "";
  191. this.getGrade()
  192. }
  193. })
  194. .catch((err) => {
  195. this.$message({
  196. message: this.lang.Additionfailed,
  197. type: "error",
  198. });
  199. this.boxLoading = false;
  200. console.error(err);
  201. });
  202. },
  203. //获取年级列表
  204. getGrade(val = 0) {
  205. this.boxLoading = true;
  206. let params = {
  207. oid: this.oid,
  208. };
  209. this.ajax
  210. .get(this.$store.state.api + "selectGradeNew", params)
  211. .then((res) => {
  212. this.boxLoading = false;
  213. let box1 = JSON.parse(JSON.stringify(res.data[0]));
  214. let box2 = JSON.parse(JSON.stringify(res.data[1]));
  215. let box3 = JSON.parse(JSON.stringify(res.data[0]));
  216. let box4 = JSON.parse(JSON.stringify(res.data[1]));
  217. box1.forEach((e) => {
  218. e.children = [];
  219. e.children = box2.filter((item) => item.pid == e.id);
  220. });
  221. if (box2.length) {
  222. if(this.activeId == '' || val ==1){
  223. console.log('111');
  224. this.activeId = box2[0].id;
  225. this.activeinfo = box2[0];
  226. } else {
  227. const activeItem = box2.find((item) => item.id === this.activeId);
  228. if (activeItem) {
  229. this.activeinfo = activeItem;
  230. }
  231. }
  232. }
  233. box3.push({id:0,name:"兴趣班",children:[]});
  234. // 获取所有年级的id列表(不包括兴趣班id:0)
  235. const gradeIds = box3.filter(e => e.id !== 0).map(e => e.id);
  236. box3.forEach((e) => {
  237. e.children = [];
  238. e.children = box4.filter((item) => item.pid == e.id);
  239. if (e.id === 0) {
  240. e.children = box4.filter((item) => !gradeIds.includes(item.pid));
  241. }
  242. });
  243. this.cascaderData = box3;
  244. this.tableData = box1;
  245. })
  246. .catch((err) => {
  247. this.boxLoading = false;
  248. console.error(err);
  249. });
  250. },
  251. openaddClass(val) {
  252. if (val) {
  253. this.addgraVisible = true;
  254. }else{
  255. this.addClassVisible = true;
  256. }
  257. },
  258. // 新增班级
  259. addClass() {
  260. if (!this.addclaName) {
  261. this.$message({
  262. message: "请输入班级名称",
  263. type: "error",
  264. });
  265. return;
  266. }
  267. //新增班级
  268. let params = [
  269. {
  270. claName: this.addclaName,
  271. gid: this.addclaGrade,
  272. oid: this.oid,
  273. uid: this.userid,
  274. },
  275. ];
  276. console.log(params);
  277. this.ajax
  278. .post(this.$store.state.api + "addClassgra", params)
  279. .then((res) => {
  280. if (res.data[0] && res.data[0][0].classname == 1) {
  281. this.$message({
  282. message: this.lang.Cannotsameothercla,
  283. type: "error",
  284. });
  285. } else {
  286. this.$message({
  287. message: this.lang.AddSuccessful,
  288. type: "success",
  289. });
  290. this.addClassVisible = false;
  291. this.addclaName = "";
  292. this.addclaGrade = "";
  293. this.getGrade();
  294. }
  295. })
  296. .catch((err) => {
  297. this.$message({
  298. message: this.lang.Additionfailed,
  299. type: "error",
  300. });
  301. console.error(err);
  302. });
  303. },
  304. // 切换班级
  305. handleClick(id, index,item = {}) {
  306. this.boxType = index;
  307. this.activeId = id;
  308. this.activeinfo = item;
  309. },
  310. },
  311. mounted() {
  312. this.getGrade();
  313. },
  314. };
  315. </script>
  316. <style scoped>
  317. .box {
  318. padding: 15px;
  319. box-sizing: border-box;
  320. background: #e7eaf0;
  321. display: flex;
  322. gap: 15px;
  323. width: 100%;
  324. height: 100%;
  325. font-family: PingFang SC, PingFang SC;
  326. }
  327. .rigbox {
  328. background: #fff;
  329. height: 100%;
  330. width: 176px;
  331. background: #ffffff;
  332. border-radius: 8px 8px 8px 8px;
  333. padding: 10px;
  334. flex-shrink: 0;
  335. box-sizing: border-box;
  336. display: flex;
  337. flex-direction: column;
  338. gap: 15px;
  339. overflow: auto;
  340. }
  341. .leftbox {
  342. flex: 1;
  343. }
  344. .centerCss {
  345. display: flex;
  346. align-items: center;
  347. gap: 5px;
  348. }
  349. .Clabtn {
  350. display: flex;
  351. align-items: center;
  352. justify-content: center;
  353. gap: 3px;
  354. color: #0052d9;
  355. background: #e8f3ff;
  356. border-radius: 3px;
  357. padding: 5px 4px;
  358. flex: 1;
  359. box-sizing: border-box;
  360. font-size: 14px;
  361. cursor: pointer;
  362. }
  363. .rigbox >>> .el-menu {
  364. border: none;
  365. }
  366. .rigbox >>> .el-menu-item-group__title {
  367. display: none;
  368. }
  369. .rigbox >>> .el-menu li {
  370. padding: 0 !important;
  371. font-weight: 600;
  372. margin-top: 5px;
  373. font-family: PingFang SC, PingFang SC !important;
  374. /* color: rgba(0,0,0,0.9) !important; */
  375. }
  376. .rigbox >>> .el-submenu .el-menu-item {
  377. min-width: 146px !important;
  378. max-width: 146px;
  379. height: 35px;
  380. display: flex;
  381. align-items: center;
  382. padding-left: 30px !important;
  383. }
  384. .rigbox >>> .el-menu-item.is-active {
  385. color: #fff;
  386. background: #0052d9;
  387. border-radius: 5px;
  388. }
  389. .rigbox >>> .el-submenu__title {
  390. height: 35px;
  391. display: flex;
  392. align-items: center;
  393. justify-content: space-between;
  394. }
  395. .rigbox >>> .el-submenu__title:hover{
  396. border-radius: 5px;
  397. }
  398. .rigbox >>> .grade-submenu-arrow {
  399. width: 12px;
  400. height: 12px;
  401. flex-shrink: 0;
  402. transition: transform 0.2s;
  403. }
  404. .rigbox >>> .el-submenu.is-opened > .el-submenu__title .grade-submenu-arrow {
  405. transform: rotate(180deg);
  406. }
  407. .rigbox >>> .el-submenu__icon-arrow {
  408. display: none;
  409. }
  410. .el-menu-item:focus,
  411. .el-menu-item:hover {
  412. background: none;
  413. }
  414. .line {
  415. height: 1px;
  416. background: #e6eaf0;
  417. margin: 5px 0;
  418. }
  419. .por {
  420. cursor: pointer;
  421. padding: 8px 5px;
  422. font-size: 14px;
  423. box-sizing: border-box;
  424. }
  425. .active {
  426. background: #0052d9;
  427. border-radius: 5px;
  428. color: #fff;
  429. }
  430. .addcla_box {
  431. display: flex;
  432. flex-direction: column;
  433. gap: 10px;
  434. }
  435. .addcla_box_item {
  436. display: flex;
  437. align-items: center;
  438. gap: 10px;
  439. }
  440. .addcla_box_item >>> .el-select {
  441. width: 100%;
  442. }
  443. .addcla_box_item span {
  444. /* width: 80px; */
  445. flex-shrink: 0;
  446. text-align: right;
  447. }
  448. .addClassDialog >>> .el-dialog {
  449. border-radius: 10px !important;
  450. height: 427px !important;
  451. display: flex;
  452. flex-direction: column;
  453. }
  454. .addClassDialog >>> .el-dialog__body {
  455. flex: 1;
  456. }
  457. .dialog-footer {
  458. display: flex;
  459. justify-content: flex-end;
  460. gap: 10px;
  461. }
  462. .dialog-footer div{
  463. /* width: 80px; */
  464. text-align: center;
  465. padding: 8px 14px;
  466. cursor: pointer;
  467. border-radius: 3px;
  468. box-sizing: border-box;
  469. font-size: 14px;
  470. }
  471. </style>