manageRegister.vue 15 KB

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