| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- import { ref, computed, onMounted, onUnmounted } from 'vue';
- import StepLayout from '../../components/step-layout/step-layout.vue';
- import { getDicts } from '../../api/dict';
- import { updateStudent, getStudent } from '../../api/student';
- export default {
- components: {
- StepLayout
- },
- setup() {
- const intentions = ref([]); // main_position_type 求职意向
- const arrivalTime = ref(''); // 当前选中的到岗时间 value
- const internDuration = ref(''); // 当前选中的实习时长 value
- const arrivalTimeList = ref([]); // 保存到岗时间字典完整列表
- const durationList = ref([]); // 保存实习时长字典完整列表
- const isIntern = computed(() => {
- return intentions.value.find(item => item.name === '实习')?.selected || false;
- });
- // 展示用的 label:将 value 反查为 dictLabel
- const arrivalTimeLabel = computed(() => {
- if (!arrivalTime.value) return '';
- const found = arrivalTimeList.value.find(d => d.dictValue === arrivalTime.value);
- return found ? found.dictLabel : arrivalTime.value;
- });
- const internDurationLabel = computed(() => {
- if (!internDuration.value) return '';
- const found = durationList.value.find(d => d.dictValue === internDuration.value);
- return found ? found.dictLabel : internDuration.value;
- });
- const jobTypes = ref([]); // main_position_intention 求职类型
- const targetCompanies = ref([]); // 选中的意向公司列表
- const showModal = ref(false);
- const modalContent = ref('');
- let currentDeleteIndex = -1;
- const isEditMode = ref(false);
- const loadDicts = async () => {
- uni.showLoading({ title: '加载中...' });
- try {
- const [arrRes, posTypeRes, posIntentionRes, durRes] = await Promise.all([
- getDicts('main_arrival_time'),
- getDicts('main_position_type'),
- getDicts('main_position_intention'),
- getDicts('main_internship_duration')
- ]);
- if (arrRes.code === 200) {
- arrivalTimeList.value = (arrRes.data || arrRes.rows || []);
- if(arrivalTimeList.value.length > 0) {
- arrivalTime.value = arrivalTimeList.value[1]?.dictValue || arrivalTimeList.value[0]?.dictValue || '';
- }
- }
-
- if (durRes && durRes.code === 200) {
- durationList.value = (durRes.data || durRes.rows || []);
- if (durationList.value.length > 0) {
- internDuration.value = durationList.value[0]?.dictValue || '';
- }
- }
- if (posTypeRes.code === 200) {
- intentions.value = (posTypeRes.data || posTypeRes.rows || []).map((dict, idx) => ({
- name: dict.dictLabel,
- value: dict.dictValue,
- selected: idx === 0
- }));
- }
- if (posIntentionRes.code === 200) {
- jobTypes.value = (posIntentionRes.data || posIntentionRes.rows || []).map((dict, idx) => ({
- name: dict.dictLabel,
- value: dict.dictValue,
- selected: idx < 2 // 默认随便选一两个
- }));
- }
- } catch (e) {
- console.error(e);
- } finally {
- uni.hideLoading();
- }
- };
- const loadStudentData = async () => {
- const userInfo = uni.getStorageSync('userInfo');
- if (!userInfo || !userInfo.studentId) return;
- try {
- const res = await getStudent(userInfo.studentId);
- if (res.code === 200 && res.data) {
- const data = res.data;
-
- // 回显到岗时间 —— 兼容 value 和 label
- if (data.availability) {
- const found = arrivalTimeList.value.find(d => d.dictValue === data.availability || d.dictLabel === data.availability);
- if (found) arrivalTime.value = found.dictValue;
- }
-
- // 回显实习时长 —— 兼容 value 和 label
- if (data.internshipDuration) {
- const found = durationList.value.find(d => d.dictValue === data.internshipDuration || d.dictLabel === data.internshipDuration);
- if (found) internDuration.value = found.dictValue;
- }
-
- // 回显求职类型(全职/实习/兼职)—— 兼容 label 和 value
- if (data.jobType) {
- intentions.value.forEach(item => {
- item.selected = (item.value === data.jobType || item.name === data.jobType);
- });
- }
-
- // 回显求职意向(从 jobIntention 字段解析)—— 兼容 label 和 value
- if (data.jobIntention) {
- const selectedIntentions = data.jobIntention.split(',').map(s => s.trim()).filter(s => s);
-
- jobTypes.value.forEach(item => {
- item.selected = selectedIntentions.includes(item.value) || selectedIntentions.includes(item.name);
- });
- }
-
- // 回显意向公司
- if (data.intentionCompanies) {
- const companyNames = data.intentionCompanies.split(',').map(s => s.trim()).filter(s => s);
- targetCompanies.value = companyNames.map(name => ({ name }));
- }
- }
- } catch (err) {
- console.error('加载学员数据失败', err);
- }
- };
- onMounted(async () => {
- const options = getCurrentPages()[getCurrentPages().length - 1].options;
- if (options && options.editMode === '1') {
- isEditMode.value = true;
- }
- uni.$on('submit_companies', (selectedCompanies) => {
- targetCompanies.value = [...selectedCompanies];
- });
- await loadDicts();
-
- // 如果是编辑模式,加载学员数据进行回显
- if (isEditMode.value) {
- await loadStudentData();
- }
- });
- onUnmounted(() => {
- uni.$off('submit_companies');
- });
- const openModal = (content, index) => {
- modalContent.value = content;
- currentDeleteIndex = index;
- showModal.value = true;
- };
- const closeModal = () => {
- showModal.value = false;
- };
- const confirmDelete = () => {
- if (currentDeleteIndex !== -1) {
- targetCompanies.value.splice(currentDeleteIndex, 1);
- }
- closeModal();
- };
- const toggleIntention = (index) => {
- intentions.value.forEach((item, i) => {
- item.selected = (i === index);
- });
- };
- const selectInternDuration = () => {
- if (durationList.value.length === 0) return;
- uni.showActionSheet({
- itemList: durationList.value.map(d => d.dictLabel),
- success: (res) => {
- internDuration.value = durationList.value[res.tapIndex].dictValue;
- }
- });
- };
- const selectTime = () => {
- if (arrivalTimeList.value.length === 0) return;
- uni.showActionSheet({
- itemList: arrivalTimeList.value.map(d => d.dictLabel),
- success: (res) => {
- arrivalTime.value = arrivalTimeList.value[res.tapIndex].dictValue;
- }
- });
- };
- const toggleType = (index) => {
- jobTypes.value[index].selected = !jobTypes.value[index].selected;
- };
- const addCompany = () => {
- const selectedNames = targetCompanies.value.map(c => c.name);
- uni.setStorageSync('selected_companies', JSON.stringify(selectedNames));
- uni.navigateTo({ url: '/pages/intention/company-select' });
- };
- const deleteCompany = (index) => {
- openModal('确定要删除这家意向公司吗?', index);
- };
- const onSubmit = async () => {
- console.log('intention.js: onSubmit called');
- uni.showLoading({ title: '提交中...' });
- try {
- const userInfo = uni.getStorageSync('userInfo');
- console.log('intention.js: userInfo from storage:', userInfo);
- const studentId = userInfo ? (userInfo.studentId || userInfo.id) : null;
- console.log('intention.js: studentId identified:', studentId);
-
- if (!studentId) {
- uni.hideLoading();
- uni.showToast({ title: '登录状态失效', icon: 'none' });
- return;
- }
- const selectedJobIntention = intentions.value.find(i => i.selected)?.value || '';
- const selectedJobType = jobTypes.value.filter(i => i.selected).map(i => i.value).join(',');
- const companies = targetCompanies.value.map(c => c.name).join(',');
- // 构建更新数据
- const reqData = {
- id: studentId,
- jobIntention: selectedJobType, // 求职意向类型(审计、咨询、税务等),传 dictValue
- intentionCompanies: companies, // 意向公司列表
- jobType: selectedJobIntention, // 求职类型(全职、实习、兼职),传 dictValue
- availability: arrivalTime.value,
- internshipDuration: isIntern.value ? internDuration.value : ''
- };
- console.log('intention.js: sending updateStudent request with data:', reqData);
- const res = await updateStudent(reqData);
- console.log('intention.js: updateStudent response:', res);
- uni.hideLoading();
- if (res.code === 200) {
- uni.showToast({
- title: isEditMode.value ? '保存成功' : '提交成功',
- icon: 'success'
- });
- setTimeout(() => {
- uni.reLaunch({
- url: '/pages/my/my',
- success: () => {
- setTimeout(() => {
- uni.navigateTo({ url: '/pages/my/resume_view' });
- }, 100);
- }
- });
- }, 1000);
- } else {
- uni.showToast({ title: res.msg || '保存失败', icon: 'none' });
- }
- } catch (e) {
- console.error(e);
- uni.hideLoading();
- uni.showToast({ title: '网络异常', icon: 'none' });
- }
- };
- const onSkip = () => {
- uni.reLaunch({
- url: '/pages/my/my',
- success: () => {
- setTimeout(() => {
- uni.navigateTo({ url: '/pages/my/resume_view' });
- }, 100);
- }
- });
- };
- return {
- intentions,
- arrivalTime,
- arrivalTimeLabel,
- internDuration,
- internDurationLabel,
- isIntern,
- jobTypes,
- targetCompanies,
- showModal, modalContent, closeModal, confirmDelete,
- toggleIntention,
- selectTime,
- selectInternDuration,
- toggleType,
- addCompany, deleteCompany,
- onSubmit, onSkip,
- isEditMode
- };
- }
- }
|