addstu.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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" 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">
  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.userSuffix == "") {
  408. this.$message.error(this.lang.ssGetSuffixReUp);
  409. this.getUser();
  410. return;
  411. }
  412. let _this = this;
  413. // 通过DOM取文件数据
  414. var rABS = false; //是否将文件读取为二进制字符串
  415. var f = file.file;
  416. var reader = new FileReader();
  417. //if (!FileReader.prototype.readAsBinaryString) {
  418. FileReader.prototype.readAsBinaryString = function (f) {
  419. var binary = "";
  420. var rABS = false; //是否将文件读取为二进制字符串
  421. var wb; //读取完成的数据
  422. var outdata;
  423. var reader = new FileReader();
  424. reader.onload = async function (e) {
  425. var bytes = new Uint8Array(reader.result);
  426. var length = bytes.byteLength;
  427. for (var i = 0; i < length; i++) {
  428. binary += String.fromCharCode(bytes[i]);
  429. }
  430. var XLSX = require("xlsx");
  431. if (rABS) {
  432. wb = XLSX.read(btoa(fixdata(binary)), {
  433. //手动转化
  434. type: "base64",
  435. });
  436. } else {
  437. wb = XLSX.read(binary, {
  438. type: "binary",
  439. });
  440. }
  441. outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); //outdata就是你想要的东西
  442. let da = [...outdata];
  443. console.log(da, "da");
  444. let arr = [];
  445. da.map((v) => {
  446. let obj = {};
  447. if (
  448. v[_this.lang.StudentName] !== undefined &&
  449. v[_this.lang.StudentName] !== ""
  450. ) {
  451. obj.name = v[_this.lang.StudentName];
  452. const accountVal = String(v[_this.lang.ssStuAccHd] || '').trim();
  453. if (
  454. _this.org != "" &&
  455. _this.org != "null" &&
  456. _this.org != undefined &&
  457. _this.org &&
  458. _this.schoolChar
  459. ) {
  460. if (accountVal && /^[a-zA-Z0-9]+$/.test(accountVal)) {
  461. obj.account = accountVal + '@' + _this.schoolChar + '.' + _this.userSuffix;
  462. } else {
  463. obj.account = '';
  464. }
  465. obj.mail =
  466. uuidv4() + "@" + _this.schoolChar + "." + _this.userSuffix;
  467. } else {
  468. if (accountVal && /^[a-zA-Z0-9]+$/.test(accountVal)) {
  469. obj.account = accountVal + '@' + _this.userSuffix;
  470. } else {
  471. obj.account = '';
  472. }
  473. obj.mail = uuidv4() + "@" + _this.userSuffix;
  474. }
  475. obj.class = _this.boxType == 2 ? v[_this.lang.Class] : _this.classInfo.id;
  476. arr.push(obj);
  477. }else{
  478. _this.$message.error(_this.lang.ssCheckStuNameCol);
  479. return;
  480. }
  481. });
  482. console.log(arr);
  483. if (!arr.length) {
  484. _this.$message.error(
  485. _this.lang.ssParseStuFail
  486. );
  487. return;
  488. }
  489. if (_this.boxType == 2) {
  490. let stuClassInfo = await _this.getClassInfo();
  491. console.log(stuClassInfo, "stuClassInfo");
  492. arr.forEach((e) => {
  493. let classInfo = stuClassInfo.find(item => item.name == e.class);
  494. if (classInfo) {
  495. e.class = classInfo.id;
  496. } else {
  497. e.class = '';
  498. }
  499. });
  500. }
  501. console.log(arr, "arr");
  502. if (_this.boxType == 2 && arr.filter(e => e.class).length !== arr.length) {
  503. _this.$message.error(_this.lang.ssCheckClassCol);
  504. return;
  505. }
  506. _this.deltypy = 1;
  507. _this.popBoxdia= true;
  508. _this.stuexcel = arr;
  509. };
  510. reader.readAsArrayBuffer(f);
  511. };
  512. if (rABS) {
  513. reader.readAsArrayBuffer(f);
  514. } else {
  515. reader.readAsBinaryString(f);
  516. }
  517. },
  518. async getClassInfo() {
  519. return new Promise((resolve, reject) => {
  520. let params = {
  521. oid: this.oid,
  522. };
  523. this.ajax
  524. .get(this.$store.state.api + "selectGradeNew", params)
  525. .then((res) => {
  526. let box1 = JSON.parse(JSON.stringify(res.data[0]));
  527. let box2 = JSON.parse(JSON.stringify(res.data[1]));
  528. // box1.push({id:0,name:this.lang.ssInterestClass});
  529. const gradeIds = box1.filter(e => e.id !== 0).map(e => e.id);
  530. let box3 = [];
  531. box2.forEach((e) => {
  532. if (gradeIds.includes(e.pid)) {
  533. e.name = box1.find(item => item.id == e.pid).name + e.name;
  534. box3.push(e);
  535. }
  536. });
  537. resolve(box3);
  538. })
  539. .catch((err) => {
  540. console.error(err);
  541. reject(err);
  542. });
  543. });
  544. },
  545. // 手动输入添加学生
  546. addStu() {
  547. if (this.uploadfileLoading) {
  548. this.$message.warning(this.lang.ssUploading);
  549. return;
  550. }
  551. this.selectedStuData = this.selectedStuData.filter((item) => item != "");
  552. if (this.selectedStuData.length == 0) {
  553. this.$message.error(this.lang.ssEnterStu);
  554. return;
  555. }
  556. if (this.selectedStuData.length > 70) {
  557. this.$message.error(this.lang.ssAddStuMax70);
  558. return;
  559. }
  560. if ((this.boxType == 2 && this.cascaderDataPath.length == 0) || this.classInfo.name == "") {
  561. this.$message.error(this.lang.ssSelectBelCla);
  562. return;
  563. }
  564. if (this.userSuffix == "") {
  565. this.$message.error(this.lang.ssGetSuffixReAdd);
  566. this.getUser();
  567. return;
  568. }
  569. let mail = "";
  570. if (
  571. this.org != "" &&
  572. this.org != "null" &&
  573. this.org != undefined &&
  574. this.org &&
  575. this.schoolChar
  576. ) {
  577. mail = "@" + this.schoolChar + "." + this.userSuffix;
  578. } else {
  579. mail = "@" + this.userSuffix;
  580. }
  581. let classInfo = this.classInfo;
  582. if (this.boxType == 2) {
  583. classInfo = this.cascaderData.flatMap((item) => item.children).filter((item) => this.cascaderDataPath[1]==item.id)[0];
  584. }
  585. let box = this.selectedStuData.map((item) => {
  586. return {
  587. name: item,
  588. mail: uuidv4() + mail,
  589. class: classInfo.id,
  590. };
  591. });
  592. this.accUpdate(box);
  593. },
  594. async accUpdate(box) {
  595. console.log(box, "box");
  596. this.uploadfileLoading = true;
  597. this.impbox = box;
  598. let data1 = box.filter(e => !e.account);
  599. let data2 = box.filter(e => e.account);
  600. data2.forEach((e) => {
  601. e.mail = e.account;
  602. });
  603. try {
  604. const batchSize = 50;
  605. if (data1.length > 0) {
  606. if (data1.length > batchSize) {
  607. // 计算总批次数
  608. const totalBatches = Math.ceil(data1.length / batchSize);
  609. for (let i = 0; i < totalBatches; i++) {
  610. const batch = data1.slice(i * batchSize, (i + 1) * batchSize);
  611. await this.uploadBatch(batch); // 假设 uploadBatch 返回 Promise
  612. console.log(`普通上传第 ${i + 1} 批上传完成`, batch);
  613. }
  614. } else {
  615. // 长度不超过 10,直接上传整个数组
  616. await this.uploadBatch(data1);
  617. }
  618. }
  619. if (data2.length > 0) {
  620. if (data2.length > batchSize) {
  621. // 计算总批次数
  622. const totalBatches = Math.ceil(data2.length / batchSize);
  623. for (let i = 0; i < totalBatches; i++) {
  624. const batch = data2.slice(i * batchSize, (i + 1) * batchSize);
  625. await this.uploadBatchAccount (batch); // 假设 uploadBatch 返回 Promise
  626. console.log(`自定义账号上传第 ${i + 1} 批上传完成`, batch);
  627. }
  628. } else {
  629. // 长度不超过 10,直接上传整个数组
  630. await this.uploadBatchAccount (data2);
  631. }
  632. }
  633. this.$message({
  634. message: this.lang.ssAddOk,
  635. type: "success",
  636. });
  637. this.deltypy = 0;
  638. this.popBoxdia= true;
  639. // this.addStuVisible = false;
  640. console.log('this.selectedStuData',this.selectedStuData);
  641. // this.selectedStuData = [];
  642. this.$emit("getCascaderData");
  643. this.addOp3('1', "", { type: "student_add" }, "success")
  644. } finally {
  645. this.uploadfileLoading = false;
  646. }
  647. },
  648. async uploadBatch(box){
  649. return new Promise((resolve, reject) => {
  650. // this.impbox = box;
  651. let z = 2;
  652. let newArr = JSON.stringify(box);
  653. let params = [
  654. {
  655. arr: newArr,
  656. userpassword: "Coco1234",
  657. oid: this.oid,
  658. },
  659. ];
  660. console.log(params, "batchRegistrationMoreCopyNewl");
  661. // batchRegistrationMoreCopy
  662. this.ajax
  663. .post(this.$store.state.api + "batchRegistrationMoreCopyNewl", params)
  664. .then((res) => {
  665. console.log(res, "res");
  666. if (res.data.type == 1) {
  667. this.$message.error(this.lang.stunumberregistered);
  668. z = 1;
  669. }
  670. if (res.data.type == 2) {
  671. this.$message.error(this.lang.stuaccregistered);
  672. z = 1;
  673. }
  674. if (res.data.type == 3) {
  675. this.$message.error(this.lang.studuplicateIDs);
  676. z = 1;
  677. }
  678. if (z == 2) {
  679. console.log("添加成功");
  680. }
  681. resolve(res);
  682. })
  683. .catch((err) => {
  684. console.error(err);
  685. this.addOp3('1', "", { type: "student_add" }, err)
  686. reject(err);
  687. });
  688. });
  689. },
  690. async uploadBatchAccount(box){
  691. return new Promise((resolve, reject) => {
  692. let z = 2;
  693. let newArr = JSON.stringify(box);
  694. let params = [
  695. {
  696. arr: newArr,
  697. userpassword: "Coco1234",
  698. oid: this.oid,
  699. },
  700. ];
  701. console.log(params, "batchRegistrationMoreAcc");
  702. // batchRegistrationMoreCopy
  703. this.ajax
  704. .post(this.$store.state.api + "batchRegistrationMoreAcc", params)
  705. .then((res) => {
  706. console.log(res, "res");
  707. if (res.data.type == 1) {
  708. this.$message.error(this.lang.stunumberregistered);
  709. z = 1;
  710. }
  711. if (res.data.type == 2) {
  712. this.$message.error(this.lang.stuaccregistered);
  713. z = 1;
  714. }
  715. if (res.data.type == 3) {
  716. this.$message.error(this.lang.studuplicateIDs);
  717. z = 1;
  718. }
  719. if (z == 2) {
  720. console.log("添加成功");
  721. }
  722. resolve(res);
  723. })
  724. .catch((err) => {
  725. console.error(err);
  726. this.addOp3('1', "", { type: "student_add" }, err)
  727. reject(err);
  728. });
  729. });
  730. },
  731. confirmDelStu(){
  732. // this.addStuVisible = false;
  733. if (this.deltypy == 0) {
  734. this.impbox = []
  735. this.selectedStuData = [];
  736. }else if (this.deltypy == 1) {
  737. this.uploadfileLoading = true;
  738. this.accUpdate(this.stuexcel);
  739. }
  740. this.popBoxdia= false;
  741. },
  742. closePop(){
  743. this.popBoxdia= false;
  744. if (this.deltypy == 1) {
  745. this.stuexcel = []
  746. }
  747. },
  748. // 修改账号
  749. updateAccount(arr) {
  750. let params = {
  751. oid: this.oid,
  752. };
  753. this.ajax
  754. .get(this.$store.state.api + "updateAccount", params)
  755. .then((res) => {
  756. console.log(res, "res");
  757. })
  758. .catch((err) => {
  759. console.error(err);
  760. });
  761. },
  762. handleClose(index) {
  763. this.searchStuData.splice(index, 1);
  764. },
  765. changeStuListType(value) {
  766. this.addStuType = value;
  767. this.clearData();
  768. },
  769. searchStu() {
  770. this.searchStuData.push(
  771. ...this.searchStuName
  772. .split(",")
  773. .map((item) => item.trim())
  774. .filter((item) => item)
  775. );
  776. this.searchStuName = "";
  777. },
  778. selectNoneStu() {
  779. this.popoverVisible = false;
  780. this.searchStuData = [];
  781. this.searchStuName = "";
  782. },
  783. selectStu() {
  784. this.popoverVisible = false;
  785. this.selectedStuData.push(...this.searchStuData);
  786. this.searchStuData = [];
  787. this.searchStuName = "";
  788. },
  789. handleSelectedStuClose(index) {
  790. this.selectedStuData.splice(index, 1);
  791. },
  792. getSchoolName() {
  793. let params = {
  794. oid: this.oid,
  795. };
  796. this.ajax
  797. .get(this.$store.state.api + "selectSchoolName2", params)
  798. .then((res) => {
  799. // this.schoolName = res.data[0][0].name;
  800. console.log(res.data[0][0].name, "res.data[0][0].name");
  801. const cleanedSchoolName = res.data[0][0].name.replace(
  802. /[,。;:!“”‘’()()]/g,
  803. ""
  804. ); // 去掉标点符号
  805. // console.log(pinyin);
  806. // console.log(pinyin.getFullChars(cleanedSchoolName));
  807. // console.log(pinyin.getCamelChars(cleanedSchoolName));
  808. this.schoolChar = pinyin
  809. .getCamelChars(cleanedSchoolName)
  810. .toLowerCase();
  811. })
  812. .catch((err) => {
  813. console.error(err);
  814. });
  815. },
  816. getUser() {
  817. let params = {
  818. userid: this.userid,
  819. };
  820. this.userSuffixloading = true;
  821. this.ajax
  822. .get(this.$store.state.api + "selectuserinfoyym", params)
  823. .then((res) => {
  824. this.userSuffix = res.data[0][0].accountNumber.split("@")[1];
  825. this.userSuffixloading = false;
  826. })
  827. .catch((err) => {
  828. console.error(err);
  829. this.userSuffixloading = false;
  830. });
  831. },
  832. },
  833. };
  834. </script>
  835. <style>
  836. .myCascader
  837. .el-cascader-panel
  838. .el-cascader-menu:first-child
  839. .el-scrollbar__wrap
  840. ul
  841. li
  842. label,
  843. .myCascader
  844. .el-cascader-panel
  845. .el-cascader-menu:first-child
  846. .el-scrollbar__wrap
  847. ul
  848. li
  849. .el-checkbox {
  850. display: none !important;
  851. }
  852. .seaStutxt {
  853. width: 360px !important;
  854. min-width: 60px !important;
  855. padding: 16px !important;
  856. }
  857. .seaStuBtn{
  858. margin-top: 10px;
  859. display: flex;
  860. justify-content: flex-end;
  861. }
  862. /* .seaStutxt .action_box > div {
  863. padding: 8px 15px;
  864. cursor: pointer;
  865. font-size: 14px;
  866. text-align: center;
  867. }
  868. .seaStutxt .action_box > div:hover {
  869. background: #e8f3ff;
  870. color: #0052d9;
  871. } */
  872. </style>
  873. <style scoped>
  874. .bar_box {
  875. display: flex;
  876. align-items: center;
  877. margin-bottom: 15px;
  878. gap: 20px;
  879. border-bottom: 0.5px solid #e7e7e7;
  880. }
  881. .bar_box div {
  882. cursor: pointer;
  883. padding-bottom: 5px;
  884. box-sizing: border-box;
  885. }
  886. .active_bar {
  887. border-bottom: 2px solid #0052d9 !important;
  888. }
  889. .addcla_box {
  890. display: flex;
  891. flex-direction: column;
  892. gap: 25px;
  893. margin-top: 30px;
  894. min-height: 300px;
  895. }
  896. .addcla_box_item {
  897. min-height: 35px;
  898. display: flex;
  899. align-items: center;
  900. gap: 10px;
  901. }
  902. .addcla_box_item >>> .el-cascader {
  903. width: 100%;
  904. }
  905. .addcla_box_item >>> .el-input__inner {
  906. width: 100%;
  907. }
  908. .addcla_box_item >>> .el-input__icon {
  909. width: 100%;
  910. }
  911. .addcla_box_item > .addcla_box_item_span {
  912. width: 80px;
  913. flex-shrink: 0;
  914. text-align: right;
  915. }
  916. .search_stu_box {
  917. width: 670px;
  918. position: absolute;
  919. display: flex;
  920. flex-direction: column;
  921. top: 100%;
  922. left: 90px;
  923. z-index: 1000;
  924. min-height: 110px;
  925. background: #fff;
  926. border: 1px solid #e8f3ff;
  927. box-sizing: border-box;
  928. border-radius: 2px;
  929. 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);
  930. }
  931. .search_stu_box_content {
  932. display: flex;
  933. gap: 10px;
  934. flex: 1;
  935. padding: 10px;
  936. flex-wrap: wrap;
  937. box-sizing: border-box;
  938. }
  939. .selected_stu_box_item {
  940. background: #e8f3ff;
  941. padding: 0px 10px;
  942. height: 30px;
  943. line-height: 30px;
  944. border-radius: 5px;
  945. box-sizing: border-box;
  946. }
  947. .search_stu_box_footer {
  948. display: flex;
  949. height: 40px;
  950. padding: 0 10px;
  951. box-sizing: border-box;
  952. justify-content: space-between;
  953. align-items: center;
  954. box-sizing: border-box;
  955. border-top: 1px #e7e7e7 solid;
  956. }
  957. .selected_stu_box {
  958. display: flex;
  959. flex-wrap: wrap;
  960. gap: 10px;
  961. }
  962. .upload-demo {
  963. width: 100%;
  964. height: 100%;
  965. display: flex;
  966. justify-content: center;
  967. align-items: center;
  968. border-radius: 6px;
  969. cursor: pointer;
  970. box-sizing: border-box;
  971. overflow: hidden;
  972. border-radius: 25px;
  973. border: 0.5px dashed #e7e7e7;
  974. }
  975. .upload-demo:hover {
  976. box-sizing: border-box;
  977. border: 0.5px dashed #0052d9;
  978. }
  979. .upload-demo >>> .el-upload {
  980. width: 100%;
  981. height: 100%;
  982. }
  983. .upload-demo >>> .el-upload-dragger {
  984. width: 100%;
  985. height: 100%;
  986. min-height: 200px;
  987. border: none;
  988. background: #f2f4f5;
  989. display: flex;
  990. justify-content: center;
  991. align-items: center;
  992. flex-direction: column;
  993. gap: 10px;
  994. }
  995. .upload-demo-tip {
  996. font-size: 12px;
  997. color: #999;
  998. }
  999. .download-template {
  1000. color: #0052d9;
  1001. cursor: pointer;
  1002. border-bottom: 1px solid #0052d9;
  1003. }
  1004. .msgCon{
  1005. display: flex;
  1006. gap: 10px;
  1007. align-items: flex-start;
  1008. box-sizing: border-box;
  1009. }
  1010. .msgContxt{
  1011. display: flex;
  1012. flex-direction: column;
  1013. gap: 10px;
  1014. font-size: 16px;
  1015. color: #000000;
  1016. }
  1017. .tagL{
  1018. height: 30px;
  1019. line-height: 30px;
  1020. border-radius: 3px;
  1021. box-sizing: border-box;
  1022. background: #E7F3FF;
  1023. border: 1px #DDE4E5 solid;
  1024. position: relative;
  1025. }
  1026. .tagitem{
  1027. height: 100%;
  1028. padding: 0 25px;
  1029. box-sizing: border-box;
  1030. display: flex;
  1031. align-items: center;
  1032. position: relative;
  1033. }
  1034. .tagtit{
  1035. position: absolute;
  1036. top: -116px;
  1037. right: 0;
  1038. background: #999;
  1039. display: none;
  1040. width: 304px;
  1041. height: 116px;
  1042. background: #FFFFFF;
  1043. border-radius: 8px 8px 8px 8px;
  1044. padding: 10px;
  1045. float: left;
  1046. box-sizing: border-box;
  1047. 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);
  1048. }
  1049. .poptag{
  1050. display: flex !important;
  1051. gap: 10px;
  1052. align-items: flex-start;
  1053. }
  1054. .tagtit img{
  1055. width: 20px;
  1056. margin-top: 5px;
  1057. }
  1058. /* tagtit 与 tagitem 是兄弟关系,需通过父元素 tagL 来联动 */
  1059. .tagL:hover .tagtit{
  1060. display: block !important;
  1061. }
  1062. .tagitem2{
  1063. background: #F7D9CF;
  1064. border: none;
  1065. color: #FE6331;
  1066. }
  1067. .pop-upBox >>> .el-dialog{
  1068. border-radius: 8px !important;
  1069. margin-top: 30vh !important;
  1070. }
  1071. .pop-upBox >>> .el-dialog__body{
  1072. padding: 12px 23px;
  1073. }
  1074. /* .addstudia >>> .el-dialog__body{
  1075. padding: 10px 20px;
  1076. } */
  1077. .msgCon{
  1078. display: flex;
  1079. gap: 10px;
  1080. align-items: flex-start;
  1081. box-sizing: border-box;
  1082. }
  1083. .msgContxt{
  1084. display: flex;
  1085. flex-direction: column;
  1086. gap: 10px;
  1087. font-size: 16px;
  1088. color: #000000;
  1089. }
  1090. .kbtn{
  1091. text-align: center;
  1092. padding: 8px 14px;
  1093. cursor: pointer;
  1094. border-radius: 3px;
  1095. box-sizing: border-box;
  1096. font-size: 14px;
  1097. }
  1098. .dialog-footer {
  1099. display: flex;
  1100. justify-content: flex-end;
  1101. gap: 10px;
  1102. }
  1103. .closeImg{
  1104. font-size: 16px;
  1105. cursor: pointer;
  1106. display: none;
  1107. position: absolute;
  1108. right: 3px;
  1109. top: 50%;
  1110. transform: translateY(-50%);
  1111. /* background: #fff; */
  1112. /* border-radius: 50%; */
  1113. /* padding: 2px; */
  1114. /* box-sizing: border-box; */
  1115. }
  1116. .tagitem:hover .closeImg{
  1117. display: block;
  1118. }
  1119. </style>