| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
- <title>学校信息管理</title>
- <link href="https://kylx365-1253256735.file.myqcloud.com/js/jquery.tagit.css" rel="stylesheet" type="text/css">
- <link href="https://kylx365-1253256735.file.myqcloud.com/js/tagit.ui-zendesk.css" rel="stylesheet" type="text/css">
- <script src="https://kylx365-1253256735.file.myqcloud.com/js/jquery-1.10.2.min.js"></script>
- <script src="https://kylx365-1253256735.file.myqcloud.com/js/jquery-ui.min.js"></script>
- <script src="https://kylx365-1253256735.file.myqcloud.com/js/vue.min.js"></script>
- <link rel="stylesheet" href="./mg/common.css">
- <style>
- .main00 {
- width: 100%;
- height: 100vh;
- /* 使用视口高度确保全屏 */
- min-height: 600px;
- /* 设置最小高度 */
- background: white;
- display: flex;
- flex-direction: column;
- }
- .ListTop {
- width: 100%;
- height: 60px;
- background: white;
- border-bottom: 1px solid #EEEEEE;
- justify-content: flex-start;
- }
- .ListTop3 {
- margin-left: 40px;
- height: 50px;
- align-items: center;
- }
- .ListTop4 {
- margin-left: 40px;
- height: 100%;
- }
- .title {
- font-size: 24px;
- color: #333333;
- font-weight: bold;
- }
- .btnNavigation {
- padding: 0 15px;
- height: 100%;
- font-size: 14px;
- color: #666666;
- border-bottom: 2px solid transparent;
- }
- .btnNavigation:hover {
- color: #4A90E2;
- }
- .btnSaveSelect {
- color: #4A90E2;
- border-bottom: 2px solid #4A90E2;
- }
- .main0 {
- width: 100%;
- background: white;
- align-items: flex-start;
- height: calc(100vh - 60px);
- /* 使用视口高度减去标题栏 */
- min-height: 540px;
- /* 600px - 60px */
- overflow: hidden;
- /* 防止内部滚动影响外部 */
- display: flex;
- }
- .school-list {
- width: 400px;
- border-right: 1px solid #EEEEEE;
- background: #F9F9F9;
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- height: calc(100vh - 120px);
- /* 视口高度减去标题栏和搜索框 */
- min-height: 480px;
- /* 600px - 120px */
- position: relative;
- flex-shrink: 0;
- /* 防止flex压缩 */
- }
- .school-list-scrollable {
- flex: 1;
- overflow-y: auto;
- width: 100%;
- }
- .school-detail {
- width: calc(100% - 400px);
- padding: 20px;
- overflow-y: auto;
- }
- .search-box {
- padding: 15px;
- border-bottom: 1px solid #EEEEEE;
- background: white;
- width: 100%;
- }
- .search-input {
- width: 200px;
- height: 32px;
- padding: 0 12px;
- border: 1px solid #DDDDDD;
- border-radius: 4px;
- font-size: 14px;
- color: #333333;
- }
- .search-input:focus {
- border-color: #4A90E2;
- outline: none;
- }
- .btn33 {
- width: 32px;
- height: 32px;
- margin-left: 8px;
- border-radius: 4px;
- background: #F5F5F5;
- }
- .btn33:hover {
- background: #EEEEEE;
- }
- .district-list {
- padding: 0;
- width: 100%;
- align-self: flex-start;
- }
- .district-item {
- margin: 0;
- border-bottom: 1px solid #EEEEEE;
- }
- .district-name {
- font-weight: 500;
- cursor: pointer;
- padding: 12px 15px;
- font-size: 14px;
- color: #333333;
- background: white;
- }
- .district-name:hover {
- background: #F5F5F5;
- }
- .school-item {
- padding: 10px 15px 10px 30px;
- cursor: pointer;
- font-size: 14px;
- color: #666666;
- background: #F9F9F9;
- width: 100%;
- box-sizing: border-box;
- }
- .school-id {
- display: inline-block;
- font-size: 12px;
- color: #666;
- background-color: #f8f8f8;
- padding: 2px 6px;
- border-radius: 3px;
- margin-right: 8px;
- font-family: "Consolas", monospace;
- min-width: 40px;
- text-align: center;
- }
- .school-items {
- width: 100%;
- }
- .school-category {
- width: 100%;
- }
- .category-title {
- padding: 10px 15px 10px 30px;
- font-size: 14px;
- color: #333333;
- background: #F5F5F5;
- border-bottom: 1px solid #EEEEEE;
- border-left: 3px solid #4A90E2;
- font-weight: 600;
- margin-top: 4px;
- }
- .category-schools:empty::before {
- content: '暂无数据';
- display: block;
- padding: 10px 15px 10px 30px;
- color: #999;
- font-size: 14px;
- text-align: left;
- width: 100%;
- box-sizing: border-box;
- background: #F9F9F9;
- }
- .school-items:empty::before {
- content: '暂无数据';
- display: block;
- padding: 15px;
- color: #999;
- font-size: 14px;
- text-align: left;
- width: 100%;
- box-sizing: border-box;
- background: #F9F9F9;
- }
- .school-item:hover {
- background: #F5F5F5;
- color: #333333;
- }
- .school-item.active {
- background: #E6F3FF;
- color: #4A90E2;
- }
- .form-group {
- margin-bottom: 20px;
- }
- .form-label {
- display: block;
- margin-bottom: 8px;
- font-weight: 500;
- font-size: 14px;
- color: #333333;
- }
- .form-input {
- width: 100%;
- height: 36px;
- padding: 0 12px;
- border: 1px solid #DDDDDD;
- border-radius: 4px;
- font-size: 14px;
- color: #333333;
- transition: all 0.3s;
- }
- .form-input:focus {
- border-color: #4A90E2;
- outline: none;
- box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
- }
- .form-select {
- width: 100%;
- height: 36px;
- padding: 0 12px;
- border: 1px solid #DDDDDD;
- border-radius: 4px;
- font-size: 14px;
- color: #333333;
- background: white;
- cursor: pointer;
- transition: all 0.3s;
- }
- .form-select:focus {
- border-color: #4A90E2;
- outline: none;
- box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
- }
- .form-textarea {
- width: 100%;
- padding: 12px;
- border: 1px solid #DDDDDD;
- border-radius: 4px;
- min-height: 120px;
- resize: vertical;
- font-size: 14px;
- color: #333333;
- transition: all 0.3s;
- }
- .form-textarea:focus {
- border-color: #4A90E2;
- outline: none;
- box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
- }
- .btn-group {
- margin-top: 24px;
- text-align: right;
- padding: 0 20px 20px;
- }
- .btn {
- min-width: 30px;
- height: 36px;
- padding: 0 16px;
- margin-left: 12px;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- font-size: 14px;
- transition: all 0.3s;
- }
- .btn-primary {
- background: #4A90E2;
- color: white;
- }
- .btn-primary:hover {
- background: #357ABD;
- }
- .btn-default {
- background: white;
- border: 1px solid #DDDDDD;
- color: #666666;
- }
- .btn-default:hover {
- background: #F5F5F5;
- border-color: #CCCCCC;
- }
- .form-sections {
- display: flex;
- flex-direction: row;
- width: 100%;
- align-items: flex-start;
- }
- .form-column {
- min-width: 0;
- /* 防止flex子项溢出 */
- }
- .form-section {
- border: 1px solid #EEEEEE;
- border-radius: 4px;
- padding: 20px;
- margin-bottom: 24px;
- background: white;
- }
- .form-section-title {
- font-size: 16px;
- font-weight: 500;
- margin-bottom: 20px;
- padding-bottom: 12px;
- border-bottom: 1px solid #EEEEEE;
- color: #333333;
- }
- .form-row {
- display: flex;
- margin: 0 -8px;
- flex-wrap: wrap;
- }
- .form-col {
- flex: 0 0 32%;
- padding: 0 8px;
- box-sizing: border-box;
- }
- .form-col-2 {
- flex: 0 0 63%;
- padding: 0 8px;
- box-sizing: border-box;
- }
- .form-col-3 {
- flex: 0 0 94%;
- padding: 0 8px;
- box-sizing: border-box;
- }
- .form-col-4 {
- flex: 0 0 48%;
- padding: 0 8px;
- box-sizing: border-box;
- }
- .toast {
- position: fixed;
- top: 20px;
- left: 50%;
- transform: translateX(-50%);
- padding: 12px 24px;
- background: rgba(0, 0, 0, 0.7);
- color: white;
- border-radius: 4px;
- z-index: 9999;
- opacity: 0;
- transition: opacity 0.3s;
- }
- .toast.show {
- opacity: 1;
- }
- .toast.success {
- background: #4CAF50;
- }
- .toast.error {
- background: #F44336;
- }
- .toast.info {
- background: #2196F3;
- }
- </style>
- </head>
- <body class="container FlexRow">
- <div id="app" class="main00 FlexColumn">
- <div class="ListTop FlexRow">
- <div class="ListTop3 FlexRow">
- <div class="title CursorPointer">学校信息管理</div>
- </div>
- </div>
- <div class="main0 FlexRow" style="height: calc(100% - 60px);">
- <!-- 左侧学校列表 -->
- <div class="school-list FlexColumn">
- <div class="search-box FlexRow">
- <input type="text" class="search-input" v-model="searchText" @input="debounceSearch"
- @keyup.enter="searchSchools" placeholder="输入学校名称搜索...">
- <div class="btn33 btn31 btn FlexRow" @click="searchSchools">
- <img title="搜索" alt="搜索"
- src="https://kylx365-1253256735.file.myqcloud.com/web/universalpic_search_gray_30x30.png"
- style="width: 20px; height: 20px;" />
- </div>
- </div>
- <div class="school-list-scrollable">
- <div class="district-list">
- <div class="district-item" v-for="district in districts">
- <div class="district-name FlexRow" @click="toggleDistrict(district)">
- <div class="flex-1">{{ district.id }} {{ district.name }} <template v-if="district.count">({{
- district.count
- }})</template></div>
- <div class="district-icon">
- </div>
- </div>
- <transition name="slide">
- <div v-show="district.isOpen" class="school-items">
- <!-- 高中部分 -->
- <div class="school-category"
- v-if="district.highSchools && district.highSchools.length > 0">
- <div class="category-title">高中</div>
- <div class="category-schools">
- <div class="school-item" v-for="school in district.highSchools"
- :class="{ active: selectedSchool && selectedSchool.ID === school.ID }"
- @click="selectSchool(school)">
- <span class="school-id">{{ school.ID }}</span>
- {{ school.SchoolFullName }}
- </div>
- </div>
- </div>
- <!-- 初中部分 -->
- <div class="school-category"
- v-if="district.middleSchools && district.middleSchools.length > 0">
- <div class="category-title">初中</div>
- <div class="category-schools">
- <div class="school-item" v-for="school in district.middleSchools"
- :class="{ active: selectedSchool && selectedSchool.ID === school.ID }"
- @click="selectSchool(school)">
- <span class="school-id">{{ school.ID }}</span>
- {{ school.SchoolFullName }}
- </div>
- </div>
- </div>
- </div>
- </transition>
- </div>
- </div>
- </div>
- </div>
- <!-- 右侧学校详情 -->
- <div class="school-detail FlexColumn" v-if="!selectedSchool"></div>
- <div class="school-detail FlexColumn" v-if="selectedSchool">
- <form @submit.prevent="saveSchool">
- <!-- 基本信息 -->
- <div class="form-sections FlexRow" style="margin: 0 -12px;">
- <!-- 第一列 -->
- <div class="form-column" style="flex: 1; padding: 0 12px;">
- <div class="form-section">
- <div class="form-section-title">基本信息</div>
- <div class="form-row">
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">学校ID</label>
- <input type="text" class="form-input" v-model="selectedSchool.ID" readonly>
- </div>
- </div>
- <div class="form-col-2">
- <div class="form-group">
- <label class="form-label">学校全称</label>
- <input type="text" class="form-input"
- v-model="selectedSchool.SchoolFullName">
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">学校简称</label>
- <input type="text" class="form-input"
- v-model="selectedSchool.SchoolShortName">
- </div>
- </div>
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">其他名称</label>
- <input type="text" class="form-input"
- v-model="selectedSchool.SchoolOtherName">
- </div>
- </div>
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">招生代码</label>
- <input type="text" class="form-input" v-model="selectedSchool.SchoolNumber">
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">拼音首字母</label>
- <input type="text" class="form-input" v-model="selectedSchool.Pinyin">
- </div>
- </div>
- <div class="form-col-2">
- <div class="form-group">
- <label class="form-label">有初高中同名(对应ID)</label>
- <input type="text" class="form-input" v-model="selectedSchool.HasSameName">
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">住宿情况</label>
- <select class="form-select" v-model="selectedSchool.Accommodation">
- <option value="">未知</option>
- <option value="全部寄宿">全部寄宿</option>
- <option value="部分寄宿">部分寄宿</option>
- <option value="无寄宿">无寄宿</option>
- </select>
- </div>
- </div>
- <div class="form-col-2">
- <div class="form-group">
- <label class="form-label">住宿情况说明</label>
- <input type="text" class="form-input"
- v-model="selectedSchool.AccommodationRemark">
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col-3">
- <div class="form-group">
- <label class="form-label">收费标准</label>
- <textarea class="form-textarea" v-model="selectedSchool.Fees"></textarea>
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">学校类型</label>
- <input type="text" class="form-input" v-model="selectedSchool.SchoolType1"
- readonly>
- </div>
- </div>
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">学校性质</label>
- <select class="form-select" v-model="selectedSchool.PublicOrPrivate">
- <option value="">未知</option>
- <option value="公办">公办</option>
- <option value="民办">民办</option>
- <option value="中外合作">中外合作</option>
- </select>
- </div>
- </div>
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">详细类型</label>
- <input type="text" class="form-input" v-model="selectedSchool.SchoolType2"
- readonly>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- 第二列 -->
- <div class="form-column" style="flex: 1; padding: 0 12px;">
- <!-- 地理信息 -->
- <div class="form-section">
- <div class="form-section-title">地理信息</div>
- <div class="form-row">
- <div class="form-col">
- <div class="form-group">
- <label class="form-label">所属区</label>
- <input type="text" class="form-input" v-model="selectedSchool.District"
- readonly>
- </div>
- </div>
- <div class="form-col-2">
- <div class="form-group">
- <label class="form-label">经纬度坐标</label>
- <input type="text" class="form-input" v-model="selectedSchool.Coordinates">
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col-3">
- <div class="form-group">
- <label class="form-label">详细地址</label>
- <input type="text" class="form-input" v-model="selectedSchool.Address">
- </div>
- </div>
- </div>
- </div>
- <!-- 联系信息 -->
- <div class="form-section">
- <div class="form-section-title">联系信息</div>
- <div class="form-row">
- <div class="form-col-4">
- <div class="form-group">
- <label class="form-label">招生电话(逗号分隔)</label>
- <input type="text" class="form-input" v-model="selectedSchool.Phone1">
- </div>
- </div>
- <div class="form-col-4">
- <div class="form-group">
- <label class="form-label">招生电话(国际课程班)</label>
- <input type="text" class="form-input" v-model="selectedSchool.Phone2">
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col-3">
- <div class="form-group">
- <label class="form-label">学校网址</label>
- <input type="text" class="form-input" v-model="selectedSchool.Website">
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col-3">
- <div class="form-group">
- <label class="form-label">联系时间</label>
- <input type="text" class="form-input" v-model="selectedSchool.ContactTime">
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- 第三列 -->
- <div class="form-column" style="flex: 1; padding: 0 12px;">
- <!-- 其他信息 -->
- <div class="form-section">
- <div class="form-section-title">其他信息</div>
- <div class="form-row">
- <div class="form-col-3">
- <div class="form-group">
- <label class="form-label">学校简介</label>
- <textarea class="form-textarea"
- v-model="selectedSchool.Introduction"></textarea>
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col-3">
- <div class="form-group">
- <label class="form-label">美育特色介绍</label>
- <textarea class="form-textarea"
- v-model="selectedSchool.Introduction2"></textarea>
- </div>
- </div>
- </div>
- <div class="form-row">
- <div class="form-col-3">
- <div class="form-group">
- <label class="form-label">备注</label>
- <textarea class="form-textarea" v-model="selectedSchool.Remark"></textarea>
- </div>
- </div>
- </div>
- </div>
- <div class="btn-group">
- <button type="button" class="btn btn-default" @click="resetForm">重置表单</button>
- <button type="submit" class="btn btn-primary">保存</button>
- </div>
- </form>
- </div>
- </div>
- <div class="toast" :class="{ show: showToastFlag, [toastType]: showToastFlag }">{{ toastMessage }}</div>
- <script>
- // 区域数据
- const arrDistrict = [{
- ID: "01",
- Name: "黄浦区",
- Count: ""
- },
- {
- ID: "02",
- Name: "徐汇区",
- Count: ""
- },
- {
- ID: "03",
- Name: "长宁区",
- Count: ""
- },
- {
- ID: "04",
- Name: "静安区",
- Count: ""
- },
- {
- ID: "05",
- Name: "普陀区",
- Count: ""
- },
- {
- ID: "06",
- Name: "虹口区",
- Count: ""
- },
- {
- ID: "07",
- Name: "杨浦区",
- Count: ""
- },
- {
- ID: "08",
- Name: "闵行区",
- Count: ""
- },
- {
- ID: "09",
- Name: "宝山区",
- Count: ""
- },
- {
- ID: "10",
- Name: "嘉定区",
- Count: ""
- },
- {
- ID: "11",
- Name: "浦东新区",
- Count: ""
- },
- {
- ID: "12",
- Name: "金山区",
- Count: ""
- },
- {
- ID: "13",
- Name: "松江区",
- Count: ""
- },
- {
- ID: "14",
- Name: "青浦区",
- Count: ""
- },
- {
- ID: "15",
- Name: "奉贤区",
- Count: ""
- },
- {
- ID: "16",
- Name: "崇明区",
- Count: ""
- }];
- new Vue({
- el: '#app',
- data: {
- searchText: '',
- districts: [],
- selectedSchool: null,
- originalSchool: null,
- searchTimeout: null,
- districtID: '',
- arrDistrict: arrDistrict,
- toastMessage: '',
- toastType: 'info',
- showToastFlag: false
- },
- methods: {
- // 搜索学校
- searchSchools() {
- // 如果搜索框为空,恢复所有学校显示
- if (!this.searchText.trim()) {
- this.loadDistricts();
- return;
- }
- const keyword = this.searchText.trim();
- // 使用提供的接口搜索学校
- fetch(`/api/GetMPSSchool?RowCount=100&Key=${keyword}`)
- .then(response => response.json())
- .then(data => {
- data = data.result;
- if (data && data.length > 0) {
- // 将搜索结果按区域分组
- const districtMap = {};
- data.forEach(school => {
- if (!districtMap[school.District]) {
- districtMap[school.District] = {
- id: school.DistrictID,
- name: school.District,
- count: 0,
- schools: [],
- highSchools: [],
- middleSchools: [],
- isOpen: true
- };
- }
- districtMap[school.District].schools.push(school);
- // 按学校类型分类
- if (school.SchoolType1 === '高中' || school.SchoolType2?.includes('高中')) {
- districtMap[school.District].highSchools.push(school);
- } else if (school.SchoolType1 === '初中' ||
- (school.SchoolType2 === '初中' && !school.SchoolType2?.includes('高中'))) {
- districtMap[school.District].middleSchools.push(school);
- }
- districtMap[school.District].count = districtMap[school.District].schools.length;
- });
- this.districts = Object.values(districtMap);
- } else {
- this.showToast('未找到匹配的学校', 'info');
- }
- })
- .catch(error => {
- console.error('搜索学校时出错:', error);
- alert('搜索失败,请稍后重试');
- });
- },
- // 防抖搜索
- debounceSearch() {
- if (this.searchTimeout) {
- clearTimeout(this.searchTimeout);
- }
- this.searchTimeout = setTimeout(() => {
- this.searchSchools();
- }, 500);
- },
- // 切换区域展开/折叠状态
- toggleDistrict(district) {
- // 如果展开且该区域下还没有加载学校数据,则加载
- if (!district.schools || district.schools.length === 0) {
- this.loadSchoolsByDistrict(district);
- }
- else {
- district.isOpen = !district.isOpen;
- }
- },
- // 加载特定区域下的学校
- loadSchoolsByDistrict(district) {
- fetch(`/api/GetMPSSchool?Usage=web&DistrictID=${district.id}`)
- .then(response => response.json())
- .then(data => {
- data = data.result;
- if (data && data.length > 0) {
- // 将学校按类型分类
- district.highSchools = data.filter(school =>
- school.SchoolType1 === '高中' ||
- school.SchoolType2?.includes('高中')
- );
- district.middleSchools = data.filter(school =>
- school.SchoolType1 === '初中' ||
- (school.SchoolType2 === '初中' && !school.SchoolType2?.includes('高中'))
- );
- // 保持原有的schools数组,以保持兼容性
- district.schools = data;
- } else {
- district.highSchools = [];
- district.middleSchools = [];
- district.schools = [];
- }
- district.isOpen = !district.isOpen;
- district.count = data.length
- })
- .catch(error => {
- console.error(`加载${district.name}区域学校数据时出错:`, error);
- district.highSchools = [];
- district.middleSchools = [];
- district.schools = [];
- });
- },
- // 选择学校
- selectSchool(school) {
- // 如果已经选择了该学校,不需要重新加载
- if (this.selectedSchool && this.selectedSchool.ID === school.ID) {
- return;
- }
- // 显示加载状态
- this.selectedSchool = { ...school, loading: true };
- // 调用API获取详细的学校信息
- fetch(`/api/GetMPSSchoolInfo?Usage=web&SchoolID=${school.ID}`)
- .then(response => response.json())
- .then(data => {
- if (data && data.result) {
- // 处理API返回的数据
- const schoolData = { ...data.result };
- // 处理详细类型(SchoolType2)
- const validSchoolTypes = [
- "",
- "市实验性示范性高中",
- "享受市实验性示范性高中招生政策高中",
- "区实验性示范性高中 (市特色普通高中)",
- "区实验性示范性高中",
- "一般高中"
- ];
- // 如果SchoolType2不在有效选项中,设置为未知
- if (!validSchoolTypes.includes(schoolData.SchoolType2)) {
- schoolData.SchoolType2 = ""; // 设置为未知
- }
- // 处理学校性质(PublicOrPrivate)
- const validPublicOrPrivate = ["", "公办", "民办", "中外合作"];
- if (!validPublicOrPrivate.includes(schoolData.PublicOrPrivate)) {
- schoolData.PublicOrPrivate = ""; // 如果值无效,设置为"未知"
- }
- // 处理住宿情况(Accommodation)
- const validAccommodations = ["", "全部寄宿", "部分寄宿", "无寄宿"];
- if (!validAccommodations.includes(schoolData.Accommodation)) {
- schoolData.Accommodation = ""; // 如果值无效,设置为"未知"
- }
- this.selectedSchool = schoolData;
- this.originalSchool = { ...schoolData };
- } else {
- // 如果API没有返回有效数据,则使用列表中的基本信息,并设置默认值
- const schoolData = { ...school };
- // 处理详细类型,如果不是有效值则设为"未知"
- const validSchoolTypes = [
- "",
- "市实验性示范性高中",
- "享受市实验性示范性高中招生政策高中",
- "区实验性示范性高中 (市特色普通高中)",
- "区实验性示范性高中",
- "一般高中"
- ];
- schoolData.SchoolType2 = validSchoolTypes.includes(schoolData.SchoolType2) ?
- schoolData.SchoolType2 : "";
- // 处理住宿情况,如果不是有效值则设为"未知"
- const validAccommodations = ["", "全部寄宿", "部分寄宿", "无寄宿"];
- schoolData.Accommodation = validAccommodations.includes(schoolData.Accommodation) ?
- schoolData.Accommodation : "";
- this.selectedSchool = schoolData;
- this.originalSchool = { ...schoolData };
- console.warn('未能获取到学校详细信息,使用基本信息显示');
- }
- })
- .catch(error => {
- console.error('获取学校详细信息时出错:', error);
- // 出错时使用列表中的基本信息
- this.selectedSchool = { ...school };
- this.originalSchool = { ...school };
- this.showToast('获取学校详细信息失败,请稍后重试', 'error');
- });
- },
- // 显示Toast通知
- showToast(message, type = 'info') {
- this.toastMessage = message;
- this.toastType = type;
- this.showToastFlag = true;
- // 自动隐藏
- setTimeout(() => {
- this.showToastFlag = false;
- }, 3000);
- },
- // 保存学校信息
- saveSchool() {
- if (!this.selectedSchool || !this.originalSchool) return;
- // 只收集修改过的字段
- const changedFields = {};
- const fieldsToCheck = [
- 'SchoolFullName', 'SchoolShortName', 'SchoolOtherName', 'SchoolNumber',
- 'Pinyin', 'HasSameName', 'Accommodation', 'AccommodationRemark',
- 'Fees', 'SchoolType1', 'PublicOrPrivate', 'SchoolType2',
- 'Coordinates', 'Address', 'Phone1', 'Phone2',
- 'Website', 'ContactTime', 'Introduction', 'Introduction2', 'Remark'
- ];
- fieldsToCheck.forEach(field => {
- if (this.selectedSchool[field] !== this.originalSchool[field]) {
- changedFields[field] = this.selectedSchool[field];
- }
- });
- // 确保ID字段始终包含
- changedFields.ID = this.selectedSchool.ID;
- // 如果没有字段被修改,不提交
- if (Object.keys(changedFields).length <= 1) {
- this.showToast('没有修改任何内容', 'info');
- return;
- }
- // 提交修改过的字段
- fetch('/api/SaveMPSSchool', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(changedFields)
- })
- .then(response => response.json())
- .then(data => {
- if (data && data.errcode == 10000) {
- this.showToast('保存成功', 'success');
- this.originalSchool = { ...this.selectedSchool };
- // 更新列表中的学校名称
- this.districts.forEach(district => {
- // 更新schools数组中的学校名称
- if (district.schools) {
- district.schools.forEach(school => {
- if (school.ID === this.selectedSchool.ID) {
- school.SchoolFullName = this.selectedSchool.SchoolFullName;
- }
- });
- }
- // 更新highSchools数组中的学校名称
- if (district.highSchools) {
- district.highSchools.forEach(school => {
- if (school.ID === this.selectedSchool.ID) {
- school.SchoolFullName = this.selectedSchool.SchoolFullName;
- }
- });
- }
- // 更新middleSchools数组中的学校名称
- if (district.middleSchools) {
- district.middleSchools.forEach(school => {
- if (school.ID === this.selectedSchool.ID) {
- school.SchoolFullName = this.selectedSchool.SchoolFullName;
- }
- });
- }
- });
- console.log('学校信息更新完成');
- } else {
- alert('保存失败,请稍后重试');
- }
- })
- .catch(error => {
- console.error('保存学校信息时出错:', error);
- alert('保存失败,请稍后重试');
- });
- },
- // 重置表单
- resetForm() {
- if (this.originalSchool) {
- this.selectedSchool = { ...this.originalSchool };
- }
- },
- // 加载所有区域
- loadDistricts() {
- // 直接使用arrDistrict数据
- this.districts = arrDistrict.map(district => ({
- id: district.ID,
- name: district.Name,
- count: district.Count,
- isOpen: false,
- schools: [] // 初始为空,点击展开时加载
- }));
- }
- },
- mounted() {
- // 初始化加载区域数据
- this.loadDistricts();
- }
- });
- </script>
- </body>
- </html>
|