index.vue 12 KB

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