import { ref, onMounted, onUnmounted } from 'vue'; import StepLayout from '../../components/step-layout/step-layout.vue'; import { getStudent } from '../../api/student'; import { delStudentEducation } from '../../api/studentEducation'; import { delStudentExperience } from '../../api/studentExperience'; import { delStudentProject } from '../../api/studentProject'; export default { components: { StepLayout }, setup() { const educationList = ref([]); const workList = ref([]); const projectList = ref([]); const isEditMode = ref(false); const loadData = async () => { const userInfo = uni.getStorageSync('userInfo'); const studentId = userInfo ? userInfo.studentId : null; if (!studentId) return; try { const res = await getStudent(studentId); if (res.code === 200 && res.data) { educationList.value = res.data.educationList || []; workList.value = res.data.experienceList || []; projectList.value = res.data.projectList || []; } } catch (err) { console.error('加载经历失败', err); } }; onMounted(() => { const options = getCurrentPages()[getCurrentPages().length - 1].options; if (options && options.editMode === '1') { isEditMode.value = true; } loadData(); uni.$on('refresh_experience', () => { loadData(); }); }); onUnmounted(() => { uni.$off('refresh_experience'); }); const showModal = ref(false); const modalContent = ref(''); let currentDeleteType = ''; let currentDeleteId = null; const openModal = (type, content, id) => { currentDeleteType = type; modalContent.value = content; currentDeleteId = id; showModal.value = true; }; const closeModal = () => { showModal.value = false; }; const confirmDelete = async () => { uni.showLoading({ title: '删除中...' }); try { if (currentDeleteType === 'education') { await delStudentEducation(currentDeleteId); } else if (currentDeleteType === 'work') { await delStudentExperience(currentDeleteId); } else if (currentDeleteType === 'project') { await delStudentProject(currentDeleteId); } uni.showToast({ title: '删除成功', icon: 'success' }); loadData(); } catch (err) { uni.showToast({ title: '删除失败', icon: 'none' }); } finally { closeModal(); uni.hideLoading(); } }; const addEducation = () => { uni.navigateTo({ url: '/pages/experience/add-education' }); }; const editEducation = (i) => { uni.setStorageSync('edit_data_education', educationList.value[i]); uni.navigateTo({ url: '/pages/experience/add-education?index=' + i }); }; const deleteEducation = (i) => { openModal('education', '确定要删除这段教育经历吗?', educationList.value[i].id); }; const addWork = () => { uni.navigateTo({ url: '/pages/experience/add-work' }); }; const editWork = (i) => { uni.setStorageSync('edit_data_work', workList.value[i]); uni.navigateTo({ url: '/pages/experience/add-work?index=' + i }); }; const deleteWork = (i) => { openModal('work', '确定要删除这段工作经历吗?', workList.value[i].id); }; const addProject = () => { uni.navigateTo({ url: '/pages/experience/add-project' }); }; const editProject = (i) => { uni.setStorageSync('edit_data_project', projectList.value[i]); uni.navigateTo({ url: '/pages/experience/add-project?index=' + i }); }; const deleteProject = (i) => { openModal('project', '确定要删除这段项目经历吗?', projectList.value[i].id); }; const goNext = () => { const url = isEditMode.value ? '/pages/intention/intention?editMode=1' : '/pages/intention/intention'; uni.navigateTo({ url }); }; const goSkip = () => { const url = isEditMode.value ? '/pages/intention/intention?editMode=1' : '/pages/intention/intention'; uni.navigateTo({ url }); }; return { educationList, workList, projectList, showModal, modalContent, closeModal, confirmDelete, addEducation, editEducation, deleteEducation, addWork, editWork, deleteWork, addProject, editProject, deleteProject, goNext, goSkip, isEditMode }; } }