school.vue 18.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
<template>
  <div>
    <back-box>
      <template slot="title">
        <span>学校设置</span>
      </template>
      <template slot="btns" v-if="!code">
        <el-tooltip effect="dark" content="导入班级名单" placement="bottom">
          <el-button
            type="primary"
            icon="el-icon-upload2"
            size="mini"
            plain
            circle
            @click="diaUp = true"
          ></el-button>
        </el-tooltip>
        <el-tooltip effect="dark" content="导出班级名单" placement="bottom">
          <el-button
            type="primary"
            icon="el-icon-download"
            size="mini"
            plain
            circle
            @click="exportClazzExl"
          ></el-button>
        </el-tooltip>
      </template>
    </back-box>
    <div class="page-content">
      <div class="content-box">
        <i class="el-icon-edit" @click="diaSchool = true"></i>
        <ul class="school-info">
          <li class="school-item">
            <span class="s1">学校名称:</span>
            <span class="s2">{{ school.schoolName || "--" }}</span>
          </li>
          <li class="school-item">
            <span class="s1">授课端管理密码:</span>
            <span class="s2">{{ school.managePwd || "--" }}</span>
          </li>
          <li class="school-item">
            <span class="s1">联系人:</span>
            <span class="s2">{{ school.contactPerson || "--" }}</span>
          </li>
          <li class="school-item">
            <span class="s1">手机号码:</span>
            <span class="s2">{{ school.contactPhone || "--" }}</span>
          </li>
          <li class="school-item">
            <span class="s1">学段:</span>
            <span class="s2">{{ sections }}</span>
          </li>
          <li class="school-item">
            <span class="s1">所属集团:</span>
            <span class="s2">{{ school.tenantName || "--" }}</span>
          </li>
          <li class="school-item">
            <span class="s1">基站登录密码 :</span>
            <span class="s2">{{ school.stationPwd || "--" }}</span>
          </li>
        </ul>
        <div class="grade-box">
          <p class="h-title">
            年级管理
            <!-- <span v-if="!code" class="popconfirm-box" @click="diaUpgradeGrade = true">
              年级升级<i class="fa fa-level-up"></i>
            </span> -->
          </p>
          <ul class="grade-info">
            <li
              class="grade-item"
              v-for="item in tableData"
              :key="item.grade"
              @click="setGrade(item)"
            >
              <p class="grade-name">{{ item.gradeName }}</p>
              <div class="grade-class">
                <p>
                  <i class="fa fa-building"></i>班级:{{
                    item.classList.length
                  }}个
                </p>
                <p>
                  <i class="fa fa-book"></i>科目:{{
                    item.subjectNames.length
                  }}个
                </p>
              </div>
            </li>
          </ul>
          <el-empty
            :image-size="100"
            v-if="!tableData.length && loading == false"
            description="没有更多数据"
          ></el-empty>
        </div>
      </div>
    </div>
    <el-dialog title="导入学校名单" :visible.sync="diaUp" width="400">
      <up-load
        id="downDevice"
        :url="url"
        @upSuccess="upSuccess"
        fileName="学校名单"
      >
        <p class="down-txt" slot="down">
          通过Excel导入学校全部班级名单,点击
          <el-link type="danger" @click="downExcel">模板下载</el-link> 。
        </p>
      </up-load>
      <div class="dialog-footer" slot="footer">
        <el-button @click="diaUp = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="修改年级信息" :visible.sync="diaGrade" width="800px">
      <el-form
        class="form-box"
        :model="formGrade"
        :rules="rulesGrade"
        label-width="160px"
      >
        <el-form-item label="科目:" prop="subjectNames">
          <div class="subject-box" :class="showAll ? 'active' : ''">
            <span
              v-show="subjectList.length > 12"
              class="showAll"
              @click="showAll = !showAll"
              >{{ showAll ? "收起" : "更多..." }}</span
            >
            <el-checkbox-group v-model="formGrade.subjectNames">
              <el-checkbox
                v-for="item in subjectList"
                :label="item"
                :key="item"
                >{{ item }}</el-checkbox
              >
            </el-checkbox-group>
          </div>
          <el-col :span="8">
            <el-input
              placeholder="添加科目"
              v-model.trim="subjectName"
              maxlength="30"
            >
              <i
                slot="suffix"
                class="el-input__icon el-icon-plus"
                @click="addSubjectName"
              ></i>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="班级:">
          <span v-for="(item, index) in formGrade.classList" :key="item.id">{{
            `${item.className}${
              index == formGrade.classList.length - 1 ? "" : "、"
            }`
          }}</span>
        </el-form-item>
      </el-form>
      <div class="dialog-footer" slot="footer">
        <el-button @click="editGrade">确 定</el-button>
        <el-button @click="diaGrade = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="修改学校信息" :visible.sync="diaSchool" width="400">
      <el-form
        ref="formSchool"
        class="form-box"
        :model="formSchool"
        :rules="rulesSchool"
        label-width="160px"
      >
        <el-form-item label="学段:" prop="sections">
          <el-checkbox-group v-model="formSchool.sections">
            <el-checkbox
              v-for="item in sectionsList"
              :label="item.code"
              :key="item.code"
              :disabled="defaultSections.includes(item.code)"
              >{{ item.name }}</el-checkbox
            >
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="授课端管理密码:" prop="managePwd">
          <el-col :span="10">
            <el-input
              maxlength="20"
              v-model="formSchool.managePwd"
              show-password
              placeholder="请输入授课端管理密码"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="基站登录密码:" prop="stationPwd">
          <el-col :span="10">
            <el-input
              maxlength="6"
              v-model="formSchool.stationPwd"
              show-password
              placeholder="请输入基站登录密码"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="联系人:" prop="contactPerson"
          ><el-col :span="10"
            ><el-input
              maxlength="30"
              v-model="formSchool.contactPerson"
              placeholder="请输入联系人"
            ></el-input></el-col
        ></el-form-item>
        <el-form-item label="手机号码:" prop="contactPhone"
          ><el-col :span="10"
            ><el-input
              v-model="formSchool.contactPhone"
              type="number"
              oninput="if(value.length > 11) value = value.slice(0,11)"
              placeholder="请输入联系人手机号码"
            ></el-input></el-col
        ></el-form-item>
      </el-form>
      <div class="dialog-footer" slot="footer">
        <el-button @click="editSchool">确 定</el-button>
        <el-button @click="diaSchool = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="班级升级" :visible.sync="diaUpgradeGrade" width="400">
      <p>注意该操作会将所有年级升级,请谨慎操作!</p>
      <div class="dialog-footer" slot="footer">
        <el-button type="danger" @click="_UpgradeGrade()">确认升级</el-button>
        <el-button type="primary" @click="diaUpgradeGrade = false"
          >取 消</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { downloadFile } from "@/utils";
export default {
  data() {
    return {
      code: "", //长水跳转标志
      loading: false,
      url: "/api_html/school/manager/importClassAndStudent",
      diaUp: false,
      diaSchool: false,
      diaGrade: false,
      showAll: false, //修改年级科目显示
      school: {
        schoolName: "",
        managePwd: "",
        contactPerson: "",
        contactPhone: "",
        sections: "",
        tenantName: "",
      },
      tableData: [],
      formSchool: {
        //修改学校
        sections: "",
        managePwd: "",
        stationPwd: "",
        contactPerson: "",
        contactPhone: "",
      },
      rulesSchool: {
        sections: [{ required: true, message: "请选择学段", trigger: "blur" }],
        managePwd: [
          { required: true, message: "请填写管理密码", trigger: "blur" },
          {
            min: 8,
            max: 20,
            message: "长度在 8 到 20 个字符",
            trigger: "blur",
          },
        ],
        stationPwd: [
          { required: true, message: "请填写基站登陆密码", trigger: "blur" },
          {
            min: 6,
            max: 6,
            message: "长度为 6 个字符",
            trigger: "blur",
          },
        ],
      },
      formGrade: {
        //修改年级
        gradeName: "",
        subjectNames: [],
        classList: [],
      },
      rulesGrade: {
        subjectNames: [
          { required: true, message: "请选择科目", trigger: "blur" },
        ],
      },
      subjectName: "",
      sectionsList: [],
      subjectList: [],
      diaUpgradeGrade: false, //班级升级
      defaultSections: [],
    };
  },
  computed: {
    sections: function () {
      let arr = this.formSchool.sections || [];
      let sections = [];
      this.sectionsList.map((item) => {
        if (arr.includes(item.code)) {
          sections.push(item.name);
        }
      });
      return sections.join(",");
    },
  },
  created() {
    this.code = localStorage.getItem("csCode") || "";
    this._QueryDataSchool();
    this._QueryDataGrade();
    this._QuerySubject();
    this._QuerySectionList();
  },
  methods: {
    upSuccess(res) {
      //导入成功
      this.$message.closeAll();
      this.$message({
        showClose: true,
        message: `成功(${res.data.success})`,
        type: "success",
        duration: 5000,
      });
      this.diaUp = false;
      this._QueryDataSchool();
      this._QueryDataGrade();
    },
    setGrade(obj) {
      //打开年级设置
      this.formGrade.subjectNames = obj.subjectNames;
      this.formGrade.classList = obj.classList;
      this.formGrade.gradeName = obj.gradeName;
      this.showAll = false;
      this.diaGrade = true;
    },
    addSubjectName() {
      //添加科目
      if (!this.subjectName) {
        this.$message.warning("请填写科目名称");
        return;
      } else if (this.subjectList.includes(this.subjectName)) {
        this.$message.warning("科目已存在,请重新填写~");
        return;
      }
      this.subjectList.push(this.subjectName);
      this.formGrade.subjectNames.push(this.subjectName);
      this.subjectName = "";
    },
    editSchool() {
      //保存修改学校信息
      if (!this.formSchool.sections.length) {
        this.$message.error("请选择学段!");
        return;
      }
      if (!this.formSchool.managePwd) {
        this.$message.error("请填写密码!");
        return;
      }
      if (!this.formSchool.stationPwd) {
        this.$message.error("请填写基站登录密码!");
        return;
      }
      if (this.loading) {
        return;
      }
      this.$refs.formSchool.validate(async (valid) => {
        if (valid) {
          this.loading = true;
          let form = { ...this.formSchool };
          form.sections = this.formSchool.sections.join(",");
          const { data, status, info } = await this.$request.updateSchool({
            ...form,
          });
          this.loading = false;
          if (status === 0) {
            this.$message.success("修改成功~");
            this.diaSchool = false;
            this._QueryDataSchool();
            this._QueryDataGrade();
          } else {
            this.$message.error(info);
          }
        } else {
          this.$message.error("数据有误,请检查!");
        }
      });
    },
    async _UpgradeGrade() {
      this.loading = true;
      const { data, status, info } = await this.$request.upgradeGrade();
      this.loading = false;
      if (status === 0) {
        this.$message.success("升级成功~");
        this.diaUpgradeGrade = false;
        this._QueryDataGrade();
        this._QuerySubject();
      } else {
        this.$message.error(info);
      }
    },
    async editGrade() {
      //保存修改年级信息
      if (!this.formGrade.subjectNames.length) {
        this.$message.error("请选择科目!");
        return;
      }
      if (this.loading) {
        return;
      }
      this.loading = true;
      const { data, status, info } = await this.$request.updateGrade({
        gradeName: this.formGrade.gradeName,
        subjectNames: this.formGrade.subjectNames,
      });
      this.loading = false;
      if (status === 0) {
        this.$message.success("修改成功~");
        this.diaGrade = false;
        this._QueryDataGrade();
      } else {
        this.$message.error(info);
      }
    },
    async _QuerySectionList() {
      //学校学段
      const { data, status, info } = await this.$request.sectionList();
      console.log(status);
      if (status === 0) {
        this.sectionsList = data?.list || [];
      } else {
        this.$message.error(info);
      }
    },
    async _QueryDataSchool() {
      //学校详情
      this.loading = true;
      const { data, status, info } = await this.$request.schoolDetail();
      this.loading = false;
      if (status === 0) {
        this.school = { ...data };
        for (let key in this.formSchool) {
          if (key == "sections") {
            this.formSchool.sections = data[key].split(",").map((item) => {
              console.log(Number(item));
              return Number(item);
            });
          } else {
            this.formSchool[key] = data[key] || "";
          }
        }
        this.defaultSections = [...this.formSchool.sections];
      } else {
        this.$message.error(info);
      }
    },
    async _QueryDataGrade() {
      this.loading = true;
      const { data, status, info } = await this.$request.gradeList();
      this.loading = false;
      console.log(status);
      if (status === 0) {
        this.tableData = data.list || [];
      } else {
        this.$message.error(info);
      }
    },
    async _QuerySubject() {
      const { data, status, info } = await this.$request.subjectList();
      if (status === 0) {
        this.subjectList = [...data.subjectNames] || [];
      } else {
        this.$message.error(info);
      }
    },
    async downExcel() {
      let data = await this.$request.classAndStudentTemplate();
      if (data && !data.code) {
        let blob = new Blob([data], {
          type: "application/vnd.ms-excel;charset=utf-8",
        });
        downloadFile(`班级名单模版.xlsx`, blob);
      } else {
        this.$message.error(data.info);
      }
    },
    async exportClazzExl() {
      this.loadingDown = true;
      let data = await this.$request.exportClassAndStudent();
      this.loadingDown = false;
      if (data) {
        let blob = new Blob([data], {
          type: "application/vnd.ms-excel;charset=utf-8",
        });
        downloadFile(`班级名单.xlsx`, blob);
      } else {
        this.$message.error("下载失败");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.page-content {
  padding: 20px;
  .content-box {
    background: #f8f8f8;
    border-radius: 16px;
    position: relative;
    .el-icon-edit {
      position: absolute;
      top: 12px;
      right: 12px;
      padding: 5px;
      font-size: 18px;
      cursor: pointer;
      &:hover {
        color: #36f;
      }
    }
  }
  .school-info {
    display: flex;
    flex-wrap: wrap;
    padding: 16px 0;
    border-bottom: 0.5px solid #f2f2f2;
    .school-item {
      width: 50%;
      line-height: 48px;
      padding-left: 100px;
      display: flex;
      box-sizing: border-box;
      .s1 {
        width: 160px;
        font-size: 15px;
        color: #888;
      }
      .s2 {
        flex: 1;
      }
    }
  }
  .grade-box {
    padding: 20px;
    .h-title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .popconfirm-box {
        cursor: pointer;
        font-size: 14px;
        color: #999;
        .fa-level-up {
          font-size: 16px;
          padding-left: 2px;
        }
        &:hover {
          color: #f30;
        }
      }
    }
    .grade-info {
      display: flex;
      flex-wrap: wrap;
      padding: 20px;
      .grade-item {
        width: calc((100% - 100px) / 3);
        margin-right: 50px;
        margin-bottom: 40px;
        box-sizing: border-box;
        padding: 12px 16px;
        border-radius: 10px;
        box-shadow: 1px 1px 3px #888;
        cursor: pointer;
        transition: all 0.5s;
        &:hover {
          transform: translate(-2px, -5px);
          box-shadow: 5px 5px 10px #888;
        }
        &:nth-of-type(3n) {
          margin-right: 0;
        }
      }
      .grade-name {
        font-size: 16px;
        font-weight: bold;
        line-height: 18px;
        padding-bottom: 12px;
      }
      .grade-class {
        display: flex;
        justify-content: space-between;
        font-size: 15px;
        padding-right: 20px;
        .fa {
          font-size: 18px;
          margin-right: 5px;
          color: #a4a4a4;
        }
        .fa-book {
          font-size: 20px;
        }
      }
    }
  }
}
.form-box {
  margin: 0 20px;
  .subject-box {
    height: 90px;
    overflow: hidden;
    position: relative;
    &.active {
      height: auto;
      overflow: auto;
    }
    .showAll {
      position: absolute;
      bottom: 0;
      right: 10px;
      font-size: 12px;
      color: #7f7f7f;
      cursor: pointer;
      padding: 2px;
      &:hover {
        color: #667ffd;
      }
    }
    .el-checkbox:last-of-type {
      margin-right: 30px;
    }
  }
}
.el-icon-plus {
  cursor: pointer;
  &:hover {
    color: #667ffd;
  }
}
</style>