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

college picker - init

abpcoder 1 hete
szülő
commit
b5cb0c9591

+ 4 - 0
src/common/routes.ts

@@ -27,6 +27,10 @@ export const routes = {
    * 大学详情
    */
   universityDetail: '/pagesOther/pages/university/detail/detail',
+  /*
+  * 院校选择
+  * */
+  universityPicker: '/pagesOther/pages/university/picker/picker',
   /**
    * 职业库
    */

+ 7 - 0
src/pages.json

@@ -128,6 +128,13 @@
           "style": {
             "navigationBarTitleText": ""
           }
+        },
+        {
+          "path": "pages/university/picker/picker",
+          "style": {
+            "navigationBarTitleText": "",
+            "enablePullDownRefresh": true
+          }
         }
       ]
     },

+ 2 - 0
src/pagesOther/pages/university/index/components/college-list.vue

@@ -2,6 +2,7 @@
     <view class="h-full">
         <z-paging ref="paging" v-model="list" @query="handleQuery">
             <template #top>
+                <slot name="top"/>
                 <college-conditions-picker :options="filter"/>
                 <ie-search v-model="queryParams.name" placeholder="输入院校名称" @search="handleSearch"
                            @clear="handleSearch"/>
@@ -74,6 +75,7 @@ watch([
 
 onMounted(async () => {
     const {data} = await getUniversityFilters()
+    filter.value = data
 })
 
 </script>

+ 27 - 0
src/pagesOther/pages/university/picker/picker.vue

@@ -0,0 +1,27 @@
+<template>
+    <ie-page>
+        <college-list custom-item-click @item-click="handleItemClick">
+            <template #top>
+                <ie-navbar :title="title"/>
+            </template>
+        </college-list>
+    </ie-page>
+</template>
+
+<script setup lang="ts">
+import {Transfer} from "@/types";
+import {useTransferPage} from "@/hooks/useTransferPage";
+import CollegeList from "@/pagesOther/pages/university/index/components/college-list.vue";
+import {University} from "@/types/university";
+
+const {prevData, transferBack} = useTransferPage<Transfer.UniversityPickerPageOptions, {}>()
+const title = computed(() => prevData.value.title || '选择院校')
+
+const handleItemClick = (college: University) => {
+    transferBack(college)
+}
+</script>
+
+<style lang="scss">
+
+</style>

+ 154 - 142
src/pagesStudy/pages/targeted-add/targeted-add.vue

@@ -1,182 +1,194 @@
 <template>
-  <ie-page bg-color="#F6F8FA" :fix-height="true">
-    <ie-navbar title="添加定向院校" />
-    <view class="mt-16 bg-white py-10">
-      <view class="">
-        <uv-cell-group :border="false">
-          <uv-cell isLink :border="true" :cellStyle="cellStyle" :rightIconStyle="rightIconStyle"
-            @click="handleUniversitySelect">
-            <template #title>
-              <text class="text-30 text-fore-subtitle">选择院校</text>
-            </template>
-            <template #value>
-              <text v-if="form.universityName" class="mr-10 text-30 text-fore-title">{{ form.universityName }}</text>
-              <text v-else class="mr-10 text-30 text-fore-placeholder">请选择</text>
-            </template>
-          </uv-cell>
-          <uv-cell isLink :border="false" :cellStyle="cellStyle" :rightIconStyle="rightIconStyle"
-            @click="handleMajorSelect">
-            <template #title>
-              <text class="text-30 text-fore-subtitle">选择专业</text>
-            </template>
-            <template #value>
-              <text v-if="form.majorName" class="mr-10 text-30 text-fore-title">{{ form.majorName }}</text>
-              <text v-else class="mr-10 text-30 text-fore-placeholder">请选择</text>
-            </template>
-          </uv-cell>
-        </uv-cell-group>
-      </view>
-    </view>
-    <ie-safe-toolbar :height="84" :shadow="false">
-      <view class="px-46 pt-24">
-        <ie-button type="primary" @click="handleAdd">确认</ie-button>
-      </view>
-    </ie-safe-toolbar>
-  </ie-page>
-  <ie-popup ref="popupRef" title="选择专业" @confirm="handleConfirm">
-    <view class="h-[50vh] bg-white px-30 pt-20 flex flex-col">
-      <view>
-        <uv-search v-model="keyword" shape="square" :showAction="false" placeholder="请输入专业名称" />
-      </view>
-      <view class="mt-20 flex-1 min-h-1">
-        <scroll-view scroll-y class="h-full">
-          <view v-for="item in filteredMajorList" :key="item.id"
-            class="px-20 py-16 bg-white sibling-border-top flex items-center gap-x-20" @click="handleSelect(item)">
-            <view class="flex-1 min-w-1 flex-shrink-0">
-              <view class="flex items-center gap-x-10 text-fore-title">
-                <span class="text-30 " :class="[isActive(item) ? 'text-primary' : 'text-fore-title']">{{ item.name }}</span>
-                <span v-if="item.notice" class="text-22 text-fore-light flex-1 min-w-1 ellipsis-1"  :class="[isActive(item) ? 'text-primary' : 'text-fore-title']">{{ `(${item.notice})` }}</span>
-              </view>
-              <view class="mt-6 text-22 text-fore-light" :class="[isActive(item) ? 'text-primary' : 'text-fore-light']">
-                {{
-                  item.ancestors }}</view>
+    <ie-page bg-color="#F6F8FA" :fix-height="true">
+        <ie-navbar title="添加定向院校"/>
+        <view class="mt-16 bg-white py-10">
+            <view class="">
+                <uv-cell-group :border="false">
+                    <uv-cell isLink :border="true" :cellStyle="cellStyle" :rightIconStyle="rightIconStyle"
+                             @click="handleUniversitySelect">
+                        <template #title>
+                            <text class="text-30 text-fore-subtitle">选择院校</text>
+                        </template>
+                        <template #value>
+                            <text v-if="form.universityName" class="mx-10 text-30 text-fore-title">
+                                {{ form.universityName }}
+                            </text>
+                            <text v-else class="mr-10 text-30 text-nowrap text-fore-placeholder">请选择</text>
+                        </template>
+                    </uv-cell>
+                    <uv-cell isLink :border="false" :cellStyle="cellStyle" :rightIconStyle="rightIconStyle"
+                             @click="handleMajorSelect">
+                        <template #title>
+                            <text class="text-30 text-fore-subtitle text-nowrap">选择专业</text>
+                        </template>
+                        <template #value>
+                            <text v-if="form.majorName" class="mx-10 text-30 text-fore-title">{{
+                                    form.majorName
+                                }}
+                            </text>
+                            <text v-else class="mr-10 text-30 text-fore-placeholder">请选择</text>
+                        </template>
+                    </uv-cell>
+                </uv-cell-group>
             </view>
-            <uv-icon v-if="isActive(item)" name="checkmark" size="20" color="#31A0FC" />
-          </view>
-        </scroll-view>
-      </view>
-    </view>
-  </ie-popup>
+        </view>
+        <ie-safe-toolbar :height="84" :shadow="false">
+            <view class="px-46 pt-24">
+                <ie-button type="primary" @click="handleAdd">确认</ie-button>
+            </view>
+        </ie-safe-toolbar>
+    </ie-page>
+    <ie-popup ref="popupRef" title="选择专业" @confirm="handleConfirm">
+        <view class="h-[50vh] bg-white px-30 pt-20 flex flex-col">
+            <view>
+                <uv-search v-model="keyword" shape="square" :showAction="false" placeholder="请输入专业名称"/>
+            </view>
+            <view class="mt-20 flex-1 min-h-1">
+                <scroll-view scroll-y class="h-full">
+                    <view v-for="item in filteredMajorList" :key="item.id"
+                          class="px-20 py-16 bg-white sibling-border-top flex items-center gap-x-20"
+                          @click="handleSelect(item)">
+                        <view class="flex-1 min-w-1 flex-shrink-0">
+                            <view class="flex items-center gap-x-10 text-fore-title">
+                                <span class="text-30 " :class="[isActive(item) ? 'text-primary' : 'text-fore-title']">{{
+                                        item.name
+                                    }}</span>
+                                <span v-if="item.notice" class="text-22 text-fore-light flex-1 min-w-1 ellipsis-1"
+                                      :class="[isActive(item) ? 'text-primary' : 'text-fore-title']">{{
+                                        `(${item.notice})`
+                                    }}</span>
+                            </view>
+                            <view class="mt-6 text-22 text-fore-light"
+                                  :class="[isActive(item) ? 'text-primary' : 'text-fore-light']">
+                                {{
+                                    item.ancestors
+                                }}
+                            </view>
+                        </view>
+                        <uv-icon v-if="isActive(item)" name="checkmark" size="20" color="#31A0FC"/>
+                    </view>
+                </scroll-view>
+            </view>
+        </view>
+    </ie-popup>
 </template>
 
 <script lang="ts" setup>
-import { useTransferPage } from '@/hooks/useTransferPage';
-import { DirectedSchool, SelectedUniversityMajor, University, UniversityMajor } from '@/types/study';
-import { getUniversityMajorList } from '@/api/modules/university';
-import { useUserStore } from '@/store/userStore';
+import {useTransferPage} from '@/hooks/useTransferPage';
+import {DirectedSchool, SelectedUniversityMajor, University, UniversityMajor} from '@/types/study';
+import {getUniversityMajorList} from '@/api/modules/university';
+import {useUserStore} from '@/store/userStore';
+import {routes} from "@/common/routes";
+
 const userStore = useUserStore();
-const { transferTo } = useTransferPage();
-const { hasDirectedSchool, directedSchoolList } = toRefs(userStore);
+const {transferTo} = useTransferPage();
+const {directedSchoolList} = toRefs(userStore);
 const form = ref<Partial<SelectedUniversityMajor>>({});
 const keyword = ref('');
 const cellStyle = {
-  padding: '20rpx 40rpx'
+    padding: '20rpx 40rpx'
 }
 const rightIconStyle = {
-  fontSize: '14px'
+    fontSize: '14px'
 }
 const majorList = ref<UniversityMajor[]>([]);
 const filteredMajorList = computed(() => {
-  return majorList.value.filter(item => item.name.includes(keyword.value));
+    return majorList.value.filter(item => item.name.includes(keyword.value));
 });
 const handleUniversitySelect = () => {
-  transferTo('/pagesOther/pages/college-library/picker/picker', {
-    data: {
-      transferType: 'v2'
-    }
-  }).then((res: any) => {
-    if (res) {
-      const university = res as University;
-      if (university.code !== form.value.universityId) {
-        selectedMajor.value = null;
-        form.value.majorId = '';
-        form.value.majorName = '';
-      }
-      form.value.universityId = university.code;
-      form.value.universityName = university.name;
-      form.value.universityLogo = university.logo;
-      loadMajorList(university.code);
-    }
-  });
+    transferTo(routes.universityPicker).then((res: any) => {
+        if (res) {
+            const university = res as University;
+            if (university.code !== form.value.universityId) {
+                selectedMajor.value = null;
+                form.value.majorId = '';
+                form.value.majorName = '';
+            }
+            form.value.universityId = university.code;
+            form.value.universityName = university.name;
+            form.value.universityLogo = university.logo;
+            loadMajorList(university.code);
+        }
+    });
 }
 
 const popupRef = ref();
 const selectedMajor = ref<Pick<UniversityMajor, 'ancestors' | 'code' | 'id' | 'name'> | null>(null);
 const handleMajorSelect = () => {
-  if (!form.value.universityId) {
-    uni.$ie.showToast('请选择院校');
-    return;
-  }
-  keyword.value = '';
-  if (form.value.majorId) {
-    selectedMajor.value = {
-      ancestors: form.value.majorAncestors || '',
-      code: form.value.majorId || '',
-      id: Number(form.value.majorId),
-      name: form.value.majorName || ''
+    if (!form.value.universityId) {
+        uni.$ie.showToast('请选择院校');
+        return;
     }
-  } else {
-    selectedMajor.value = null;
-  }
-  popupRef.value.open();
+    keyword.value = '';
+    if (form.value.majorId) {
+        selectedMajor.value = {
+            ancestors: form.value.majorAncestors || '',
+            code: form.value.majorId || '',
+            id: Number(form.value.majorId),
+            name: form.value.majorName || ''
+        }
+    } else {
+        selectedMajor.value = null;
+    }
+    popupRef.value.open();
 }
 
 const handleConfirm = () => {
-  if (!selectedMajor.value) {
-    uni.$ie.showToast('请选择专业');
-    return;
-  }
-  form.value.majorAncestors = selectedMajor.value.ancestors;
-  form.value.majorId = selectedMajor.value.id.toString();
-  form.value.majorName = selectedMajor.value.name;
-  popupRef.value.close();
+    if (!selectedMajor.value) {
+        uni.$ie.showToast('请选择专业');
+        return;
+    }
+    form.value.majorAncestors = selectedMajor.value.ancestors;
+    form.value.majorId = selectedMajor.value.id.toString();
+    form.value.majorName = selectedMajor.value.name;
+    popupRef.value.close();
 }
 const handleSelect = (item: UniversityMajor) => {
-  selectedMajor.value = item;
+    selectedMajor.value = item;
 }
 
 const handleAdd = async () => {
-  if (!form.value.universityId) {
-    uni.$ie.showToast('请选择院校');
-    return;
-  }
-  if (!form.value.majorId) {
-    uni.$ie.showToast('请选择专业');
-    return;
-  }
-  // 检查数据是否已存在
-  const historyData = directedSchoolList.value;
-  const isExist = historyData.some(item => item.universityId === form.value.universityId && item.majorId === form.value.majorId);
-  if (isExist) {
-    uni.$ie.showToast('该院校专业已存在');
-    return;
-  }
-  uni.$ie.showLoading();
-  const params = {
-    ...form.value,
-    code: form.value.universityId
-  } as DirectedSchool;
-  await userStore.saveDirectedSchoolList([params, ...directedSchoolList.value]);
-  uni.$ie.hideLoading();
-  uni.$ie.showSuccess('保存成功');
-  setTimeout(() => {
-    transferTo('/pagesStudy/pages/targeted-setting/targeted-setting', {
-      type: 'redirectTo'
-    });
-  }, 600);
+    if (!form.value.universityId) {
+        uni.$ie.showToast('请选择院校');
+        return;
+    }
+    if (!form.value.majorId) {
+        uni.$ie.showToast('请选择专业');
+        return;
+    }
+    // 检查数据是否已存在
+    const historyData = directedSchoolList.value;
+    const isExist = historyData.some(item => item.universityId === form.value.universityId && item.majorId === form.value.majorId);
+    if (isExist) {
+        uni.$ie.showToast('该院校专业已存在');
+        return;
+    }
+    uni.$ie.showLoading();
+    const params = {
+        ...form.value,
+        code: form.value.universityId
+    } as DirectedSchool;
+    await userStore.saveDirectedSchoolList([params, ...directedSchoolList.value]);
+    uni.$ie.hideLoading();
+    uni.$ie.showSuccess('保存成功');
+    setTimeout(() => {
+        transferTo('/pagesStudy/pages/targeted-setting/targeted-setting', {
+            type: 'redirectTo'
+        });
+    }, 600);
 }
 const isActive = (item: UniversityMajor) => {
-  return selectedMajor.value && selectedMajor.value.id === item.id;
+    return selectedMajor.value && selectedMajor.value.id === item.id;
 }
 const loadMajorList = async (universityId: string) => {
-  uni.$ie.showLoading();
-  const { data } = await getUniversityMajorList({ universityId });
-  majorList.value = data;
-  uni.$ie.hideLoading();
+    uni.$ie.showLoading();
+    const {data} = await getUniversityMajorList({universityId});
+    majorList.value = data;
+    uni.$ie.hideLoading();
 }
 
 onLoad(() => {
-  handleUniversitySelect();
+    handleUniversitySelect();
 });
 </script>
 

+ 4 - 0
src/types/transfer.ts

@@ -40,4 +40,8 @@ export interface ExamAnalysisPageOptions {
 export interface SimulationAnalysisPageOptions {
   examineeId: number;
   paperType: EnumPaperType;
+}
+
+export interface UniversityPickerPageOptions {
+  title?: string;
 }