123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- <template>
- <div
- class="pb_content"
- style="
- width: 100%;
- height: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- min-height: 640px;
- min-width: unset;
- margin: 0;
- "
- >
- <div class="pb_content_body" style="position: relative; width: 100%">
- <div style="width: 100%; margin: 0px auto">
- <div class="formTop">
- <div class="tx">
- <img
- :src="ruleForm.headportrait ? ruleForm.headportrait : tx"
- alt
- />
- </div>
- <!-- <div class="right">
- <div class="name">{{ ruleForm.name }}</div>
- <div class="rightBottom">
- <div class="emailImg">
- <img src="../../../assets/email.png" alt />
- </div>
- <div class="email">{{ ruleForm.mail }}</div>
- </div>
- </div> -->
- </div>
- <div class="data_nav">
- <span @click="type = 1" :class="{ active: type == 1 }">我的资料</span>
- <span @click="type = 2" :class="{ active: type == 2 }">修改密码</span>
- </div>
- <el-form
- v-if="type == 1"
- :model="ruleForm"
- :rules="rules"
- ref="ruleForm"
- label-width="100px"
- class="demo-ruleForm"
- >
- <!-- <el-form-item label="姓名" prop="teacherName">
- <el-input
- v-model="ruleForm.name"
- style="width: 250px"
- placeholder="请输入名字"
- ></el-input>
- </el-form-item>-->
- <el-form-item label="性别">
- <el-radio-group v-model="ruleForm.sex">
- <el-radio label="男"></el-radio>
- <el-radio label="女"></el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="姓名" prop="username">
- <el-input
- v-model="ruleForm.name"
- style="width: 300px"
- placeholder="请输入姓名"
- ></el-input>
- </el-form-item>
- <!-- <el-form-item label="邮箱" prop="mail">
- <el-input
- v-if="ruleForm.mail == ''"
- v-model="ruleForm.mail"
- style="width: 300px"
- placeholder="请输入邮箱"
- ></el-input>
- <el-input
- v-else
- disabled
- v-model="ruleForm.mail"
- style="width: 300px"
- placeholder="请输入邮箱"
- ></el-input>
- </el-form-item> -->
- <!-- <el-form-item label="手机号码" prop="phone">
- <el-input
- v-model="ruleForm.phone"
- style="width: 300px"
- placeholder="请输入手机号码"
- ></el-input>
- </el-form-item> -->
- <el-form-item label="学校" prop="sBySchool">
- <el-select
- v-model="ruleForm.sBySchool"
- clearable
- placeholder="请选择学校"
- disabled
- >
- <!-- <el-option
- v-for="item in schoolJuri"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option> -->
- <el-option :value="ruleForm.sBySchool"> </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="联结学校" prop="cname" v-if="false">
- <el-select
- v-model="ruleForm.cname"
- clearable
- placeholder="暂无联结学校"
- disabled
- >
- <el-option
- v-for="item in orgJuri"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="submitForm('ruleForm')"
- >修改</el-button
- >
- </el-form-item>
- </el-form>
- <div class="password" v-if="type == 2">
- <div class="input_box">
- <span>原密码</span>
- <el-input
- class="input"
- v-model="opassword"
- placeholder="请输入原密码"
- ></el-input>
- </div>
- <div class="input_box">
- <span>修改密码</span>
- <el-input
- class="input"
- v-model="password"
- placeholder="请输入修改密码"
- ></el-input>
- </div>
- <div class="input_box">
- <span></span>
- <div class="input">
- <el-button type="primary" @click="updatePassword">修改</el-button>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- data() {
- var validatePass = (rule, value, callback) => {
- if (value == "") {
- return;
- }
- var reg =
- /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
- if (!reg.test(value)) {
- callback(new Error("请输入正确的邮箱"));
- } else {
- callback();
- }
- };
- var validatePass1 = (rule, value, callback) => {
- var reg = /^1\d{10}$/;
- if (!reg.test(value)) {
- callback(new Error("请输入正确的手机号码"));
- } else {
- callback();
- }
- };
- return {
- type: 1,
- ruleForm: {
- name: "",
- type: "",
- sex: "男",
- intro: "",
- // mail: "",
- phone: "",
- sBySchool: "",
- org: "",
- headportrait: "",
- cname:"",
- },
- opassword: "",
- password: "",
- tx: require("../../../assets/avatar.png"),
- userinfo: "",
- schoolJuri: [],
- orgJuri: [],
- userid: this.$route.query.userid,
- rules: {
- pass: [{ validator: validatePass, trigger: "blur" }],
- name: [{ required: true, message: "请输入你的名字", trigger: "blur" }],
- mail: [
- {
- required: true,
- message: "请输入你的邮箱",
- trigger: "blur",
- },
- ],
- phone: [
- // { required: true, message: "请输入你的手机号码", trigger: "blur" },
- {
- validator: validatePass1,
- trigger: "blur",
- },
- ],
- },
- };
- },
- methods: {
- getSchool() {
- this.isLoading = true;
- let params = {
- page: this.page,
- };
- this.ajax
- .get(this.$store.state.api + "selectOrg", params)
- .then((res) => {
- this.isLoading = false;
- this.schoolJuri = res.data[0];
- })
- .catch((err) => {
- this.isLoading = false;
- console.error(err);
- });
- },
- getOrg() {
- this.isLoading = true;
- this.ajax
- .get(this.$store.state.api + "selectorg2", "")
- .then((res) => {
- this.isLoading = false;
- this.orgJuri = res.data[0];
- })
- .catch((err) => {
- this.isLoading = false;
- console.error(err);
- });
- },
- submitForm(formName) {
- this.$refs[formName];
- let params = [
- {
- userid: this.userid,
- username: this.ruleForm.name,
- type: this.ruleForm.type == "老师" ? 1 : 2,
- oid: this.ruleForm.sBySchool,
- phone: this.ruleForm.phone,
- intro: "",
- sex: this.ruleForm.sex == "男" ? "0" : "1",
- },
- ];
- this.ajax
- .post(this.$store.state.api + "updatePblMessage2", params)
- .then((res) => {
- this.$message({
- message: "修改成功",
- type: "success",
- });
- window.parent.postMessage({ close: "1" }, "*");
- this.getUser();
- })
- .catch((err) => {
- this.$message.error("修改失败");
- console.error(err);
- });
- },
- getUser() {
- let params = { uid: this.userid };
- this.ajax
- .get(this.$store.state.api + "getUser", params)
- .then((res) => {
- this.userinfo = res.data[0][0];
- // this.$cookies.set("userInfo", this.userinfo, -1);
- this.$cookies.set("teacherInfo", res.data[0][0], -1);
- this.$store.commit("update", ["userInfo", this.userinfo]);
- console.log(res.data[0][0]);
- })
- .catch((err) => {
- console.error(err);
- });
- },
- getDetail() {
- let params = { uid: this.userid };
- this.ajax
- .get(this.$store.state.api + "getUser", params)
- .then((res) => {
- if (res.data[0][0]) {
- res.data[0][0].sex = res.data[0][0].sex ? "女" : "男";
- this.ruleForm = res.data[0][0];
- this.ruleForm.org = res.data[0][0].org
- ? res.data[0][0].org.split(",")[0]
- : "";
- this.ruleForm.type = res.data[0][0].type == 1 ? "老师" : "学生";
- this.ruleForm.name = res.data[0][0].username;
- console.log(res.data[0][0]);
- }
- })
- .catch((err) => {
- console.error(err);
- });
- },
- updatePassword() {
- if (this.password.length < 6) {
- this.$message.error("密码长度不少于6位");
- return;
- }
- let params = [
- {
- userid: this.userid,
- opassword: this.opassword,
- password: this.password,
- },
- ];
- this.ajax
- .post(this.$store.state.api + "updatePassword", params)
- .then((res) => {
- if (res.data[0] && res.data[0].success == 1) {
- this.$message.success("修改成功");
- this.opassword = "";
- this.password = "";
- } else {
- this.$message.error("修改失败,原密码不正确");
- }
- })
- .catch((err) => {
- this.$message.error("修改失败");
- console.error(err);
- });
- },
- },
- created() {
- this.getSchool();
- this.getOrg();
- this.getDetail();
- },
- };
- </script>
- <style scoped>
- .formTop {
- display: flex;
- align-items: center;
- justify-content: center;
- margin: 20px 0;
- }
- .formTop >>> .el-form {
- margin: 0 auto;
- }
- .tx {
- width: 100px;
- /* margin-right: 15px; */
- min-width: 50px;
- min-height: 50px;
- }
- .emailImg {
- width: 30px;
- margin-right: 5px;
- }
- .tx > img,
- .emailImg > img {
- width: 100%;
- height: 100%;
- }
- .right {
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- }
- .name {
- color: #3c88dd;
- font-size: 20px;
- margin-bottom: 10px;
- }
- .email {
- color: #acacac;
- font-size: 18px;
- }
- .rightBottom {
- display: flex;
- align-items: center;
- }
- .demo-ruleForm {
- width: 100%;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- background: #fff;
- }
- /* .demo-ruleForm >>> .el-form-item__label:before {
- content: "*";
- color: #f56c6c;
- margin-right: 4px;
- }
- .demo-ruleForm >>> .el-form-item__label:nth-child(3) {
- content: "";
- } */
- .demo-ruleForm >>> .el-form-item__content {
- width: 300px;
- }
- .data_nav {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- margin: 10px 0;
- }
- .data_nav span {
- box-sizing: border-box;
- padding: 8px 5px;
- cursor: pointer;
- color: #444444;
- height: 35px;
- }
- .data_nav span + span {
- margin-left: 10px;
- }
- .data_nav .active {
- color: #4aa3ff;
- border-bottom: 2px solid #409eff;
- }
- .password {
- height: 511px;
- padding: 50px 0 0 0;
- box-sizing: border-box;
- /* display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column; */
- }
- .input_box {
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .input_box span {
- width: 100px;
- font-size: 14px;
- text-align: right;
- padding: 0 12px 0 0;
- }
- .input_box .input {
- width: 300px;
- }
- .input_box + .input_box {
- margin-top: 20px;
- }
- </style>
|