Register.vue 16 KB

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