manageRegister.vue 16 KB

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