addstu.vue 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. <template>
  2. <div class="addstudia_box">
  3. <el-dialog class="addstudia" :visible.sync="addStuVisible" width="800px">
  4. <template #title>
  5. <div class="title_box">
  6. <div class="title_box_item">
  7. <span>{{ lang.ssAddStuTitle }}</span>
  8. <span v-if="boxType == 1" style="font-size: 13px"
  9. >({{ lang.ssFromExistL }})</span
  10. >
  11. </div>
  12. </div>
  13. </template>
  14. <div class="addStuBox" v-loading="userSuffixloading">
  15. <div class="bar_box" v-if="boxType != 1">
  16. <div
  17. v-for="item in stuListTypeList"
  18. :key="item.value"
  19. :class="{ active_bar: addStuType == item.value }"
  20. @click="changeStuListType(item.value)"
  21. >
  22. {{ item.label }}
  23. </div>
  24. </div>
  25. <!-- 手动添加学生 -->
  26. <div class="addcla_box" v-if="addStuType == 1">
  27. <div class="addcla_box_item" v-if="boxType != 2">
  28. <span class="addcla_box_item_span">{{ lang.ssBelongClass }}</span>
  29. <el-input
  30. v-model.trim="classInfo.name"
  31. disabled
  32. :placeholder="lang.Enterclass"
  33. ></el-input>
  34. </div>
  35. <div class="addcla_box_item" v-if="boxType == 2">
  36. <span class="addcla_box_item_span">{{ lang.ssBelongClass }}</span>
  37. <el-cascader
  38. :options="cascaderData"
  39. v-model="cascaderDataPath"
  40. @change="handleChangecascader"
  41. popper-class="myCascader"
  42. :props="{
  43. label: 'name',
  44. value: 'id',
  45. children: 'children',
  46. }"
  47. >
  48. <template slot-scope="{ data, node }">
  49. <!-- 一级选项(年级) -->
  50. <span v-if="node.level === 1">{{ data.name }}</span>
  51. <!-- 二级选项(班级)- 可以自定义显示 -->
  52. <span v-else-if="node.level === 2" class="cascader-class-item">
  53. <span>{{ data.name }}</span>
  54. </span>
  55. <!-- 其他级别(兜底) -->
  56. <span v-else>{{ data.name }}</span>
  57. </template>
  58. </el-cascader>
  59. </div>
  60. <div class="addcla_box_item" style="position: relative">
  61. <span class="addcla_box_item_span">{{ lang.StudentName }}:</span>
  62. <el-input
  63. v-model.trim="searchStuName"
  64. :placeholder="lang.ssEnterStuNameMul"
  65. slot="reference"
  66. @change="searchStu"
  67. @focus="popoverVisible = true"
  68. ></el-input>
  69. <div class="search_stu_box" v-if="popoverVisible">
  70. <div class="search_stu_box_content">
  71. <!-- <el-tag
  72. v-for="(item, index) in searchStuData"
  73. :key="index"
  74. closable
  75. :type="stuname2(item)"
  76. @close="handleClose(index)"
  77. >
  78. <span>{{ item }}</span>
  79. </el-tag> -->
  80. <div class="tagL" v-for="(item, index) in searchStuData" :key="index">
  81. <div class="tagtit" v-if="stuname2(item) == 'danger'">
  82. <div class="poptag">
  83. <img src="../../../../assets/stuImg/tishi.svg" alt=""/>
  84. <div>{{ lang.ssStuNameDup.replace(/\*/g, item) }}</div>
  85. </div>
  86. <div style="display: flex;justify-content: flex-end;gap: 10px;">
  87. <!-- <span>添加</span> -->
  88. <span style="cursor: pointer;" @click="addpopStu(item)">添加</span>
  89. <span style="cursor: pointer;color: #0052D9;" @click="delSeaStu(index)">删除</span>
  90. </div>
  91. </div>
  92. <div class="tagitem" :class="stuname2(item) == 'danger' ? 'tagitem2' :''">
  93. {{ item }}
  94. <i @click="delSeaStu(index)" class="el-icon-close closeImg"></i>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="search_stu_box_footer">
  99. <div>{{ lang.ssInputStuCnt.replace(/\*/g, searchStuData.length) }}</div>
  100. <div class="dialog-footer">
  101. <!-- <el-button size="small" @click="selectNoneStu"
  102. >取消</el-button
  103. > -->
  104. <div @click="selectNoneStu" class="kbtn">{{ lang.Cancel }}</div>
  105. <div @click="selectStu" class="kbtn" style="background: #3681FC; color: #E6FFFFFF;">{{ lang.Confirm }}</div>
  106. <!-- <el-button size="small" type="primary" @click="selectStu"
  107. >确定</el-button
  108. > -->
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <div class="addcla_box_item">
  114. <span class="addcla_box_item_span">{{ lang.ssEntered }}</span>
  115. <div class="selected_stu_box">
  116. <!-- <el-tag
  117. v-for="(item, index) in selectedStuData"
  118. :key="index"
  119. closable
  120. :type="stuname(item)"
  121. @close="handleSelectedStuClose(index)"
  122. >
  123. <span>{{ item }}</span>
  124. </el-tag> -->
  125. <div class="tagL" v-for="(item, index) in selectedStuData" :key="index">
  126. <div class="tagtit" v-if="stuname(item) == 'danger'">
  127. <div class="poptag">
  128. <img src="../../../../assets/stuImg/tishi.svg" alt=""/>
  129. <div>{{ lang.ssStuNameDup.replace(/\*/g, item) }}</div>
  130. </div>
  131. <div style="display: flex;justify-content: flex-end;gap: 10px;">
  132. <!-- <span>添加</span> -->
  133. <span style="cursor: pointer;" @click="addpopStu(item)">添加</span>
  134. <span style="cursor: pointer;color: #0052D9;" @click="handleSelectedStuClose(index)">删除</span>
  135. </div>
  136. </div>
  137. <div class="tagitem" :class="stuname(item) == 'danger' ? 'tagitem2' :''">
  138. {{ item }}
  139. <i @click="handleSelectedStuClose(index)" class="el-icon-close closeImg"></i>
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145. <!-- 批量上传学生 -->
  146. <div v-if="addStuType == 2">
  147. <div>
  148. <el-upload
  149. class="upload-demo"
  150. drag
  151. :http-request="handleChange"
  152. action="#"
  153. :show-file-list="false"
  154. accept=".xlsx,.xls"
  155. v-loading="uploadfileLoading"
  156. >
  157. <img src="@/assets/stuImg/uploadfile.svg" alt="upload" />
  158. <div style="color: #000">{{ lang.ssUploadClickDrag }}</div>
  159. <div class="upload-demo-tip">{{ lang.ssUploadTip }}</div>
  160. </el-upload>
  161. <div style="margin-top: 10px">
  162. {{ lang.ssUploadTempLbl }}
  163. <span class="download-template" @click="downloadTemplate"
  164. >{{ lang.ssDownloadTemp }}</span
  165. >
  166. <span style="margin-left: 10px;font-weight: 600;">{{ lang.ssAccColOptional }}</span>
  167. </div>
  168. <div v-if="boxType == 0" style="margin-top: 10px;font-weight: 600;">
  169. {{ lang.ssUploadNote }}
  170. </div>
  171. <div v-else style="margin-top: 10px;font-weight: 600;">
  172. {{ lang.ssSyncImportClassInfo }}
  173. </div>
  174. <!-- <div style="margin-top: 10px">
  175. 学生列表批量上传需表格需添加“班级”列
  176. </div> -->
  177. </div>
  178. </div>
  179. <!-- 从已有学生中添加 -->
  180. <div v-if="addStuType == 3">
  181. <allClaAddStu
  182. ref="allClaAddSturef"
  183. @closeAllClaAddStu="closeAllClaAddStu"
  184. @getStudent="allClaAddStuGetStudent"
  185. :classInfo="classInfo"
  186. />
  187. </div>
  188. </div>
  189. <div slot="footer" class="dialog-footer">
  190. <template v-if="addStuType == 1">
  191. <!-- <el-button size="small" @click="closeAllClaAddStu">取消</el-button> -->
  192. <div @click="closeAllClaAddStu" class="kbtn">{{ lang.Cancel }}</div>
  193. <div @click="addStu" class="kbtn" style="background: #3681FC; color: #E6FFFFFF;">{{ lang.Confirm }}</div>
  194. <!-- <el-button size="small" type="primary" @click="addStu"
  195. >确认</el-button
  196. > -->
  197. </template>
  198. </div>
  199. </el-dialog>
  200. <div class="pop-upBox">
  201. <el-dialog
  202. :visible.sync="popBoxdia"
  203. width="480px"
  204. :show-close="false"
  205. >
  206. <div class="msgCon">
  207. <img v-if="deltypy == 0 || deltypy == 2" style="width: 20px;" src="../../../../assets/stuImg/duil.svg" alt="">
  208. <img v-if="deltypy == 1" style="width: 20px;" src="../../../../assets/stuImg/tishi.svg" alt="">
  209. <div class="msgContxt">
  210. <div v-if="deltypy == 0 || deltypy == 2">
  211. {{ (impbox.length ? impbox[0].name : '') + lang.ssAddStuSucc.replace(/\*/g, impbox.length) }}
  212. </div>
  213. <div v-if="deltypy == 1">{{ lang.ssConfirmUpload }}?</div>
  214. </div>
  215. </div>
  216. <span slot="footer" class="dialog-footer">
  217. <div @click="closePop" class="kbtn" v-if="deltypy == 1">{{ lang.Cancel }}</div>
  218. <div @click="confirmDelStu" class="kbtn" style="background: #3681FC; color: #E3EDFF;">{{ lang.Confirm }}</div>
  219. </span>
  220. </el-dialog>
  221. </div>
  222. </div>
  223. </template>
  224. <script>
  225. import { v4 as uuidv4 } from "uuid";
  226. import pinyin from "../../../../../node_modules/js-pinyin/index";
  227. import allClaAddStu from "./allClaAddStu.vue";
  228. import { myMixin } from "@/mixins/mixin.js"
  229. export default {
  230. mixins: [ myMixin ],
  231. name: "addStu",
  232. props: {
  233. boxType: {
  234. type: Number,
  235. default: 0,
  236. },
  237. cascaderData: {
  238. type: Array,
  239. default: () => [],
  240. },
  241. },
  242. watch: {
  243. boxType: {
  244. handler(newVal) {
  245. if (newVal == 1) {
  246. this.stuListTypeList = [];
  247. this.addStuType = 3;
  248. } else if (newVal == 0) {
  249. this.stuListTypeList = this.tab1;
  250. this.addStuType = 1;
  251. } else if (newVal == 2) {
  252. this.stuListTypeList = this.tab2;
  253. this.addStuType = 1;
  254. }
  255. this.clearData();
  256. },
  257. immediate: true,
  258. },
  259. },
  260. components: {
  261. allClaAddStu,
  262. },
  263. data() {
  264. return {
  265. userid: this.$route.query.userid,
  266. org: this.$route.query.org,
  267. oid: this.$route.query.oid,
  268. role: this.$route.query.role,
  269. cascaderDataPath: [],
  270. userSuffixloading:false,
  271. deltypy:0,
  272. stuexcel:[],
  273. impbox:[],
  274. addpopStuList:[],
  275. popBoxdia:false,
  276. uploadfileLoading:false,
  277. addStuType: 1,
  278. schoolChar: "",
  279. userSuffix: "",
  280. addStuVisible: false,
  281. classInfo: {},
  282. stuListTypeList: [],
  283. tab1: [
  284. {
  285. label: this.lang.ssManualInput,
  286. value: 1,
  287. },
  288. {
  289. label: this.lang.ssBatchUp,
  290. value: 2,
  291. },
  292. {
  293. label: this.lang.ssFromExistL,
  294. value: 3,
  295. },
  296. ],
  297. tab2: [
  298. {
  299. label: this.lang.ssManualInput,
  300. value: 1,
  301. },
  302. {
  303. label: this.lang.ssBatchUp,
  304. value: 2,
  305. },
  306. ],
  307. searchStuName: "",
  308. searchStuData: [],
  309. selectedStuData: [],
  310. popoverVisible: false,
  311. };
  312. },
  313. computed: {
  314. stuname() {
  315. return (item) => {
  316. let box = this.selectedStuData.filter((e) => (e === item && this.addpopStuList.indexOf(item) == -1));
  317. // console.log(box);
  318. return box.length > 1 ? "danger" : "";
  319. };
  320. },
  321. stuname2() {
  322. return (item) => {
  323. let box = this.searchStuData.filter((e) => (e === item && this.addpopStuList.indexOf(item) == -1));
  324. // console.log(box);
  325. return box.length > 1 ? "danger" : "";
  326. };
  327. },
  328. },
  329. mounted() {
  330. this.getUser();
  331. this.getSchoolName();
  332. },
  333. methods: {
  334. stardop(){
  335. this.addStuVisible = true;
  336. this.searchStuName= "";
  337. console.log('666');
  338. // this.addStuType=1
  339. if (this.boxType == 1) {
  340. this.stuListTypeList = [];
  341. this.addStuType = 3;
  342. // this.nextTick(() => {
  343. // this.$refs.allClaAddSturef.clearData();
  344. // });
  345. } else if (this.boxType == 0) {
  346. this.stuListTypeList = this.tab1;
  347. this.addStuType = 1;
  348. } else if (this.boxType == 2) {
  349. this.stuListTypeList = this.tab2;
  350. this.addStuType = 1;
  351. }
  352. this.searchStuData= [];
  353. this.selectedStuData= [];
  354. this.cascaderDataPath=[];
  355. this.impbox=[];
  356. this.addpopStuList=[];
  357. },
  358. addpopStu(val){
  359. this.addpopStuList.push(val)
  360. },
  361. delSeaStu(ind){
  362. this.searchStuData.splice(ind,1)
  363. },
  364. handleChangecascader(val) {
  365. console.log(val);
  366. // 更新级联选择器的选中数据路径
  367. this.cascaderDataPath = val || [];
  368. let box = this.cascaderData.flatMap((item) => item.children).filter((item) => this.cascaderDataPath[1]==item.id);
  369. console.log(box, "box");
  370. this.classInfo = box;
  371. },
  372. clearData() {
  373. this.searchStuName = "";
  374. this.searchStuData = [];
  375. this.selectedStuData = [];
  376. this.popoverVisible = false;
  377. },
  378. allClaAddStuGetStudent() {
  379. this.$emit("getStudent");
  380. },
  381. closeAllClaAddStu() {
  382. this.addStuVisible = false;
  383. },
  384. // 下载Excel模板
  385. downloadTemplate() {
  386. require.ensure([], () => {
  387. const {
  388. export_json_to_excel,
  389. } = require("../../../../common/Export2Excel");
  390. // 增加 colWidths 参数以调整列宽,例如调整为 [20, 35, 20]
  391. let tHeader = [this.lang.StudentName, this.lang.ssStuAccHd];
  392. if (this.boxType == 2) {
  393. tHeader = [this.lang.StudentName, this.lang.Class, this.lang.ssStuAccHd];
  394. }
  395. const data = [];
  396. const colWidths = [35]; // 设置每一列的宽度
  397. export_json_to_excel(
  398. tHeader,
  399. data,
  400. this.lang.Uploadstusamples,
  401. colWidths
  402. );
  403. });
  404. },
  405. // 上传Excel添加学生
  406. handleChange(file) {
  407. if (this.uploadfileLoading) {
  408. this.$message.warning(this.lang.ssUploading);
  409. return;
  410. }
  411. if (this.userSuffix == "") {
  412. this.$message.error(this.lang.ssGetSuffixReUp);
  413. this.getUser();
  414. return;
  415. }
  416. let _this = this;
  417. // 通过DOM取文件数据
  418. var rABS = false; //是否将文件读取为二进制字符串
  419. var f = file.file;
  420. var reader = new FileReader();
  421. //if (!FileReader.prototype.readAsBinaryString) {
  422. FileReader.prototype.readAsBinaryString = function (f) {
  423. var binary = "";
  424. var rABS = false; //是否将文件读取为二进制字符串
  425. var wb; //读取完成的数据
  426. var outdata;
  427. var reader = new FileReader();
  428. reader.onload = async function (e) {
  429. var bytes = new Uint8Array(reader.result);
  430. var length = bytes.byteLength;
  431. for (var i = 0; i < length; i++) {
  432. binary += String.fromCharCode(bytes[i]);
  433. }
  434. var XLSX = require("xlsx");
  435. if (rABS) {
  436. wb = XLSX.read(btoa(fixdata(binary)), {
  437. //手动转化
  438. type: "base64",
  439. });
  440. } else {
  441. wb = XLSX.read(binary, {
  442. type: "binary",
  443. });
  444. }
  445. outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); //outdata就是你想要的东西
  446. let da = [...outdata];
  447. console.log(da, "da");
  448. let arr = [];
  449. da.map((v) => {
  450. let obj = {};
  451. if (
  452. v[_this.lang.StudentName] !== undefined &&
  453. v[_this.lang.StudentName] !== ""
  454. ) {
  455. obj.name = v[_this.lang.StudentName];
  456. const accountVal = String(v[_this.lang.ssStuAccHd] || '').trim();
  457. if (
  458. _this.org != "" &&
  459. _this.org != "null" &&
  460. _this.org != undefined &&
  461. _this.org &&
  462. _this.schoolChar
  463. ) {
  464. if (accountVal && /^[a-zA-Z0-9]+$/.test(accountVal)) {
  465. obj.account = accountVal + '@' + _this.schoolChar + '.' + _this.userSuffix;
  466. } else {
  467. obj.account = '';
  468. }
  469. obj.mail =
  470. uuidv4() + "@" + _this.schoolChar + "." + _this.userSuffix;
  471. } else {
  472. if (accountVal && /^[a-zA-Z0-9]+$/.test(accountVal)) {
  473. obj.account = accountVal + '@' + _this.userSuffix;
  474. } else {
  475. obj.account = '';
  476. }
  477. obj.mail = uuidv4() + "@" + _this.userSuffix;
  478. }
  479. obj.class = _this.boxType == 2 ? v[_this.lang.Class] : _this.classInfo.id;
  480. arr.push(obj);
  481. }else{
  482. _this.$message.error(_this.lang.ssCheckStuNameCol);
  483. return;
  484. }
  485. });
  486. console.log(arr);
  487. if (!arr.length) {
  488. _this.$message.error(
  489. _this.lang.ssParseStuFail
  490. );
  491. return;
  492. }
  493. if (_this.boxType == 2) {
  494. let stuClassInfo = await _this.getClassInfo();
  495. console.log(stuClassInfo, "stuClassInfo");
  496. arr.forEach((e) => {
  497. let classInfo = stuClassInfo.find(item => item.name == e.class);
  498. if (classInfo) {
  499. e.class = classInfo.id;
  500. } else {
  501. e.class = '';
  502. }
  503. });
  504. }
  505. console.log(arr, "arr");
  506. if (_this.boxType == 2 && arr.filter(e => e.class).length !== arr.length) {
  507. _this.$message.error(_this.lang.ssCheckClassCol);
  508. return;
  509. }
  510. // 打开确认上传弹窗
  511. _this.deltypy = 1;
  512. _this.popBoxdia= true;
  513. _this.stuexcel = arr;
  514. };
  515. reader.readAsArrayBuffer(f);
  516. };
  517. if (rABS) {
  518. reader.readAsArrayBuffer(f);
  519. } else {
  520. reader.readAsBinaryString(f);
  521. }
  522. },
  523. async getClassInfo() {
  524. return new Promise((resolve, reject) => {
  525. let params = {
  526. oid: this.oid,
  527. };
  528. this.ajax
  529. .get(this.$store.state.api + "selectGradeNew", params)
  530. .then((res) => {
  531. let box1 = JSON.parse(JSON.stringify(res.data[0]));
  532. let box2 = JSON.parse(JSON.stringify(res.data[1]));
  533. // box1.push({id:0,name:this.lang.ssInterestClass});
  534. const gradeIds = box1.filter(e => e.id !== 0).map(e => e.id);
  535. let box3 = [];
  536. box2.forEach((e) => {
  537. if (gradeIds.includes(e.pid)) {
  538. e.name = box1.find(item => item.id == e.pid).name + e.name;
  539. box3.push(e);
  540. }
  541. });
  542. resolve(box3);
  543. })
  544. .catch((err) => {
  545. console.error(err);
  546. reject(err);
  547. });
  548. });
  549. },
  550. // 手动输入添加学生
  551. addStu() {
  552. if (this.uploadfileLoading) {
  553. this.$message.warning(this.lang.ssUploading);
  554. return;
  555. }
  556. this.selectedStuData = this.selectedStuData.filter((item) => item != "");
  557. if (this.selectedStuData.length == 0) {
  558. this.$message.error(this.lang.ssEnterStu);
  559. return;
  560. }
  561. if (this.selectedStuData.length > 70) {
  562. this.$message.error(this.lang.ssAddStuMax70);
  563. return;
  564. }
  565. if ((this.boxType == 2 && this.cascaderDataPath.length == 0) || this.classInfo.name == "") {
  566. this.$message.error(this.lang.ssSelectBelCla);
  567. return;
  568. }
  569. if (this.userSuffix == "") {
  570. this.$message.error(this.lang.ssGetSuffixReAdd);
  571. this.getUser();
  572. return;
  573. }
  574. let mail = "";
  575. if (
  576. this.org != "" &&
  577. this.org != "null" &&
  578. this.org != undefined &&
  579. this.org &&
  580. this.schoolChar
  581. ) {
  582. mail = "@" + this.schoolChar + "." + this.userSuffix;
  583. } else {
  584. mail = "@" + this.userSuffix;
  585. }
  586. let classInfo = this.classInfo;
  587. if (this.boxType == 2) {
  588. classInfo = this.cascaderData.flatMap((item) => item.children).filter((item) => this.cascaderDataPath[1]==item.id)[0];
  589. }
  590. let box = this.selectedStuData.map((item) => {
  591. return {
  592. name: item,
  593. mail: uuidv4() + mail,
  594. class: classInfo.id,
  595. };
  596. });
  597. // 手动输入添加学生,打开弹框
  598. this.accUpdate(box,0);
  599. },
  600. async accUpdate(box,index) {
  601. console.log(box, "box");
  602. this.uploadfileLoading = true;
  603. this.impbox = box;
  604. let data1 = box.filter(e => !e.account);
  605. let data2 = box.filter(e => e.account);
  606. data2.forEach((e) => {
  607. e.mail = e.account;
  608. });
  609. try {
  610. const batchSize = 50;
  611. if (data1.length > 0) {
  612. if (data1.length > batchSize) {
  613. // 计算总批次数
  614. const totalBatches = Math.ceil(data1.length / batchSize);
  615. for (let i = 0; i < totalBatches; i++) {
  616. const batch = data1.slice(i * batchSize, (i + 1) * batchSize);
  617. await this.uploadBatch(batch); // 假设 uploadBatch 返回 Promise
  618. console.log(`普通上传第 ${i + 1} 批上传完成`, batch);
  619. }
  620. } else {
  621. // 长度不超过 10,直接上传整个数组
  622. await this.uploadBatch(data1);
  623. }
  624. }
  625. if (data2.length > 0) {
  626. if (data2.length > batchSize) {
  627. // 计算总批次数
  628. const totalBatches = Math.ceil(data2.length / batchSize);
  629. for (let i = 0; i < totalBatches; i++) {
  630. const batch = data2.slice(i * batchSize, (i + 1) * batchSize);
  631. await this.uploadBatchAccount (batch); // 假设 uploadBatch 返回 Promise
  632. console.log(`自定义账号上传第 ${i + 1} 批上传完成`, batch);
  633. }
  634. } else {
  635. // 长度不超过 10,直接上传整个数组
  636. await this.uploadBatchAccount (data2);
  637. }
  638. }
  639. this.$message({
  640. message: this.lang.ssAddOk,
  641. type: "success",
  642. });
  643. // excel与手动上传,上传完毕,打开弹框
  644. this.deltypy = index;
  645. this.popBoxdia= true;
  646. // this.addStuVisible = false;
  647. console.log('this.selectedStuData',this.selectedStuData);
  648. // this.selectedStuData = [];
  649. this.$emit("getCascaderData");
  650. this.addOp3('1', "", { type: "student_add" }, "success")
  651. } catch (err) {
  652. console.error(err);
  653. // 业务错误已在 uploadBatch / uploadBatchAccount 中提示
  654. if (!err || !err.business) {
  655. this.$message.error(this.lang.Additionfailed);
  656. }
  657. } finally {
  658. this.uploadfileLoading = false;
  659. }
  660. },
  661. async uploadBatch(box){
  662. return new Promise((resolve, reject) => {
  663. // this.impbox = box;
  664. let z = 2;
  665. let newArr = JSON.stringify(box);
  666. let params = [
  667. {
  668. arr: newArr,
  669. userpassword: "Coco1234",
  670. oid: this.oid,
  671. },
  672. ];
  673. console.log(params, "batchRegistrationMoreCopyNewl");
  674. // batchRegistrationMoreCopy
  675. this.ajax
  676. .post(this.$store.state.api + "batchRegistrationMoreCopyNewl", params)
  677. .then((res) => {
  678. console.log(res, "res");
  679. if (res.data.type == 1) {
  680. this.$message.error(this.lang.stunumberregistered);
  681. z = 1;
  682. }
  683. if (res.data.type == 2) {
  684. this.$message.error(this.lang.stuaccregistered);
  685. z = 1;
  686. }
  687. if (res.data.type == 3) {
  688. this.$message.error(this.lang.studuplicateIDs);
  689. z = 1;
  690. }
  691. if (z == 2) {
  692. console.log("添加成功");
  693. resolve(res);
  694. } else {
  695. reject({ business: true, res });
  696. }
  697. })
  698. .catch((err) => {
  699. console.error(err);
  700. this.addOp3('1', "", { type: "student_add" }, err)
  701. reject(err);
  702. });
  703. });
  704. },
  705. async uploadBatchAccount(box){
  706. return new Promise((resolve, reject) => {
  707. let z = 2;
  708. let newArr = JSON.stringify(box);
  709. let params = [
  710. {
  711. arr: newArr,
  712. userpassword: "Coco1234",
  713. oid: this.oid,
  714. },
  715. ];
  716. console.log(params, "batchRegistrationMoreAcc");
  717. // batchRegistrationMoreCopy
  718. this.ajax
  719. .post(this.$store.state.api + "batchRegistrationMoreAcc", params)
  720. .then((res) => {
  721. console.log(res, "res");
  722. if (res.data.type == 1) {
  723. this.$message.error(this.lang.stunumberregistered);
  724. z = 1;
  725. }
  726. if (res.data.type == 2) {
  727. this.$message.error(this.lang.stuaccregistered);
  728. z = 1;
  729. }
  730. if (res.data.type == 3) {
  731. this.$message.error(this.lang.studuplicateIDs);
  732. z = 1;
  733. }
  734. if (z == 2) {
  735. console.log("添加成功");
  736. resolve(res);
  737. } else {
  738. reject({ business: true, res });
  739. }
  740. })
  741. .catch((err) => {
  742. console.error(err);
  743. this.addOp3('1', "", { type: "student_add" }, err)
  744. reject(err);
  745. });
  746. });
  747. },
  748. confirmDelStu(){
  749. // this.addStuVisible = false;
  750. if (this.deltypy == 0 || this.deltypy == 2) { //上传完毕,关闭弹窗
  751. this.impbox = []
  752. this.selectedStuData = [];
  753. // 关闭弹窗
  754. if(this.deltypy == 2){ //excel上传,关闭弹窗
  755. this.stuexcel = [];
  756. this.addStuVisible = false;
  757. }
  758. }else if (this.deltypy == 1) { //excel上传,提示是否继续上传
  759. if (this.uploadfileLoading) {
  760. this.$message.warning(this.lang.ssUploading);
  761. return;
  762. }
  763. this.accUpdate(this.stuexcel,2);
  764. }
  765. this.popBoxdia= false;
  766. },
  767. closePop(){
  768. this.popBoxdia= false;
  769. if (this.deltypy == 1) {
  770. // excel上传,清空数据
  771. this.stuexcel = []
  772. }
  773. },
  774. // 修改账号
  775. updateAccount(arr) {
  776. let params = {
  777. oid: this.oid,
  778. };
  779. this.ajax
  780. .get(this.$store.state.api + "updateAccount", params)
  781. .then((res) => {
  782. console.log(res, "res");
  783. })
  784. .catch((err) => {
  785. console.error(err);
  786. });
  787. },
  788. handleClose(index) {
  789. this.searchStuData.splice(index, 1);
  790. },
  791. changeStuListType(value) {
  792. this.addStuType = value;
  793. this.clearData();
  794. },
  795. searchStu() {
  796. this.searchStuData.push(
  797. ...this.searchStuName
  798. .split(",")
  799. .map((item) => item.trim())
  800. .filter((item) => item)
  801. );
  802. this.searchStuName = "";
  803. },
  804. selectNoneStu() {
  805. this.popoverVisible = false;
  806. this.searchStuData = [];
  807. this.searchStuName = "";
  808. },
  809. selectStu() {
  810. this.popoverVisible = false;
  811. this.selectedStuData.push(...this.searchStuData);
  812. this.searchStuData = [];
  813. this.searchStuName = "";
  814. },
  815. handleSelectedStuClose(index) {
  816. this.selectedStuData.splice(index, 1);
  817. },
  818. getSchoolName() {
  819. let params = {
  820. oid: this.oid,
  821. };
  822. this.ajax
  823. .get(this.$store.state.api + "selectSchoolName2", params)
  824. .then((res) => {
  825. // this.schoolName = res.data[0][0].name;
  826. console.log(res.data[0][0].name, "res.data[0][0].name");
  827. const cleanedSchoolName = res.data[0][0].name.replace(
  828. /[,。;:!“”‘’()()]/g,
  829. ""
  830. ); // 去掉标点符号
  831. // console.log(pinyin);
  832. // console.log(pinyin.getFullChars(cleanedSchoolName));
  833. // console.log(pinyin.getCamelChars(cleanedSchoolName));
  834. this.schoolChar = pinyin
  835. .getCamelChars(cleanedSchoolName)
  836. .toLowerCase();
  837. })
  838. .catch((err) => {
  839. console.error(err);
  840. });
  841. },
  842. getUser() {
  843. let params = {
  844. userid: this.userid,
  845. };
  846. this.userSuffixloading = true;
  847. this.ajax
  848. .get(this.$store.state.api + "selectuserinfoyym", params)
  849. .then((res) => {
  850. this.userSuffix = res.data[0][0].accountNumber.split("@")[1];
  851. this.userSuffixloading = false;
  852. })
  853. .catch((err) => {
  854. console.error(err);
  855. this.userSuffixloading = false;
  856. });
  857. },
  858. },
  859. };
  860. </script>
  861. <style>
  862. .myCascader
  863. .el-cascader-panel
  864. .el-cascader-menu:first-child
  865. .el-scrollbar__wrap
  866. ul
  867. li
  868. label,
  869. .myCascader
  870. .el-cascader-panel
  871. .el-cascader-menu:first-child
  872. .el-scrollbar__wrap
  873. ul
  874. li
  875. .el-checkbox {
  876. display: none !important;
  877. }
  878. .seaStutxt {
  879. width: 360px !important;
  880. min-width: 60px !important;
  881. padding: 16px !important;
  882. }
  883. .seaStuBtn{
  884. margin-top: 10px;
  885. display: flex;
  886. justify-content: flex-end;
  887. }
  888. /* .seaStutxt .action_box > div {
  889. padding: 8px 15px;
  890. cursor: pointer;
  891. font-size: 14px;
  892. text-align: center;
  893. }
  894. .seaStutxt .action_box > div:hover {
  895. background: #e8f3ff;
  896. color: #0052d9;
  897. } */
  898. </style>
  899. <style scoped>
  900. .bar_box {
  901. display: flex;
  902. align-items: center;
  903. margin-bottom: 15px;
  904. gap: 20px;
  905. border-bottom: 0.5px solid #e7e7e7;
  906. }
  907. .bar_box div {
  908. cursor: pointer;
  909. padding-bottom: 5px;
  910. box-sizing: border-box;
  911. }
  912. .active_bar {
  913. border-bottom: 2px solid #0052d9 !important;
  914. }
  915. .addcla_box {
  916. display: flex;
  917. flex-direction: column;
  918. gap: 25px;
  919. margin-top: 30px;
  920. min-height: 300px;
  921. }
  922. .addcla_box_item {
  923. min-height: 35px;
  924. display: flex;
  925. align-items: center;
  926. gap: 10px;
  927. }
  928. .addcla_box_item >>> .el-cascader {
  929. width: 100%;
  930. }
  931. .addcla_box_item >>> .el-input__inner {
  932. width: 100%;
  933. }
  934. .addcla_box_item >>> .el-input__icon {
  935. width: 100%;
  936. }
  937. .addcla_box_item > .addcla_box_item_span {
  938. width: 80px;
  939. flex-shrink: 0;
  940. text-align: right;
  941. }
  942. .search_stu_box {
  943. width: 670px;
  944. position: absolute;
  945. display: flex;
  946. flex-direction: column;
  947. top: 100%;
  948. left: 90px;
  949. z-index: 1000;
  950. min-height: 110px;
  951. background: #fff;
  952. border: 1px solid #e8f3ff;
  953. box-sizing: border-box;
  954. border-radius: 2px;
  955. box-shadow: 0px 5px 5px -3px rgba(0,0,0,0.1), 0px 8px 10px 1px rgba(0,0,0,0.06), 0px 3px 14px 2px rgba(0,0,0,0.05);
  956. }
  957. .search_stu_box_content {
  958. display: flex;
  959. gap: 10px;
  960. flex: 1;
  961. padding: 10px;
  962. flex-wrap: wrap;
  963. box-sizing: border-box;
  964. }
  965. .selected_stu_box_item {
  966. background: #e8f3ff;
  967. padding: 0px 10px;
  968. height: 30px;
  969. line-height: 30px;
  970. border-radius: 5px;
  971. box-sizing: border-box;
  972. }
  973. .search_stu_box_footer {
  974. display: flex;
  975. height: 40px;
  976. padding: 0 10px;
  977. box-sizing: border-box;
  978. justify-content: space-between;
  979. align-items: center;
  980. box-sizing: border-box;
  981. border-top: 1px #e7e7e7 solid;
  982. }
  983. .selected_stu_box {
  984. display: flex;
  985. flex-wrap: wrap;
  986. gap: 10px;
  987. }
  988. .upload-demo {
  989. width: 100%;
  990. height: 100%;
  991. display: flex;
  992. justify-content: center;
  993. align-items: center;
  994. border-radius: 6px;
  995. cursor: pointer;
  996. box-sizing: border-box;
  997. overflow: hidden;
  998. border-radius: 25px;
  999. border: 0.5px dashed #e7e7e7;
  1000. }
  1001. .upload-demo:hover {
  1002. box-sizing: border-box;
  1003. border: 0.5px dashed #0052d9;
  1004. }
  1005. .upload-demo >>> .el-upload {
  1006. width: 100%;
  1007. height: 100%;
  1008. }
  1009. .upload-demo >>> .el-upload-dragger {
  1010. width: 100%;
  1011. height: 100%;
  1012. min-height: 200px;
  1013. border: none;
  1014. background: #f2f4f5;
  1015. display: flex;
  1016. justify-content: center;
  1017. align-items: center;
  1018. flex-direction: column;
  1019. gap: 10px;
  1020. }
  1021. .upload-demo-tip {
  1022. font-size: 12px;
  1023. color: #999;
  1024. }
  1025. .download-template {
  1026. color: #0052d9;
  1027. cursor: pointer;
  1028. border-bottom: 1px solid #0052d9;
  1029. }
  1030. .msgCon{
  1031. display: flex;
  1032. gap: 10px;
  1033. align-items: flex-start;
  1034. box-sizing: border-box;
  1035. }
  1036. .msgContxt{
  1037. display: flex;
  1038. flex-direction: column;
  1039. gap: 10px;
  1040. font-size: 16px;
  1041. color: #000000;
  1042. }
  1043. .tagL{
  1044. height: 30px;
  1045. line-height: 30px;
  1046. border-radius: 3px;
  1047. box-sizing: border-box;
  1048. background: #E7F3FF;
  1049. border: 1px #DDE4E5 solid;
  1050. position: relative;
  1051. }
  1052. .tagitem{
  1053. height: 100%;
  1054. padding: 0 25px;
  1055. box-sizing: border-box;
  1056. display: flex;
  1057. align-items: center;
  1058. position: relative;
  1059. }
  1060. .tagtit{
  1061. position: absolute;
  1062. top: -116px;
  1063. right: 0;
  1064. background: #999;
  1065. display: none;
  1066. width: 304px;
  1067. height: 116px;
  1068. background: #FFFFFF;
  1069. border-radius: 8px 8px 8px 8px;
  1070. padding: 10px;
  1071. float: left;
  1072. box-sizing: border-box;
  1073. box-shadow: 0px 8px 10px -5px rgba(0,0,0,0.08), 0px 16px 24px 2px rgba(0,0,0,0.04), 0px 6px 30px 5px rgba(0,0,0,0.05);
  1074. }
  1075. .poptag{
  1076. display: flex !important;
  1077. gap: 10px;
  1078. align-items: flex-start;
  1079. }
  1080. .tagtit img{
  1081. width: 20px;
  1082. margin-top: 5px;
  1083. }
  1084. /* tagtit 与 tagitem 是兄弟关系,需通过父元素 tagL 来联动 */
  1085. .tagL:hover .tagtit{
  1086. display: block !important;
  1087. }
  1088. .tagitem2{
  1089. background: #F7D9CF;
  1090. border: none;
  1091. color: #FE6331;
  1092. }
  1093. .pop-upBox >>> .el-dialog{
  1094. border-radius: 8px !important;
  1095. margin-top: 30vh !important;
  1096. }
  1097. .pop-upBox >>> .el-dialog__body{
  1098. padding: 12px 23px;
  1099. }
  1100. /* .addstudia >>> .el-dialog__body{
  1101. padding: 10px 20px;
  1102. } */
  1103. .msgCon{
  1104. display: flex;
  1105. gap: 10px;
  1106. align-items: flex-start;
  1107. box-sizing: border-box;
  1108. }
  1109. .msgContxt{
  1110. display: flex;
  1111. flex-direction: column;
  1112. gap: 10px;
  1113. font-size: 16px;
  1114. color: #000000;
  1115. }
  1116. .kbtn{
  1117. text-align: center;
  1118. padding: 8px 14px;
  1119. cursor: pointer;
  1120. border-radius: 3px;
  1121. box-sizing: border-box;
  1122. font-size: 14px;
  1123. }
  1124. .dialog-footer {
  1125. display: flex;
  1126. justify-content: flex-end;
  1127. gap: 10px;
  1128. }
  1129. .closeImg{
  1130. font-size: 16px;
  1131. cursor: pointer;
  1132. display: none;
  1133. position: absolute;
  1134. right: 3px;
  1135. top: 50%;
  1136. transform: translateY(-50%);
  1137. /* background: #fff; */
  1138. /* border-radius: 50%; */
  1139. /* padding: 2px; */
  1140. /* box-sizing: border-box; */
  1141. }
  1142. .tagitem:hover .closeImg{
  1143. display: block;
  1144. }
  1145. </style>