manageRegister.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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. :props="{ checkStrictly: true }"
  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. this.groupData = resultRes;
  200. } else {
  201. this.groupData = [];
  202. }
  203. // this.channelList = res.data;
  204. } else {
  205. this.$message.error(res.msg);
  206. }
  207. });
  208. },
  209. //z增加
  210. addPro(val) {
  211. let data = JSON.parse(JSON.stringify(val));
  212. for (let i = 0; i < val.length; i++) {
  213. data[i].value = val[i].orgNo;
  214. data[i].label = val[i].orgName;
  215. }
  216. return data;
  217. },
  218. //非递归方式:将平铺数据转换为树形结构数据
  219. arrToTree(arr) {
  220. let data = arr.filter((item) => {
  221. item.children = arr.filter((e) => {
  222. return item.orgNo === e.parentOrgNo;
  223. });
  224. return !item.parentOrgNo;
  225. });
  226. return data;
  227. },
  228. //去除转换树形结构数据后存在的空children
  229. deleteChildren(arr) {
  230. let childs = arr;
  231. for (let i = childs.length; i--; i > 0) {
  232. if (childs[i].children) {
  233. if (childs[i].children.length) {
  234. this.deleteChildren(childs[i].children);
  235. } else {
  236. delete childs[i].children;
  237. }
  238. }
  239. }
  240. return arr;
  241. },
  242. queryOrgName() {
  243. for (let i = 0; i < this.ppData.length; i++) {
  244. if (this.ruleForm.group[this.ruleForm.group.length - 1] == this.ppData[i].orgNo) {
  245. this.groupName = this.ppData[i].orgName;
  246. }
  247. }
  248. },
  249. //获取组织架构方法--------------------结束-----------------------
  250. timeChange(val) {
  251. if (val !== null) {
  252. //根据时间得到格式化的数据
  253. this.ruleForm.birthDate = this.formatterTime(val);
  254. }
  255. },
  256. formatterTime(val) {
  257. let date = new Date(val);
  258. let year = date.getFullYear();
  259. let month = date.getMonth() + 1;
  260. month = this.formatterMon(month);
  261. let day = date.getDate();
  262. day = this.formatterMon(day);
  263. return year + "-" + month + "-" + day;
  264. },
  265. formatterMon(val) {
  266. if (val < 10) {
  267. return "0" + val;
  268. } else {
  269. return val;
  270. }
  271. },
  272. open(val) {
  273. this.cancle();
  274. this.getChannel();
  275. this.dialogVisible = true;
  276. this.isView = val;
  277. this.$nextTick(() => {
  278. this.$refs.ruleForm.clearValidate();
  279. });
  280. },
  281. edit(val) {
  282. this.getChannel();
  283. this.dialogVisible = true;
  284. this.isView = false;
  285. this.queryUserDetail(val.id);
  286. //调用查询详情的接口
  287. },
  288. //调用查询详情的接口
  289. queryUserDetail(val) {
  290. let url = `/user/findUserById?id=${val}`;
  291. this.$http.get(url, {}, (res) => {
  292. console.log(res);
  293. if (res && res.code == 200) {
  294. //获取返回值
  295. //根据将数据存储
  296. this.userDetailData = res.data;
  297. let a = [];
  298. for (let i = res.data.orgList.length; i > 0; i--) {
  299. //
  300. a.push(res.data.orgList[i - 1].orgNo);
  301. }
  302. //回显学号
  303. this.ruleForm.studentNumber = res.data.userNo;
  304. //回显姓名
  305. this.ruleForm.name = res.data.userName;
  306. //回显性别
  307. this.ruleForm.sex = res.data.gender;
  308. this.ruleForm.group = a;
  309. } else {
  310. // this.$toast.fail(res.msg);
  311. this.$message.error(res.msg);
  312. }
  313. });
  314. },
  315. cancle() {
  316. this.$refs["ruleForm"].clearValidate();
  317. //清空表单
  318. this.ruleForm.group = "";
  319. this.ruleForm.name = "";
  320. this.ruleForm.studentNumber = "";
  321. this.ruleForm.password = "";
  322. this.ruleForm.comPassword = "";
  323. this.ruleForm.sex = "";
  324. this.dialogVisible = false;
  325. },
  326. disableFlagStatus() {
  327. setTimeout(() => {
  328. this.disableFlag = false;
  329. }, 1500);
  330. },
  331. submitCom() {
  332. if (this.disableFlag) {
  333. return;
  334. }
  335. this.disableFlag = true;
  336. let validSp = [];
  337. if (this.isView) {
  338. validSp = ["group", "studentNumber", "name", "sex", "password", "comPassword"];
  339. } else {
  340. validSp = ["group", "studentNumber", "name", "sex"];
  341. }
  342. let aa = [];
  343. this.$refs["ruleForm"].validateField(validSp, (valid) => {
  344. if (!valid) {
  345. aa.push(valid);
  346. //判断是编辑还是新增
  347. if (this.isView) {
  348. if (aa.length == 6) {
  349. this.register();
  350. } else {
  351. this.disableFlagStatus();
  352. }
  353. } else {
  354. if (aa.length == 4) {
  355. this.editUserFun();
  356. } else {
  357. this.disableFlagStatus();
  358. }
  359. }
  360. //都校验通过后可以触发注册接口了
  361. //调用方法进行入参
  362. } else {
  363. this.disableFlagStatus();
  364. }
  365. });
  366. },
  367. register() {
  368. this.queryOrgName();
  369. if (this.ruleForm.group.length != 2) {
  370. this.$message({
  371. message: "院管理员请选择二级组织架构",
  372. type: "error",
  373. });
  374. return;
  375. }
  376. console.log(this.ruleForm.group);
  377. let that = this;
  378. // this.ruleForm.password = md5(this.ruleForm.password);
  379. this.$http.post(
  380. `/user/addOrUpdateUser`,
  381. {
  382. orgNo: this.ruleForm.group[this.ruleForm.group.length - 1],
  383. orgName: this.groupName,
  384. userNo: this.ruleForm.studentNumber,
  385. userName: this.ruleForm.name,
  386. gender: this.ruleForm.sex,
  387. password: md5(this.ruleForm.password),
  388. //roleType 1普通用户 roleType 管理员
  389. roleType: "2",
  390. },
  391. (res) => {
  392. this.disableFlagStatus();
  393. // this.disableFlag = false;
  394. if (res && res.code == 200) {
  395. this.dialogVisible = false;
  396. // this.$toast.success({ message: "成功" });
  397. //调用父组件的查询方法
  398. that.$emit("search");
  399. } else {
  400. // this.$toast.fail({ message: res.msg });
  401. this.$message.error(res.msg);
  402. }
  403. //清空缓存
  404. this.cancle();
  405. }
  406. );
  407. },
  408. editUserFun() {
  409. let that = this;
  410. this.queryOrgName();
  411. if (this.ruleForm.group.length != 2) {
  412. this.$message({
  413. message: "院管理员请选择二级组织架构",
  414. type: "error",
  415. });
  416. return;
  417. }
  418. this.userDetailData.orgNo = this.ruleForm.group[this.ruleForm.group.length - 1];
  419. this.userDetailData.orgName = this.groupName;
  420. this.userDetailData.userName = this.ruleForm.name;
  421. this.userDetailData.gender = this.ruleForm.sex;
  422. this.userDetailData.userNo = this.ruleForm.studentNumber;
  423. this.$http.post(
  424. `/user/addOrUpdateUser`,
  425. {
  426. ...this.userDetailData,
  427. },
  428. (res) => {
  429. this.disableFlagStatus();
  430. if (res && res.code == 200) {
  431. this.dialogVisible = false;
  432. // this.$toast.success({ message: "成功" });
  433. //调用父组件的查询方法
  434. that.$emit("search");
  435. this.$message.success("修改成功");
  436. } else {
  437. // this.$toast.fail({ message: res.msg });
  438. this.$message.error(res.msg);
  439. }
  440. //清空缓存
  441. //清空缓存
  442. }
  443. );
  444. },
  445. },
  446. };
  447. </script>
  448. <style lang="less" scoped>
  449. .dig_update /deep/.el-cascader {
  450. position: relative;
  451. font-size: 14px;
  452. line-height: 40px;
  453. width: 100%;
  454. }
  455. .dig_update /deep/.el-dialog {
  456. box-shadow: none !important;
  457. background: transparent !important;
  458. }
  459. .demo-ruleForm /deep/ .el-form-item {
  460. margin-right: 10px;
  461. vertical-align: top;
  462. display: flex !important;
  463. flex-direction: column;
  464. }
  465. .demo-ruleForm /deep/.el-form-item__label {
  466. text-align: left;
  467. vertical-align: middle;
  468. float: left;
  469. font-size: 14px;
  470. color: #606266;
  471. line-height: 40px;
  472. padding: 0 12px 0 0;
  473. -webkit-box-sizing: border-box;
  474. box-sizing: border-box;
  475. }
  476. .demo-ruleForm /deep/.el-input {
  477. width: 100% !important;
  478. }
  479. .demo-ruleForm /deep/.el-input__inner {
  480. width: 100% !important;
  481. background-color: #f7f7f7;
  482. border: 0px;
  483. }
  484. .dig_button {
  485. display: flex;
  486. width: 100%;
  487. justify-content: space-around;
  488. }
  489. .demo-ruleForm {
  490. background-color: #ffffff;
  491. // border-radius: 20px;
  492. margin-right: -10px;
  493. margin-top: -10px;
  494. padding-right: 100px;
  495. padding-left: 100px;
  496. border-radius: 20px;
  497. padding-top: 20px;
  498. padding-bottom: 40px;
  499. .dig_title {
  500. margin-bottom: 30px;
  501. text-align: center;
  502. font-weight: 700;
  503. }
  504. }
  505. </style>