Forráskód Böngészése

添加与修改老师

yuanyiming 1 éve
szülő
commit
6a293428ef
1 módosított fájl, 268 hozzáadás és 77 törlés
  1. 268 77
      src/components/pages/sz/teacher.vue

+ 268 - 77
src/components/pages/sz/teacher.vue

@@ -116,11 +116,19 @@
           </el-table-column>
           <el-table-column label="操作" width="220px">
             <template slot-scope="scope">
-              <div
-                class="delete"
-                @click="deleteStudent(scope.row.userid, scope.row.state)"
-              >
-                <img src="../../../assets/remove.png" alt />
+              <div style="display: flex;">
+                <el-button
+                  size="mini"
+                  type="primary"
+                  @click="modifyDiaBtn(scope.row)"
+                  >修改</el-button
+                >
+                <div
+                  class="delete"
+                  @click="deleteStudent(scope.row.userid, scope.row.state)"
+                >
+                  <img src="../../../assets/remove.png" alt />
+                </div>
               </div>
             </template>
           </el-table-column>
@@ -137,12 +145,84 @@
         ></el-pagination>
       </div>
     </div>
+
+    <el-dialog
+      title="修改账号信息"
+      :visible.sync="modifyDia"
+      :append-to-body="true"
+      width="700px"
+      :before-close="handleClose"
+      :close-on-click-modal="true"
+      class="add_student"
+    >
+      <el-form class="inputClass">
+        <el-form-item label="教师名称" :label-width="formLabelWidth">
+          <span>
+            <el-input
+              placeholder="请输入教师姓名"
+              clearable
+              v-model.trim="modifyDiaData.dName"
+              class="add_input"
+            ></el-input>
+          </span>
+        </el-form-item>
+        <el-form-item label="教师账号" :label-width="formLabelWidth">
+          <span>
+            <el-input
+              placeholder="请输入教师姓名"
+              clearable
+              disabled
+              v-model.trim="modifyDiaData.mail"
+              class="add_input"
+            ></el-input>
+          </span>
+        </el-form-item>
+        <el-form-item label="手机号" :label-width="formLabelWidth">
+          <span>
+            <el-input
+              placeholder="请输入手机号"
+              clearable
+              disabled
+              v-model="modifyDiaData.tel"
+              class="add_input"
+            ></el-input>
+          </span>
+        </el-form-item>
+        <el-form-item
+          label="角色"
+          :label-width="formLabelWidth"
+          v-if="org && org != 'undefined' && org != 'null'"
+        >
+          <template>
+            <el-radio v-model="modifyDiaData.radio" :label="0">管理员</el-radio>
+            <el-radio v-model="modifyDiaData.radio" :label="1"
+              >普通教师</el-radio
+            >
+          </template>
+        </el-form-item>
+        <!-- <el-form-item label="所属学校" :label-width="formLabelWidth" v-else>
+          <el-select v-model="oidName.name" disabled>
+            <el-option
+              v-for="(item, index) in classJuri"
+              :key="index"
+              :label="item.name"
+              :value="item.id"
+            ></el-option>
+          </el-select>
+        </el-form-item> -->
+      </el-form>
+      <span slot="footer" class="dialog-footer flex">
+        <el-button class="right" @click="conModify">确认</el-button>
+      </span>
+    </el-dialog>
+
     <el-dialog
       title="添加教师"
       :visible.sync="dialogVisible"
       :append-to-body="true"
       width="700px"
       :before-close="handleClose"
+      :close-on-click-modal="true"
       class="add_student"
     >
       <!-- <div slot="title" class="header-title">
@@ -172,6 +252,18 @@
             ></el-input>
           </span>
         </el-form-item>
+        <el-form-item label="教师账号" :label-width="formLabelWidth">
+          <span>
+            <template>
+              <el-radio v-model="addRadio" :label="0"
+                >管理员</el-radio
+              >
+              <el-radio v-model="addRadio" :label="1"
+                >普通教师</el-radio
+              >
+            </template>
+          </span>
+        </el-form-item>
         <el-form-item
           label="所属学校"
           :label-width="formLabelWidth"
@@ -209,7 +301,7 @@
 
 <script>
 import $ from "jquery";
-import pinyin from "../../../../node_modules/js-pinyin/index";
+// import pinyin from "../../../../node_modules/js-pinyin/index";
 export default {
   data() {
     return {
@@ -218,8 +310,22 @@ export default {
       formLabelWidth: "100px",
       tableData: [],
       dialogVisible: false,
+
+      modifyDia: false,
+      modifyDiaData: {
+        userid: "",
+        mail:'',
+        dName: "",
+        tel: "",
+        radio: 0,
+        type: 0,
+        role: 0
+      },
       sName: "",
       sMail: "",
+      addPol: "",
+      addTyp: 0,
+      addRadio: 1,
       sId: "",
       schoolName: "",
       schoolJuri: [],
@@ -233,11 +339,11 @@ export default {
       oid: this.$route.query.oid,
       cid: "",
       org: this.$route.query.org,
-      tx: require("../../../assets/avatar.png"),
+      tx: require("../../../assets/avatar.png")
     };
   },
   mounted() {
-    this.$nextTick(function () {
+    this.$nextTick(function() {
       this.tableHeight =
         window.innerHeight - this.$refs.table.$el.offsetTop - 200;
       if (this.tableHeight <= 530) {
@@ -245,7 +351,7 @@ export default {
       }
       // 监听窗口大小变化
       let self = this;
-      window.onresize = function () {
+      window.onresize = function() {
         self.tableHeight =
           window.innerHeight - self.$refs.table.$el.offsetTop - 200;
         if (self.tableHeight <= 530) {
@@ -255,6 +361,76 @@ export default {
     });
   },
   methods: {
+    // 确定修改信息
+    conModify() {
+      if (!this.modifyDiaData.dName) {
+        this.$message({
+          message: "教师名称不能为空",
+          type: "error"
+        });
+        return;
+      }
+
+      let uRole = null;
+      let uType = null;
+      if (!this.modifyDiaData.radio) {
+        uRole = 1;
+        uType = 0;
+      } else {
+        uRole = this.modifyDiaData.role;
+        uType = this.modifyDiaData.type;
+      }
+
+      let params = [
+        {
+          uid: this.modifyDiaData.userid,
+          uname: this.modifyDiaData.dName,
+          rol: uRole,
+          typ: uType
+        }
+      ];
+      this.ajax
+        .post(this.$store.state.api + "updateYTeacherInfo", params)
+        .then(res => {
+          this.$message({
+            message: "修改成功",
+            type: "success"
+          });
+          this.modifyDia = false;
+          this.getStudent();
+        })
+        .catch(err => {
+          this.isLoading = false;
+          this.$message({
+            message: "修改失败",
+            type: "error"
+          });
+          console.error(err);
+        });
+      // return console.log(data);
+
+      // this.
+    },
+    // 修改用户信息弹窗
+    modifyDiaBtn(val) {
+      console.log(val);
+      this.modifyDiaData.userid = val.userid;
+      this.modifyDiaData.dName = val.username;
+      this.modifyDiaData.tel = "";
+      this.modifyDiaData.role = val.role;
+      this.modifyDiaData.type = val.type;
+      this.modifyDiaData.mail = val.un;
+
+
+
+      if (val.type == 0 && val.role == 1) {
+        this.modifyDiaData.radio = 0;
+      } else {
+        this.modifyDiaData.radio = 1;
+      }
+
+      this.modifyDia = true;
+    },
     tableRowClassName({ row, rowIndex }) {
       if ((rowIndex + 1) % 2 === 0) {
         return "even_row";
@@ -282,7 +458,7 @@ export default {
     getExcel(res) {
       require.ensure([], () => {
         const {
-          export_json_to_excel,
+          export_json_to_excel
         } = require("../../../common/Export2Excel");
         const tHeader = ["教师姓名", "教师账号", "学校"];
         const data = [];
@@ -349,19 +525,28 @@ export default {
         let params = { un: this.sMail };
         this.ajax
           .get(this.$store.state.api + "findMail", params)
-          .then((res) => {
+          .then(res => {
             if (res.data[0].length > 0) {
               this.$message.error("此邮箱已被注册");
             } else {
               this.add_Student();
             }
           })
-          .catch((err) => {
+          .catch(err => {
             console.error(err);
           });
       }
     },
     add_Student() {
+      let AddT=0
+      let addR=0
+      if (!this.addRadio) {
+        AddT=0
+        addR=1
+      }else{
+        AddT=1
+        addR=0
+      }
       let params = [
         {
           username: this.sMail,
@@ -378,37 +563,41 @@ export default {
           ph: this.sPhone,
           sid: this.sId,
           cid: "",
-        },
+          typ:AddT,
+          rol:addR
+        }
       ];
+      // return console.log('params:',params);
+
       this.ajax
-        .post(this.$store.state.api + "batchRegistration1", params)
-        .then((res) => {
+        .post(this.$store.state.api + "teacherRegistration", params)
+        .then(res => {
           // debugger;
-          let params = [
-            {
-              userid: res.data.uid,
-              username: this.sName,
-              sid: this.sId,
-              type: 1,
-              org: this.org,
-              oid: res.data.oid,
-              phone: res.data.ph,
-              cid: "",
-              intro: "",
-              sex: "0",
-            },
-          ];
-          this.ajax
-            .post(this.$store.state.api + "updateUserByEdu1", params)
-            .then((res) => {
-              console.log(res);
-            })
-            .catch((err) => {
-              console.error(err);
-            });
+          // let params = [
+          //   {
+          //     userid: res.data.uid,
+          //     username: this.sName,
+          //     sid: this.sId,
+          //     type: 1,
+          //     org: this.org,
+          //     oid: res.data.oid,
+          //     phone: res.data.ph,
+          //     cid: "",
+          //     intro: "",
+          //     sex: "0"
+          //   }
+          // ];
+          // this.ajax
+          //   .post(this.$store.state.api + "updateUserByEdu1", params)
+          //   .then(res => {
+          //     console.log(res);
+          //   })
+          //   .catch(err => {
+          //     console.error(err);
+          //   });
           this.$message({
             message: "新增成功",
-            type: "success",
+            type: "success"
           });
           this.dialogVisible = false;
           this.sName = "";
@@ -416,11 +605,11 @@ export default {
           this.schoolName = "";
           this.getStudent();
         })
-        .catch((err) => {
+        .catch(err => {
           this.isLoading = false;
           this.$message({
             message: "新增失败",
-            type: "error",
+            type: "error"
           });
           console.error(err);
         });
@@ -429,15 +618,15 @@ export default {
     getClass() {
       this.isLoading = true;
       let params = {
-        org: this.org,
+        org: this.org
       };
       this.ajax
         .get(this.$store.state.api + "selectSchoolByOrg", params)
-        .then((res) => {
+        .then(res => {
           this.isLoading = false;
           this.classJuri = res.data[0];
         })
-        .catch((err) => {
+        .catch(err => {
           this.isLoading = false;
           console.error(err);
         });
@@ -446,15 +635,15 @@ export default {
     getOidName() {
       this.isLoading = true;
       let params = {
-        oid: this.oid,
+        oid: this.oid
       };
       this.ajax
         .get(this.$store.state.api + "selectSchoolName2", params)
-        .then((res) => {
+        .then(res => {
           this.isLoading = false;
           this.oidName = res.data[0][0];
         })
-        .catch((err) => {
+        .catch(err => {
           this.isLoading = false;
           console.error(err);
         });
@@ -488,16 +677,17 @@ export default {
             : this.oid,
         cu: this.cid,
         cn: this.sPhoneUser,
-        page: this.page,
+        page: this.page
       };
       this.ajax
-        .get(this.$store.state.api + "selectTcTeacher", params)
-        .then((res) => {
+        .get(this.$store.state.api + "selectOrgTeachar", params)
+        .then(res => {
           this.isLoading = false;
           this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
           this.tableData = res.data[0];
+          console.log("this.tableData", this.tableData);
         })
-        .catch((err) => {
+        .catch(err => {
           this.isLoading = false;
           console.error(err);
         });
@@ -515,13 +705,13 @@ export default {
         } else {
           this.$message({
             type: "warning",
-            message: "附件格式错误,请删除后重新上传!",
+            message: "附件格式错误,请删除后重新上传!"
           });
         }
       } else {
         this.$message({
           type: "warning",
-          message: "请上传附件!",
+          message: "请上传附件!"
         });
       }
     },
@@ -531,11 +721,11 @@ export default {
     exportExcel() {
       try {
         let params = {
-          oid: this.oid,
+          oid: this.oid
         };
         this.ajax
           .get(this.$store.state.api + "selectUserBySchool", params)
-          .then((res) => {
+          .then(res => {
             var res = res.data[0];
             //如果value的json字段的key值和想要的headers值不一致时,可做如下更改
             //将和下面的Object.fromEntries结合,将json字段的key值改变为要求的excel的header值
@@ -555,7 +745,7 @@ export default {
               //设置每一列的宽度
               { wch: 50 },
               { wch: 50 },
-              { wch: 50 },
+              { wch: 50 }
             ];
             XLSX.utils.book_append_sheet(workbook, ws, "sheet1"); //把sheet添加到workbook里,第三个参数是sheet名
             XLSX.writeFile(workbook, "学生信息.xlsx");
@@ -564,10 +754,10 @@ export default {
             // FileSaver.saveAs(new Blob([wbout], { type: "application/octet-stream" }), `${title} demo.xlsx`);//保存文件
             this.$message({
               message: "导出成功",
-              type: "success",
+              type: "success"
             });
           })
-          .catch((err) => {
+          .catch(err => {
             console.error(err);
           });
       } catch (e) {
@@ -577,7 +767,7 @@ export default {
     importfxx(obj) {
       const loading = this.$loading.service({
         background: "rgba(255, 255, 255, 0.7)",
-        target: document.body,
+        target: document.body
       });
       var _$ = $;
       this.importCount++;
@@ -588,14 +778,14 @@ export default {
       var f = this.file;
       var reader = new FileReader();
       //if (!FileReader.prototype.readAsBinaryString) {
-      FileReader.prototype.readAsBinaryString = function (f) {
+      FileReader.prototype.readAsBinaryString = function(f) {
         var binary = "";
         var rABS = false; //是否将文件读取为二进制字符串
         var pt = this;
         var wb; //读取完成的数据
         var outdata;
         var reader = new FileReader();
-        reader.onload = function (e) {
+        reader.onload = function(e) {
           var bytes = new Uint8Array(reader.result);
           var length = bytes.byteLength;
           for (var i = 0; i < length; i++) {
@@ -605,17 +795,17 @@ export default {
           if (rABS) {
             wb = XLSX.read(btoa(fixdata(binary)), {
               //手动转化
-              type: "base64",
+              type: "base64"
             });
           } else {
             wb = XLSX.read(binary, {
-              type: "binary",
+              type: "binary"
             });
           }
           outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); //outdata就是你想要的东西
           this.da = [...outdata];
           let arr = [];
-          this.da.map((v) => {
+          this.da.map(v => {
             let obj = {};
             obj.name = v["教师姓名"];
             obj.mail = v["教师账号"];
@@ -656,22 +846,22 @@ export default {
               org:
                 _this.org && _this.org != "undefined" && _this.org != "null"
                   ? _this.org
-                  : "",
-            },
+                  : ""
+            }
           ];
           _this.ajax
             .post(_this.$store.state.api + "batchRegistrationMore1", params)
-            .then((res) => {
+            .then(res => {
               if (z == 2) {
                 _this.$message({
                   message: "新增成功",
-                  type: "success",
+                  type: "success"
                 });
                 _this.getStudent();
               }
               loading.close();
             })
-            .catch((err) => {
+            .catch(err => {
               console.error(err);
             });
           _this.fileListUpload = [];
@@ -688,14 +878,14 @@ export default {
     },
     getSchoolName() {
       let params = {
-        oid: this.oid,
+        oid: this.oid
       };
       this.ajax
         .get(this.$store.state.api + "selectSchoolName2", params)
-        .then((res) => {
+        .then(res => {
           this.schoolName = res.data[0][0].name;
         })
-        .catch((err) => {
+        .catch(err => {
           console.error(err);
         });
     },
@@ -705,32 +895,32 @@ export default {
       this.$confirm("确定" + "删除" + "此教师吗?", "提示", {
         confirmButtonText: "确定",
         cancelButtonText: "取消",
-        type: "warning",
+        type: "warning"
       })
         .then(() => {
           this.ajax
             .post(this.$store.state.api + "deleteStudent", params)
-            .then((res) => {
+            .then(res => {
               this.$message({
                 message: "操作成功",
-                type: "success",
+                type: "success"
               });
               this.getStudent();
             })
-            .catch((err) => {
+            .catch(err => {
               this.$message.error("操作失败");
               console.error(err);
             });
         })
         .catch(() => {});
-    },
+    }
   },
   created() {
     this.page = 1;
     this.getStudent();
     this.getSchoolName();
     this.getClass();
-  },
+  }
 };
 </script>
 
@@ -906,6 +1096,7 @@ export default {
 .delete {
   width: 25px;
   cursor: pointer;
+  margin-left: 10px;
 }
 
 .tx > img,