experience.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { ref, onMounted, onUnmounted } from 'vue';
  2. import StepLayout from '../../components/step-layout/step-layout.vue';
  3. import { getStudent } from '../../api/student';
  4. import { delStudentEducation } from '../../api/studentEducation';
  5. import { delStudentExperience } from '../../api/studentExperience';
  6. import { delStudentProject } from '../../api/studentProject';
  7. export default {
  8. components: {
  9. StepLayout
  10. },
  11. setup() {
  12. const educationList = ref([]);
  13. const workList = ref([]);
  14. const projectList = ref([]);
  15. const isEditMode = ref(false);
  16. const loadData = async () => {
  17. const userInfo = uni.getStorageSync('userInfo');
  18. const studentId = userInfo ? userInfo.studentId : null;
  19. if (!studentId) return;
  20. try {
  21. const res = await getStudent(studentId);
  22. if (res.code === 200 && res.data) {
  23. educationList.value = res.data.educationList || [];
  24. workList.value = res.data.experienceList || [];
  25. projectList.value = res.data.projectList || [];
  26. }
  27. } catch (err) {
  28. console.error('加载经历失败', err);
  29. }
  30. };
  31. onMounted(() => {
  32. const options = getCurrentPages()[getCurrentPages().length - 1].options;
  33. if (options && options.editMode === '1') {
  34. isEditMode.value = true;
  35. }
  36. loadData();
  37. uni.$on('refresh_experience', () => {
  38. loadData();
  39. });
  40. });
  41. onUnmounted(() => {
  42. uni.$off('refresh_experience');
  43. });
  44. const showModal = ref(false);
  45. const modalContent = ref('');
  46. let currentDeleteType = '';
  47. let currentDeleteId = null;
  48. const openModal = (type, content, id) => {
  49. currentDeleteType = type;
  50. modalContent.value = content;
  51. currentDeleteId = id;
  52. showModal.value = true;
  53. };
  54. const closeModal = () => {
  55. showModal.value = false;
  56. };
  57. const confirmDelete = async () => {
  58. uni.showLoading({ title: '删除中...' });
  59. try {
  60. if (currentDeleteType === 'education') {
  61. await delStudentEducation(currentDeleteId);
  62. } else if (currentDeleteType === 'work') {
  63. await delStudentExperience(currentDeleteId);
  64. } else if (currentDeleteType === 'project') {
  65. await delStudentProject(currentDeleteId);
  66. }
  67. uni.showToast({ title: '删除成功', icon: 'success' });
  68. loadData();
  69. } catch (err) {
  70. uni.showToast({ title: '删除失败', icon: 'none' });
  71. } finally {
  72. closeModal();
  73. uni.hideLoading();
  74. }
  75. };
  76. const addEducation = () => { uni.navigateTo({ url: '/pages/experience/add-education' }); };
  77. const editEducation = (i) => {
  78. uni.setStorageSync('edit_data_education', educationList.value[i]);
  79. uni.navigateTo({ url: '/pages/experience/add-education?index=' + i });
  80. };
  81. const deleteEducation = (i) => { openModal('education', '确定要删除这段教育经历吗?', educationList.value[i].id); };
  82. const addWork = () => { uni.navigateTo({ url: '/pages/experience/add-work' }); };
  83. const editWork = (i) => {
  84. uni.setStorageSync('edit_data_work', workList.value[i]);
  85. uni.navigateTo({ url: '/pages/experience/add-work?index=' + i });
  86. };
  87. const deleteWork = (i) => { openModal('work', '确定要删除这段工作经历吗?', workList.value[i].id); };
  88. const addProject = () => { uni.navigateTo({ url: '/pages/experience/add-project' }); };
  89. const editProject = (i) => {
  90. uni.setStorageSync('edit_data_project', projectList.value[i]);
  91. uni.navigateTo({ url: '/pages/experience/add-project?index=' + i });
  92. };
  93. const deleteProject = (i) => { openModal('project', '确定要删除这段项目经历吗?', projectList.value[i].id); };
  94. const goNext = () => {
  95. const url = isEditMode.value ? '/pages/intention/intention?editMode=1' : '/pages/intention/intention';
  96. uni.navigateTo({ url });
  97. };
  98. const goSkip = () => {
  99. const url = isEditMode.value ? '/pages/intention/intention?editMode=1' : '/pages/intention/intention';
  100. uni.navigateTo({ url });
  101. };
  102. return {
  103. educationList,
  104. workList,
  105. projectList,
  106. showModal, modalContent, closeModal, confirmDelete,
  107. addEducation, editEducation, deleteEducation,
  108. addWork, editWork, deleteWork,
  109. addProject, editProject, deleteProject,
  110. goNext, goSkip,
  111. isEditMode
  112. };
  113. }
  114. }