data.vue 12 KB

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