data.vue 12 KB

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