Register.vue 21 KB

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