data.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <div class="pb_content">
  3. <div
  4. class="pb_head"
  5. style="
  6. display: flex;
  7. flex-direction: row;
  8. align-items: center;
  9. justify-content: space-between;
  10. "
  11. >
  12. <div>
  13. <span>我的资料</span>
  14. </div>
  15. <div v-if="$store.state.userInfo.type == 1">
  16. <el-button @click="goTo('/eventCenter')" type="primary" size="small"
  17. >返回</el-button
  18. >
  19. </div>
  20. </div>
  21. <div class="pb_content_body" style="position: relative; width: 100%">
  22. <div style="width: 100%; margin: 0px auto">
  23. <div
  24. :class="
  25. $store.state.userInfo.type == 1 ? 'isDataNav' : 'data_nav'
  26. "
  27. >
  28. <span @click="type = 1" :class="{ active: type == 1 }">我的资料</span>
  29. <span @click="type = 2" :class="{ active: type == 2 }">修改密码</span>
  30. </div>
  31. <el-form
  32. v-if="type == 1"
  33. :model="ruleForm"
  34. :rules="rules"
  35. autocomplete="off"
  36. ref="ruleForm"
  37. label-width="100px"
  38. :class="
  39. this.$store.state.userInfo.type == 1
  40. ? 'isDemoRuleForm'
  41. : 'demo-ruleForm'
  42. "
  43. >
  44. <!-- <el-form-item label="姓名" prop="teacherName">
  45. <el-input
  46. v-model="ruleForm.name"
  47. style="width: 250px"
  48. placeholder="请输入名字"
  49. ></el-input>
  50. </el-form-item> -->
  51. <el-form-item label="姓名" prop="name">
  52. <el-input
  53. v-model="ruleForm.name"
  54. style="width: 300px"
  55. placeholder="请输入昵称"
  56. ></el-input>
  57. </el-form-item>
  58. <el-form-item label="手机号码" prop="phone">
  59. <el-input
  60. v-model="ruleForm.phone"
  61. style="width: 300px"
  62. placeholder="请输入手机号码"
  63. ></el-input>
  64. </el-form-item>
  65. <el-form-item label="账号">
  66. <el-input
  67. v-model="ruleForm.username"
  68. disabled
  69. style="width: 300px"
  70. placeholder="请输入昵称"
  71. ></el-input>
  72. </el-form-item>
  73. <el-form-item label="地区" prop="sBySchool">
  74. <el-input
  75. v-model="ruleForm.region"
  76. disabled
  77. style="width: 300px"
  78. placeholder=""
  79. ></el-input>
  80. </el-form-item>
  81. <!-- <el-form-item label="学校" prop="sBySchool">
  82. <el-input
  83. v-model="ruleForm.school"
  84. disabled
  85. style="width: 300px"
  86. placeholder=""
  87. ></el-input>
  88. </el-form-item> -->
  89. <el-form-item label="个人简介" prop="intro">
  90. <el-input
  91. v-model="ruleForm.remark"
  92. type="textarea"
  93. :rows="5"
  94. resize="none"
  95. placeholder="想说点什么..."
  96. style="width: 300px"
  97. ></el-input>
  98. </el-form-item>
  99. <el-form-item>
  100. <el-button type="primary" @click="submitForm('ruleForm')"
  101. >修改</el-button
  102. >
  103. </el-form-item>
  104. </el-form>
  105. <div
  106. :class="
  107. this.$store.state.userInfo.type == 1 ? 'isPassword' : 'password'
  108. "
  109. v-if="type == 2"
  110. >
  111. <div class="input_box">
  112. <span>原密码</span>
  113. <el-input
  114. class="input"
  115. v-model="opassword"
  116. placeholder="请输入原密码"
  117. ></el-input>
  118. </div>
  119. <div class="input_box">
  120. <span>输入新密码</span>
  121. <div style="position: relative">
  122. <el-input
  123. :type="isLook ? 'type' : 'password'"
  124. class="input"
  125. v-model="password"
  126. placeholder="请输入修改密码"
  127. ></el-input>
  128. <div class="eye" @click="changeEye">
  129. <img :src="isLook ? eye : eyeOff" alt="" />
  130. </div>
  131. </div>
  132. </div>
  133. <div class="input_box">
  134. <span>再次输入新密码</span>
  135. <div style="position: relative">
  136. <el-input
  137. :type="isLook ? 'type' : 'password'"
  138. class="input"
  139. v-model="password1"
  140. placeholder="请再次输入修改密码"
  141. ></el-input>
  142. <div class="eye" @click="changeEye">
  143. <img :src="isLook ? eye : eyeOff" alt="" />
  144. </div>
  145. </div>
  146. </div>
  147. <div class="input_box">
  148. <span></span>
  149. <div class="input">
  150. <el-button type="primary" @click="updatePassword">修改</el-button>
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </template>
  158. <script>
  159. export default {
  160. data() {
  161. var validatePass = (rule, value, callback) => {
  162. if (value == "") {
  163. return;
  164. }
  165. var reg =
  166. /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
  167. if (!reg.test(value)) {
  168. callback(new Error("请输入正确的邮箱"));
  169. } else {
  170. callback();
  171. }
  172. };
  173. var validatePass1 = (rule, value, callback) => {
  174. var reg = /^1\d{10}$/;
  175. if (!reg.test(value)) {
  176. callback(new Error("请输入正确的手机号码"));
  177. } else {
  178. callback();
  179. }
  180. };
  181. return {
  182. type: 1,
  183. ruleForm: {
  184. name: "",
  185. type: "",
  186. region: "",
  187. phone: "",
  188. school: "",
  189. remark: "",
  190. },
  191. opassword: "",
  192. password: "",
  193. password1: "",
  194. userinfo: "",
  195. schoolJuri: [],
  196. orgJuri: [],
  197. isLook: false,
  198. eyeOff: require("../../../assets/icon/eyeOff.png"),
  199. eye: require("../../../assets/icon/eye.png"),
  200. userid: this.$store.state.userInfo.userid,
  201. rules: {
  202. pass: [{ validator: validatePass, trigger: "blur" }],
  203. name: [{ required: true, message: "请输入你的名字", trigger: "blur" }],
  204. mail: [
  205. {
  206. required: true,
  207. message: "请输入你的邮箱",
  208. trigger: "blur",
  209. },
  210. ],
  211. phone: [
  212. // { required: true, message: "请输入你的手机号码", trigger: "blur" },
  213. {
  214. required: true,
  215. validator: validatePass1,
  216. trigger: "blur",
  217. },
  218. ],
  219. },
  220. };
  221. },
  222. methods: {
  223. goTo(path) {
  224. this.$router.push(path);
  225. },
  226. submitForm(formName) {
  227. this.$refs[formName];
  228. this.$refs[formName].validate((valid) => {
  229. if (valid) {
  230. let params = [
  231. {
  232. username: this.ruleForm.name,
  233. phone: this.ruleForm.phone,
  234. intro: this.ruleForm.remark,
  235. userid: this.userid,
  236. },
  237. ];
  238. this.ajax
  239. .post(this.$store.state.api + "updateRaceUser", params)
  240. .then((res) => {
  241. this.$message({
  242. message: "修改成功",
  243. type: "success",
  244. });
  245. this.getUser();
  246. })
  247. .catch((err) => {
  248. this.$message.error("修改失败");
  249. console.error(err);
  250. });
  251. } else {
  252. return false;
  253. }
  254. });
  255. },
  256. changeEye() {
  257. this.isLook = !this.isLook;
  258. },
  259. getUser() {
  260. let params = { uid: this.userid };
  261. this.ajax
  262. .get(this.$store.state.api + "getRaceUser1", params)
  263. .then((res) => {
  264. this.userinfo = res.data[0][0];
  265. // this.$cookies.set("userInfo", this.userinfo, -1);
  266. this.$cookies.set("teacherInfo", res.data[0][0], -1);
  267. this.$store.commit("update", ["userInfo", this.userinfo]);
  268. console.log(res.data[0][0]);
  269. })
  270. .catch((err) => {
  271. console.error(err);
  272. });
  273. },
  274. getDetail() {
  275. let params = { uid: this.userid };
  276. this.ajax
  277. .get(this.$store.state.api + "getRaceUser1", params)
  278. .then((res) => {
  279. if (res.data[0][0]) {
  280. this.ruleForm = res.data[0][0];
  281. console.log(res.data[0][0]);
  282. }
  283. })
  284. .catch((err) => {
  285. console.error(err);
  286. });
  287. },
  288. updatePassword() {
  289. if (this.password.length < 6) {
  290. this.$message.error("密码长度不少于6位");
  291. return;
  292. } else if (this.password != this.password1) {
  293. this.$message.error("两次新密码不相同");
  294. return;
  295. }
  296. let params = [
  297. {
  298. userid: this.userid,
  299. opassword: this.opassword,
  300. password: this.password,
  301. },
  302. ];
  303. this.ajax
  304. .post(this.$store.state.api + "updatePassword1", params)
  305. .then((res) => {
  306. if (res.data[0] && res.data[0].success == 1) {
  307. this.$message.success("修改成功");
  308. this.opassword = "";
  309. this.password = "";
  310. } else {
  311. this.$message.error("修改失败,原密码不正确");
  312. }
  313. })
  314. .catch((err) => {
  315. this.$message.error("修改失败");
  316. console.error(err);
  317. });
  318. },
  319. },
  320. created() {
  321. this.getDetail();
  322. },
  323. };
  324. </script>
  325. <style scoped>
  326. .formTop {
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. margin: 20px 0;
  331. }
  332. .formTop >>> .el-form {
  333. margin: 0 auto;
  334. }
  335. .tx {
  336. width: 100px;
  337. /* margin-right: 15px; */
  338. min-width: 50px;
  339. min-height: 50px;
  340. }
  341. .emailImg {
  342. width: 30px;
  343. margin-right: 5px;
  344. }
  345. .tx > img,
  346. .emailImg > img {
  347. width: 100%;
  348. height: 100%;
  349. }
  350. .right {
  351. display: flex;
  352. flex-direction: column;
  353. align-items: flex-start;
  354. }
  355. .name {
  356. color: #3c88dd;
  357. font-size: 20px;
  358. margin-bottom: 10px;
  359. }
  360. .email {
  361. color: #acacac;
  362. font-size: 18px;
  363. }
  364. .rightBottom {
  365. display: flex;
  366. align-items: center;
  367. }
  368. .demo-ruleForm,
  369. .isDemoRuleForm {
  370. width: 100%;
  371. display: flex;
  372. flex-direction: column;
  373. justify-content: center;
  374. align-items: flex-start;
  375. background: #fff;
  376. margin-top: 30px;
  377. }
  378. .isDemoRuleForm {
  379. align-items: center;
  380. }
  381. /* .demo-ruleForm >>> .el-form-item__label:before {
  382. content: "*";
  383. color: #f56c6c;
  384. margin-right: 4px;
  385. }
  386. .demo-ruleForm >>> .el-form-item__label:nth-child(3) {
  387. content: "";
  388. } */
  389. .demo-ruleForm >>> .el-form-item__content {
  390. width: 300px;
  391. }
  392. .data_nav,
  393. .isDataNav {
  394. display: flex;
  395. align-items: center;
  396. justify-content: flex-start;
  397. margin: 0 0 10px 150px;
  398. }
  399. .isDataNav {
  400. justify-content: center;
  401. width: 100%;
  402. margin: 60px 0 10px 0;
  403. }
  404. .data_nav span,
  405. .isDataNav span {
  406. box-sizing: border-box;
  407. padding: 8px 5px;
  408. cursor: pointer;
  409. color: #444444;
  410. height: 35px;
  411. }
  412. .data_nav span + span,
  413. .isDataNav span + span {
  414. margin-left: 20px;
  415. }
  416. .data_nav .active,
  417. .isDataNav .active {
  418. color: #4aa3ff;
  419. border-bottom: 2px solid #409eff;
  420. }
  421. .password,
  422. .isPassword {
  423. height: 511px;
  424. padding: 10px 0 0 10px;
  425. box-sizing: border-box;
  426. display: flex;
  427. flex-direction: column;
  428. align-items: flex-start;
  429. /* display: flex;
  430. justify-content: center;
  431. align-items: center;
  432. flex-direction: column; */
  433. }
  434. .isPassword {
  435. padding: 50px 0 0 0;
  436. align-items: center;
  437. }
  438. .input_box {
  439. display: flex;
  440. align-items: center;
  441. justify-content: center;
  442. }
  443. .input_box span {
  444. width: 100px;
  445. font-size: 14px;
  446. text-align: right;
  447. padding: 0 12px 0 0;
  448. }
  449. .input_box .input {
  450. width: 300px;
  451. }
  452. .input_box + .input_box {
  453. margin-top: 20px;
  454. }
  455. .eye {
  456. position: absolute;
  457. right: 10px;
  458. top: 8px;
  459. width: 25px;
  460. height: 25px;
  461. cursor: pointer;
  462. }
  463. .eye > img {
  464. width: 100%;
  465. height: 100%;
  466. }
  467. </style>