manageRegister.vue 15 KB

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