data.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. <el-form
  35. :model="ruleForm"
  36. :rules="rules"
  37. ref="ruleForm"
  38. label-width="100px"
  39. class="demo-ruleForm"
  40. >
  41. <!-- <el-form-item label="姓名" prop="teacherName">
  42. <el-input
  43. v-model="ruleForm.name"
  44. style="width: 250px"
  45. placeholder="请输入名字"
  46. ></el-input>
  47. </el-form-item>-->
  48. <el-form-item label="性别">
  49. <el-radio-group v-model="ruleForm.sex">
  50. <el-radio label="男"></el-radio>
  51. <el-radio label="女"></el-radio>
  52. </el-radio-group>
  53. </el-form-item>
  54. <el-form-item label="昵称" prop="name">
  55. <el-input
  56. v-model="ruleForm.name"
  57. style="width: 300px"
  58. placeholder="请输入昵称"
  59. ></el-input>
  60. </el-form-item>
  61. <!-- <el-form-item label="邮箱" prop="mail">
  62. <el-input
  63. v-if="ruleForm.mail == ''"
  64. v-model="ruleForm.mail"
  65. style="width: 300px"
  66. placeholder="请输入邮箱"
  67. ></el-input>
  68. <el-input
  69. v-else
  70. disabled
  71. v-model="ruleForm.mail"
  72. style="width: 300px"
  73. placeholder="请输入邮箱"
  74. ></el-input>
  75. </el-form-item> -->
  76. <el-form-item label="手机号码" prop="phone">
  77. <el-input
  78. v-model="ruleForm.phone"
  79. style="width: 300px"
  80. placeholder="请输入手机号码"
  81. ></el-input>
  82. </el-form-item>
  83. <el-form-item label="学校" prop="sBySchool">
  84. <el-select
  85. v-model="ruleForm.sBySchool"
  86. clearable
  87. placeholder="请选择学校"
  88. >
  89. <el-option
  90. v-for="item in schoolJuri"
  91. :key="item.id"
  92. :label="item.name"
  93. :value="item.id"
  94. >
  95. </el-option>
  96. </el-select>
  97. </el-form-item>
  98. <el-form-item label="身份" prop="type">
  99. <el-select
  100. v-model="ruleForm.type"
  101. clearable
  102. placeholder="请选择身份"
  103. >
  104. <el-option value="老师">老师 </el-option>
  105. <el-option value="学生">学生 </el-option>
  106. </el-select>
  107. </el-form-item>
  108. <el-form-item label="个人简介" prop="intro">
  109. <el-input
  110. v-model="ruleForm.intro"
  111. type="textarea"
  112. :rows="5"
  113. resize="none"
  114. placeholder="想说点什么..."
  115. style="width: 300px"
  116. ></el-input>
  117. </el-form-item>
  118. <el-form-item>
  119. <el-button type="primary" @click="submitForm('ruleForm')"
  120. >修改</el-button
  121. >
  122. </el-form-item>
  123. </el-form>
  124. </div>
  125. </div>
  126. </div>
  127. </template>
  128. <script>
  129. export default {
  130. data() {
  131. var validatePass = (rule, value, callback) => {
  132. if (value == "") {
  133. return;
  134. }
  135. var reg =
  136. /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
  137. if (!reg.test(value)) {
  138. callback(new Error("请输入正确的邮箱"));
  139. } else {
  140. callback();
  141. }
  142. };
  143. var validatePass1 = (rule, value, callback) => {
  144. var reg = /^1\d{10}$/;
  145. if (!reg.test(value)) {
  146. callback(new Error("请输入正确的手机号码"));
  147. } else {
  148. callback();
  149. }
  150. };
  151. return {
  152. ruleForm: {
  153. name: "",
  154. type: [],
  155. sex: "男",
  156. intro: "",
  157. // mail: "",
  158. phone: "",
  159. sBySchool: "",
  160. headportrait: "",
  161. },
  162. tx: require("../../assets/portal.png"),
  163. userinfo: "",
  164. schoolJuri: [],
  165. userid: this.$route.query.userid,
  166. rules: {
  167. pass: [{ validator: validatePass, trigger: "blur" }],
  168. name: [{ required: true, message: "请输入你的名字", trigger: "blur" }],
  169. mail: [
  170. {
  171. required: true,
  172. message: "请输入你的邮箱",
  173. trigger: "blur",
  174. },
  175. ],
  176. phone: [
  177. { required: true, message: "请输入你的手机号码", trigger: "blur" },
  178. {
  179. validator: validatePass1,
  180. trigger: "blur",
  181. },
  182. ],
  183. },
  184. };
  185. },
  186. methods: {
  187. getSchool() {
  188. this.isLoading = true;
  189. let params = {
  190. page: this.page,
  191. };
  192. this.ajax
  193. .get(this.$store.state.api + "selectOrg", params)
  194. .then((res) => {
  195. this.isLoading = false;
  196. this.schoolJuri = res.data[0];
  197. })
  198. .catch((err) => {
  199. this.isLoading = false;
  200. console.error(err);
  201. });
  202. },
  203. submitForm(formName) {
  204. this.$refs[formName];
  205. let params = [
  206. {
  207. userid: this.userid,
  208. username: this.ruleForm.name,
  209. type: this.ruleForm.type == "老师" ? "1" : "2",
  210. oid: this.ruleForm.sBySchool,
  211. phone: this.ruleForm.phone,
  212. intro: this.ruleForm.intro,
  213. sex: this.ruleForm.sex == "男" ? "0" : "1",
  214. },
  215. ];
  216. this.ajax
  217. // .post(this.$store.state.api + "updateUser", params)
  218. .post(this.$store.state.api + "updateUserByEdu", params)
  219. .then((res) => {
  220. this.$message({
  221. message: "修改成功",
  222. type: "success",
  223. });
  224. window.parent.postMessage({ close: "1" }, "*");
  225. this.getUser();
  226. })
  227. .catch((err) => {
  228. this.$message.error("修改失败");
  229. console.error(err);
  230. });
  231. },
  232. getUser() {
  233. let params = { uid: this.userid };
  234. this.ajax
  235. .get(this.$store.state.api + "getUser", params)
  236. .then((res) => {
  237. this.userinfo = res.data[0][0];
  238. // this.$cookies.set("userInfo", this.userinfo, -1);
  239. this.$cookies.set("teacherInfo", res.data[0][0], -1);
  240. this.$store.commit("update", ["userInfo", this.userinfo]);
  241. console.log(res.data[0][0]);
  242. })
  243. .catch((err) => {
  244. console.error(err);
  245. });
  246. },
  247. getDetail() {
  248. let params = { uid: this.userid };
  249. this.ajax
  250. .get(this.$store.state.api + "getUser", params)
  251. .then((res) => {
  252. if (res.data[0][0]) {
  253. res.data[0][0].sex = res.data[0][0].sex ? "女" : "男";
  254. this.ruleForm = res.data[0][0];
  255. this.ruleForm.type = res.data[0][0].type == 1 ? "老师" : "学生";
  256. console.log(res.data[0][0]);
  257. }
  258. })
  259. .catch((err) => {
  260. console.error(err);
  261. });
  262. },
  263. },
  264. created() {
  265. this.getSchool();
  266. this.getDetail();
  267. },
  268. };
  269. </script>
  270. <style scoped>
  271. .formTop {
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. margin: 20px 0;
  276. }
  277. .formTop >>> .el-form {
  278. margin: 0 auto;
  279. }
  280. .tx {
  281. width: 100px;
  282. margin-right: 15px;
  283. min-width: 50px;
  284. min-height: 50px;
  285. }
  286. .emailImg {
  287. width: 30px;
  288. margin-right: 5px;
  289. }
  290. .tx > img,
  291. .emailImg > img {
  292. width: 100%;
  293. height: 100%;
  294. }
  295. .right {
  296. display: flex;
  297. flex-direction: column;
  298. align-items: flex-start;
  299. }
  300. .name {
  301. color: #3c88dd;
  302. font-size: 20px;
  303. margin-bottom: 10px;
  304. }
  305. .email {
  306. color: #acacac;
  307. font-size: 18px;
  308. }
  309. .rightBottom {
  310. display: flex;
  311. align-items: center;
  312. }
  313. .demo-ruleForm {
  314. width: 100%;
  315. display: flex;
  316. flex-direction: column;
  317. justify-content: center;
  318. align-items: center;
  319. background: #fff;
  320. }
  321. .demo-ruleForm >>> .el-form-item__label:before {
  322. content: "*";
  323. color: #f56c6c;
  324. margin-right: 4px;
  325. }
  326. .demo-ruleForm >>> .el-form-item__content{
  327. width: 300px;
  328. }
  329. </style>