manageRegister.vue 16 KB

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