TeacherRegister.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <template>
  2. <div>
  3. <!---lxh-修改密码-->
  4. <div class="dig_update">
  5. <el-dialog
  6. :visible.sync="dialogVisible"
  7. :close-on-click-modal="false"
  8. width="40%"
  9. style="border-radius: 40px"
  10. top="15vh"
  11. >
  12. <div slot="title">
  13. <el-form
  14. :model="ruleForm"
  15. :rules="rules"
  16. :inline="true"
  17. ref="ruleForm"
  18. label-width="150px"
  19. class="demo-ruleForm"
  20. >
  21. <p v-if="isView" class="dig_title">单独注册</p>
  22. <p v-if="!isView" class="dig_title">编辑</p>
  23. <div slot=""></div>
  24. <div slot="footer"></div>
  25. <!-- :show-all-levels="false" -->
  26. <el-form-item label="所属组织架构" prop="group">
  27. <el-cascader
  28. :disabled="!isView"
  29. placeholder="请选择组织架构"
  30. v-model="ruleForm.group"
  31. :options="groupData"
  32. clearable
  33. ></el-cascader>
  34. </el-form-item>
  35. <el-form-item label="编号" prop="studentNumber">
  36. <el-input v-model="ruleForm.studentNumber"></el-input>
  37. </el-form-item>
  38. <el-row>
  39. <el-col :span="12">
  40. <el-form-item label="姓名" prop="name">
  41. <el-input v-model="ruleForm.name" autocomplete="off"></el-input>
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="12">
  45. <el-form-item label="性别" prop="sex">
  46. <el-radio-group v-model="ruleForm.sex" style="margin-left: 20px">
  47. <el-radio label="1">男</el-radio>
  48. <el-radio label="0">女</el-radio>
  49. </el-radio-group>
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. <!-- <el-form-item v-if="isView" label="密码" prop="password">
  54. <el-input
  55. type="password"
  56. v-model="ruleForm.password"
  57. autocomplete="off"
  58. ></el-input>
  59. </el-form-item>
  60. <el-form-item v-if="isView" label="确认密码" prop="comPassword">
  61. <el-input
  62. type="password"
  63. v-model="ruleForm.comPassword"
  64. autocomplete="off"
  65. ></el-input>
  66. </el-form-item> -->
  67. <div class="dig_button">
  68. <el-button type="info" round @click="resetData()">重置</el-button>
  69. <!-- <el-button type="success" round @click="submitForm('ruleForm')"
  70. >提交</el-button
  71. > -->
  72. <el-button type="success" round @click="submitCom()">提交</el-button>
  73. </div>
  74. </el-form>
  75. </div>
  76. </el-dialog>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. // import { oSessionStorage } from "../../utils/utils";
  82. import { oSessionStorage } from "../utils/utils";
  83. import md5 from "md5";
  84. export default {
  85. data() {
  86. var validatePass = (rule, value, callback) => {
  87. if (value === "") {
  88. callback(new Error("请输入密码"));
  89. } else if (value.length < 6) {
  90. callback(new Error("密码至少6位"));
  91. } else {
  92. callback();
  93. }
  94. };
  95. var validateComPass = (rule, value, callback) => {
  96. if (value === "") {
  97. callback(new Error("请输入密码"));
  98. } else if (value.length < 6) {
  99. callback(new Error("密码至少6位"));
  100. } else if (value !== this.ruleForm.password) {
  101. callback(new Error("两次密码不一致"));
  102. // callback();
  103. } else {
  104. callback();
  105. }
  106. };
  107. var validatePhone = (rule, value, callback) => {
  108. let myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  109. if (value === "") {
  110. callback(new Error("请输入手机号"));
  111. } else if (!myreg.test(value)) {
  112. callback(new Error("请输入正确格式"));
  113. } else {
  114. callback();
  115. }
  116. };
  117. return {
  118. userInfo: "",
  119. //编辑返回的值
  120. userDetailData: {},
  121. //组织架构名字
  122. groupName: "",
  123. ppData: [],
  124. groupData: [],
  125. options: [
  126. {
  127. value: "1",
  128. label: "选项1",
  129. children: [
  130. {
  131. value: "11",
  132. label: "选项11",
  133. children: [{ value: "111", label: "选项111" }],
  134. },
  135. ],
  136. },
  137. ],
  138. disableFlag: false,
  139. phoneFlag: false,
  140. flag: 3,
  141. dialogVisible: false,
  142. //渠道列表
  143. channelList: [{ name: "渠道天成", id: "1" }],
  144. ruleForm: {
  145. //所属组织架构
  146. group: "",
  147. //学号
  148. studentNumber: "",
  149. //姓名
  150. name: "",
  151. //性别
  152. sex: "",
  153. //密码
  154. password: "",
  155. comPassword: "",
  156. },
  157. isView: true,
  158. rules: {
  159. group: [{ required: true, message: "请选择组织架构", trigger: "blur" }],
  160. studentNumber: [{ required: true, message: "请输入编号", trigger: "blur" }],
  161. name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
  162. sex: [{ required: true, message: "请选择性别", trigger: "blur" }],
  163. // password: [{ required: true, message: "请输密码", trigger: "blur" }],
  164. // password: [{ required: true, validator: validatePass, trigger: "blur" }],
  165. // comPassword: [{ required: true, validator: validateComPass, trigger: "blur" }],
  166. },
  167. };
  168. },
  169. mounted() {
  170. //获取渠道信息
  171. // this.ruleForm.type = "3";
  172. },
  173. methods: {
  174. resetData() {
  175. this.$refs["ruleForm"].clearValidate();
  176. //清空表单
  177. // this.ruleForm.group = "";
  178. this.ruleForm.name = "";
  179. this.ruleForm.studentNumber = "";
  180. // this.ruleForm.password = "";
  181. // this.ruleForm.comPassword = "";
  182. this.ruleForm.sex = "";
  183. },
  184. //获取组织架构方法--------------------开始-----------------------
  185. getChannel() {
  186. this.$http.get(
  187. `/org/findAllOrgByPOrgNo?orgNo=${this.userInfo.orgNo}`,
  188. {},
  189. (res) => {
  190. // this.$toast.success({message:'成功'});
  191. if (res && res.code == 200) {
  192. //将值赋值给list
  193. if (res.data.length > 0) {
  194. let resAdd = this.addPro(res.data);
  195. this.ppData = JSON.parse(JSON.stringify(resAdd));
  196. let forRes = this.arrToTree(resAdd);
  197. // console.log('格式化的结构')
  198. // console.log(forRes)
  199. let resultRes = this.deleteChildren(forRes);
  200. // this.groupData = resultRes[0].children;
  201. let list = resultRes[0].children;
  202. this.groupData = list.filter((item) => {
  203. return item.extend == -1;
  204. });
  205. } else {
  206. this.groupData = [];
  207. }
  208. // this.channelList = res.data;
  209. } else {
  210. this.$message.error(res.msg);
  211. }
  212. }
  213. );
  214. },
  215. //z增加
  216. addPro(val) {
  217. let data = JSON.parse(JSON.stringify(val));
  218. for (let i = 0; i < val.length; i++) {
  219. data[i].value = val[i].orgNo;
  220. data[i].label = val[i].orgName;
  221. }
  222. return data;
  223. },
  224. //非递归方式:将平铺数据转换为树形结构数据
  225. arrToTree(arr) {
  226. let data = arr.filter((item) => {
  227. item.children = arr.filter((e) => {
  228. return item.orgNo === e.parentOrgNo;
  229. });
  230. return this.userInfo.orgNo == item.orgNo;
  231. //return !item.parentOrgNo;
  232. });
  233. return data;
  234. },
  235. //去除转换树形结构数据后存在的空children
  236. deleteChildren(arr) {
  237. let childs = arr;
  238. for (let i = childs.length; i--; i > 0) {
  239. if (childs[i].children) {
  240. if (childs[i].children.length) {
  241. this.deleteChildren(childs[i].children);
  242. } else {
  243. delete childs[i].children;
  244. }
  245. }
  246. }
  247. return arr;
  248. },
  249. queryOrgName() {
  250. for (let i = 0; i < this.ppData.length; i++) {
  251. if (this.ruleForm.group[this.ruleForm.group.length - 1] == this.ppData[i].orgNo) {
  252. this.groupName = this.ppData[i].orgName;
  253. }
  254. }
  255. },
  256. //获取组织架构方法--------------------结束-----------------------
  257. timeChange(val) {
  258. if (val !== null) {
  259. //根据时间得到格式化的数据
  260. this.ruleForm.birthDate = this.formatterTime(val);
  261. }
  262. },
  263. formatterTime(val) {
  264. let date = new Date(val);
  265. let year = date.getFullYear();
  266. let month = date.getMonth() + 1;
  267. month = this.formatterMon(month);
  268. let day = date.getDate();
  269. day = this.formatterMon(day);
  270. return year + "-" + month + "-" + day;
  271. },
  272. formatterMon(val) {
  273. if (val < 10) {
  274. return "0" + val;
  275. } else {
  276. return val;
  277. }
  278. },
  279. open(val) {
  280. this.userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));
  281. this.cancle();
  282. this.getChannel();
  283. this.dialogVisible = true;
  284. this.isView = val;
  285. this.$nextTick(() => {
  286. this.$refs.ruleForm.clearValidate();
  287. });
  288. },
  289. edit(val) {
  290. this.userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));
  291. this.getChannel();
  292. this.dialogVisible = true;
  293. this.isView = false;
  294. this.queryUserDetail(val.id);
  295. //调用查询详情的接口
  296. },
  297. //调用查询详情的接口
  298. queryUserDetail(val) {
  299. let url = `/user/findUserById?id=${val}`;
  300. this.$http.get(url, {}, (res) => {
  301. if (res && res.code == 200) {
  302. //获取返回值
  303. //根据将数据存储
  304. this.userDetailData = res.data;
  305. let a = [];
  306. //当角色等于2时
  307. // if (this.userInfo.roleType == "2") {
  308. // //
  309. // a.push(res.data.orgNo);
  310. // }
  311. // //当角色等于1时
  312. // if (this.userInfo.roleType == "3") {
  313. // for (let i = 0; i < res.data.orgList.length; i++) {
  314. // if (i < 2) {
  315. // a.push(res.data.orgList[i].orgNo);
  316. // }
  317. // }
  318. // }
  319. // a.push(this.userInfo.orgNo);
  320. // a.push(res.data.orgNo);
  321. //判断用户登录类型
  322. // debugger;
  323. // for (let i = res.data.orgList.length; i > 0; i--) {
  324. // //
  325. // a.push(res.data.orgList[i - 1].orgNo);
  326. // }
  327. //回显学号
  328. if (this.userInfo.roleType == "3") {
  329. this.ruleForm.group3 = res.data.orgNo;
  330. } else if (this.userInfo.roleType == "4") {
  331. this.ruleForm.group = [res.data.orgNo];
  332. }
  333. this.ruleForm.studentNumber = res.data.userNo;
  334. //回显姓名
  335. this.ruleForm.name = res.data.userName;
  336. //回显性别
  337. this.ruleForm.sex = res.data.gender;
  338. //
  339. // this.ruleForm.group = a.reverse();
  340. } else {
  341. // this.$toast.fail(res.msg);
  342. this.$message.error(res.msg);
  343. }
  344. });
  345. },
  346. cancle() {
  347. this.$refs["ruleForm"].clearValidate();
  348. //清空表单
  349. this.ruleForm.group = "";
  350. this.ruleForm.name = "";
  351. this.ruleForm.studentNumber = "";
  352. this.ruleForm.password = "";
  353. this.ruleForm.comPassword = "";
  354. this.ruleForm.sex = "";
  355. this.dialogVisible = false;
  356. },
  357. disableFlagStatus() {
  358. setTimeout(() => {
  359. this.disableFlag = false;
  360. }, 1500);
  361. },
  362. submitCom() {
  363. if (this.disableFlag) {
  364. return;
  365. }
  366. this.disableFlag = true;
  367. let validSp = [];
  368. if (this.isView) {
  369. // validSp = ["group", "studentNumber", "name", "sex", "password", "comPassword"];
  370. validSp = ["group","studentNumber", "name", "sex"];
  371. } else {
  372. validSp = ["group","studentNumber", "name", "sex"];
  373. }
  374. let aa = [];
  375. this.$refs["ruleForm"].validateField(validSp, (valid) => {
  376. if (!valid) {
  377. aa.push(valid);
  378. //判断是编辑还是新增
  379. if (this.isView) {
  380. if (aa.length == 4) {
  381. this.register();
  382. } else {
  383. this.disableFlagStatus();
  384. }
  385. } else {
  386. if (aa.length == 4) {
  387. this.editUserFun();
  388. } else {
  389. this.disableFlagStatus();
  390. }
  391. }
  392. //都校验通过后可以触发注册接口了
  393. //调用方法进行入参
  394. } else {
  395. this.disableFlagStatus();
  396. }
  397. });
  398. },
  399. register() {
  400. // if (this.ruleForm.group.length == 1) {
  401. // this.$message({
  402. // message: "请选择专业节点",
  403. // type: "warning",
  404. // });
  405. // return;
  406. // }
  407. this.queryOrgName();
  408. console.log(this.ruleForm.group);
  409. let that = this;
  410. // this.ruleForm.password = md5(this.ruleForm.password);
  411. this.$http.post(
  412. `/user/addOrUpdateUser`,
  413. {
  414. // orgNo: this.userInfo.orgNo,
  415. // orgName: this.userInfo.orgName,
  416. orgNo: this.ruleForm.group[this.ruleForm.group.length - 1],
  417. orgName: this.groupName,
  418. userNo: this.ruleForm.studentNumber,
  419. userName: this.ruleForm.name,
  420. gender: this.ruleForm.sex,
  421. position: -1,
  422. // password: md5(this.ruleForm.password),
  423. //roleType 5超级管理员 4 院管理员 3 辅导员 2 教师 1学生
  424. roleType: "2",
  425. },
  426. (res) => {
  427. this.disableFlagStatus();
  428. // this.disableFlag = false;
  429. if (res && res.code == 200) {
  430. this.dialogVisible = false;
  431. // this.$toast.success({ message: "成功" });
  432. //调用父组件的查询方法
  433. this.$message.success(res.msg);
  434. that.$emit("search");
  435. } else {
  436. // this.$toast.fail({ message: res.msg });
  437. this.$message.error(res.msg);
  438. }
  439. //清空缓存
  440. this.cancle();
  441. }
  442. );
  443. },
  444. editUserFun() {
  445. let that = this;
  446. this.queryOrgName();
  447. this.userDetailData.orgNo = this.ruleForm.group[this.ruleForm.group.length - 1];
  448. this.userDetailData.orgName = this.groupName;
  449. // this.userDetailData.userName = this.ruleForm.name;
  450. // this.userDetailData.userNo = this.ruleForm.studentNumber;
  451. this.userDetailData.gender = this.ruleForm.sex;
  452. this.$http.post(
  453. `/user/addOrUpdateUser`,
  454. {
  455. ...this.userDetailData,
  456. },
  457. (res) => {
  458. this.disableFlagStatus();
  459. if (res && res.code == 200) {
  460. this.dialogVisible = false;
  461. // this.$toast.success({ message: "成功" });
  462. //调用父组件的查询方法
  463. that.$emit("search");
  464. this.$message.success("修改成功");
  465. } else {
  466. // this.$toast.fail({ message: res.msg });
  467. this.$message.error(res.msg);
  468. }
  469. //清空缓存
  470. //清空缓存
  471. }
  472. );
  473. },
  474. },
  475. };
  476. </script>
  477. <style lang="less" scoped>
  478. .el-form-item {
  479. margin-bottom: 5px !important;
  480. }
  481. .dig_update /deep/.el-cascader {
  482. position: relative;
  483. font-size: 14px;
  484. line-height: 40px;
  485. width: 100%;
  486. }
  487. .dig_update /deep/.el-dialog {
  488. box-shadow: none !important;
  489. background: transparent !important;
  490. }
  491. .demo-ruleForm /deep/ .el-form-item {
  492. margin-right: 10px;
  493. vertical-align: top;
  494. display: flex !important;
  495. flex-direction: column;
  496. }
  497. .demo-ruleForm /deep/.el-form-item__label {
  498. text-align: left;
  499. vertical-align: middle;
  500. float: left;
  501. font-size: 14px;
  502. color: #606266;
  503. line-height: 40px;
  504. padding: 0 12px 0 0;
  505. -webkit-box-sizing: border-box;
  506. box-sizing: border-box;
  507. }
  508. .demo-ruleForm /deep/.el-input {
  509. width: 100% !important;
  510. }
  511. .demo-ruleForm /deep/.el-input__inner {
  512. width: 100% !important;
  513. background-color: #f7f7f7;
  514. border: 0px;
  515. }
  516. .dig_button {
  517. margin-top: 20px;
  518. display: flex;
  519. width: 100%;
  520. justify-content: space-around;
  521. }
  522. .demo-ruleForm {
  523. background-color: #ffffff;
  524. // border-radius: 20px;
  525. margin-right: -10px;
  526. margin-top: -10px;
  527. padding-right: 100px;
  528. padding-left: 100px;
  529. border-radius: 20px;
  530. padding-top: 20px;
  531. padding-bottom: 40px;
  532. .dig_title {
  533. margin-bottom: 30px;
  534. text-align: center;
  535. font-weight: 700;
  536. }
  537. }
  538. </style>