| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const api_studentEducation = require("../../api/studentEducation.js");
- const api_dict = require("../../api/dict.js");
- const _sfc_main = {
- setup() {
- const degreeOptions = common_vendor.ref([]);
- const typeOptions = common_vendor.ref([]);
- const form = common_vendor.ref({
- school: "",
- degree: "",
- educationType: "",
- major: "",
- startTime: "",
- endTime: "",
- desc: ""
- });
- const isComplete = common_vendor.computed(() => {
- return !!(form.value.school && form.value.degree && form.value.major && form.value.startTime && form.value.endTime);
- });
- const editIndex = common_vendor.ref(-1);
- const isEdit = common_vendor.computed(() => editIndex.value !== -1);
- const loadDicts = async () => {
- try {
- const [eduRes, typeRes] = await Promise.all([
- api_dict.getDicts("main_education"),
- api_dict.getDicts("main_education_all")
- ]);
- degreeOptions.value = (eduRes.data || []).map((item) => item.dictLabel);
- typeOptions.value = (typeRes.data || []).map((item) => item.dictLabel);
- if (!form.value.educationType && typeOptions.value.length > 0) {
- form.value.educationType = typeOptions.value[0];
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/experience/add-education.js:48", "加载字典失败", e);
- }
- };
- common_vendor.onLoad((options) => {
- loadDicts();
- if (options && options.index !== void 0) {
- editIndex.value = parseInt(options.index);
- const data = common_vendor.index.getStorageSync("edit_data_education");
- if (data) {
- let degreeVal = data.education || data.degree || "";
- let typeVal = "";
- if (degreeVal.includes(" ")) {
- const parts = degreeVal.split(" ");
- degreeVal = parts[0];
- typeVal = parts[1] || "";
- }
- if (data.educationType) {
- typeVal = data.educationType;
- }
- form.value = {
- id: data.id,
- school: data.school || "",
- degree: degreeVal,
- educationType: typeVal,
- major: data.major || "",
- startTime: data.startTime || "",
- endTime: data.endTime || "",
- desc: data.campusExperience || data.desc || ""
- };
- }
- }
- common_vendor.index.setNavigationBarTitle({ title: isEdit.value ? "修改教育经历" : "添加教育经历" });
- });
- const goBack = () => {
- common_vendor.index.navigateBack();
- };
- const showPicker = common_vendor.ref(false);
- const pickerValue = common_vendor.ref([0, 0]);
- const openPicker = () => {
- if (form.value.degree) {
- let dIdx = degreeOptions.value.indexOf(form.value.degree);
- let tIdx = typeOptions.value.indexOf(form.value.educationType);
- if (dIdx === -1)
- dIdx = 0;
- if (tIdx === -1)
- tIdx = 0;
- pickerValue.value = [dIdx, tIdx];
- } else {
- pickerValue.value = [0, 0];
- }
- showPicker.value = true;
- };
- const closePicker = () => {
- showPicker.value = false;
- };
- const onPickerChange = (e) => {
- pickerValue.value = e.detail.value;
- };
- const confirmPicker = () => {
- const dIdx = pickerValue.value[0] !== void 0 ? pickerValue.value[0] : 0;
- const tIdx = pickerValue.value[1] !== void 0 ? pickerValue.value[1] : 0;
- if (degreeOptions.value.length > 0) {
- form.value.degree = degreeOptions.value[dIdx];
- }
- if (typeOptions.value.length > 0) {
- form.value.educationType = typeOptions.value[tIdx];
- }
- showPicker.value = false;
- };
- const yearOptions = [];
- const monthOptions = [];
- const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
- for (let i = 1990; i <= currentYear + 10; i++) {
- yearOptions.push(i + "年");
- }
- for (let i = 1; i <= 12; i++) {
- monthOptions.push((i < 10 ? "0" + i : i) + "月");
- }
- const showDatePicker = common_vendor.ref(false);
- const datePickerType = common_vendor.ref("start");
- const datePickerValue = common_vendor.ref([currentYear - 1990, 0]);
- const openDatePicker = (type) => {
- datePickerType.value = type;
- const target = type === "start" ? form.value.startTime : form.value.endTime;
- if (target) {
- const parts = target.split(".");
- let yIdx = yearOptions.indexOf(parts[0] + "年");
- let mIdx = monthOptions.indexOf(parts[1] + "月");
- if (yIdx === -1)
- yIdx = currentYear - 1990;
- if (mIdx === -1)
- mIdx = 0;
- datePickerValue.value = [yIdx, mIdx];
- } else {
- datePickerValue.value = [currentYear - 1990, 0];
- }
- showDatePicker.value = true;
- };
- const closeDatePicker = () => {
- showDatePicker.value = false;
- };
- const onDatePickerChange = (e) => {
- datePickerValue.value = e.detail.value;
- };
- const confirmDatePicker = () => {
- const yIdx = datePickerValue.value[0] !== void 0 ? datePickerValue.value[0] : currentYear - 1990;
- const mIdx = datePickerValue.value[1] !== void 0 ? datePickerValue.value[1] : 0;
- const yVal = yearOptions[yIdx].replace("年", "");
- const mVal = monthOptions[mIdx].replace("月", "");
- const formatted = `${yVal}.${mVal}`;
- if (datePickerType.value === "start") {
- form.value.startTime = formatted;
- } else {
- form.value.endTime = formatted;
- }
- showDatePicker.value = false;
- };
- const saveForm = async () => {
- if (!isComplete.value)
- return;
- common_vendor.index.showLoading({ title: "保存中..." });
- try {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- const studentId = userInfo ? userInfo.studentId : null;
- if (!studentId) {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({ title: "登录失效,请重新登录", icon: "none" });
- return;
- }
- const reqData = {
- studentId,
- school: form.value.school,
- education: form.value.degree,
- educationType: form.value.educationType,
- major: form.value.major,
- startTime: form.value.startTime,
- endTime: form.value.endTime,
- campusExperience: form.value.desc
- };
- if (isEdit.value) {
- reqData.id = form.value.id;
- const res = await api_studentEducation.updateStudentEducation(reqData);
- common_vendor.index.hideLoading();
- if (res.code === 200) {
- common_vendor.index.showToast({ title: "修改成功", icon: "success" });
- common_vendor.index.removeStorageSync("edit_data_education");
- setTimeout(() => {
- common_vendor.index.$emit("refresh_experience");
- common_vendor.index.navigateBack();
- }, 1e3);
- } else {
- common_vendor.index.showToast({ title: res.msg || "修改失败", icon: "none" });
- }
- } else {
- const res = await api_studentEducation.addStudentEducation(reqData);
- common_vendor.index.hideLoading();
- if (res.code === 200) {
- common_vendor.index.showToast({ title: "添加成功", icon: "success" });
- setTimeout(() => {
- common_vendor.index.$emit("refresh_experience");
- common_vendor.index.navigateBack();
- }, 1e3);
- } else {
- common_vendor.index.showToast({ title: res.msg || "添加失败", icon: "none" });
- }
- }
- } catch (error) {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({ title: "网络异常,保存失败", icon: "none" });
- common_vendor.index.__f__("error", "at pages/experience/add-education.js:241", error);
- }
- };
- return {
- form,
- degreeOptions,
- typeOptions,
- isComplete,
- isEdit,
- goBack,
- showPicker,
- pickerValue,
- openPicker,
- closePicker,
- onPickerChange,
- confirmPicker,
- showDatePicker,
- datePickerType,
- datePickerValue,
- yearOptions,
- monthOptions,
- openDatePicker,
- closeDatePicker,
- onDatePickerChange,
- confirmDatePicker,
- saveForm
- };
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: !_ctx.form.school
- }, !_ctx.form.school ? {} : {}, {
- b: _ctx.form.school,
- c: common_vendor.o(($event) => _ctx.form.school = $event.detail.value),
- d: !_ctx.form.degree
- }, !_ctx.form.degree ? {} : {}, {
- e: common_vendor.t(_ctx.form.degree || "请选择"),
- f: common_vendor.n(!_ctx.form.degree ? "is-empty" : ""),
- g: common_vendor.o((...args) => _ctx.openPicker && _ctx.openPicker(...args)),
- h: !_ctx.form.major
- }, !_ctx.form.major ? {} : {}, {
- i: _ctx.form.major,
- j: common_vendor.o(($event) => _ctx.form.major = $event.detail.value),
- k: !_ctx.form.startTime || !_ctx.form.endTime
- }, !_ctx.form.startTime || !_ctx.form.endTime ? {} : {}, {
- l: common_vendor.t(_ctx.form.startTime || "入学时间"),
- m: common_vendor.n(!_ctx.form.startTime ? "is-empty" : ""),
- n: common_vendor.o(($event) => _ctx.openDatePicker("start")),
- o: common_vendor.t(_ctx.form.endTime || "毕业时间"),
- p: common_vendor.n(!_ctx.form.endTime ? "is-empty" : ""),
- q: common_vendor.o(($event) => _ctx.openDatePicker("end")),
- r: _ctx.form.desc,
- s: common_vendor.o(($event) => _ctx.form.desc = $event.detail.value),
- t: _ctx.isEdit
- }, _ctx.isEdit ? {} : {}, {
- v: !_ctx.isComplete ? 1 : "",
- w: common_vendor.o((...args) => _ctx.saveForm && _ctx.saveForm(...args)),
- x: _ctx.showPicker
- }, _ctx.showPicker ? {
- y: common_vendor.o((...args) => _ctx.closePicker && _ctx.closePicker(...args)),
- z: common_vendor.o((...args) => _ctx.closePicker && _ctx.closePicker(...args)),
- A: common_vendor.o((...args) => _ctx.confirmPicker && _ctx.confirmPicker(...args)),
- B: common_vendor.f(_ctx.degreeOptions, (item, index, i0) => {
- return {
- a: common_vendor.t(item),
- b: index
- };
- }),
- C: common_vendor.f(_ctx.typeOptions, (item, index, i0) => {
- return {
- a: common_vendor.t(item),
- b: index
- };
- }),
- D: _ctx.pickerValue,
- E: common_vendor.o((...args) => _ctx.onPickerChange && _ctx.onPickerChange(...args)),
- F: common_vendor.o(() => {
- })
- } : {}, {
- G: _ctx.showDatePicker
- }, _ctx.showDatePicker ? {
- H: common_vendor.o((...args) => _ctx.closeDatePicker && _ctx.closeDatePicker(...args)),
- I: common_vendor.o((...args) => _ctx.closeDatePicker && _ctx.closeDatePicker(...args)),
- J: common_vendor.t(_ctx.datePickerType === "start" ? "入学时间" : "毕业时间"),
- K: common_vendor.o((...args) => _ctx.confirmDatePicker && _ctx.confirmDatePicker(...args)),
- L: common_vendor.f(_ctx.yearOptions, (item, index, i0) => {
- return {
- a: common_vendor.t(item),
- b: index
- };
- }),
- M: common_vendor.f(_ctx.monthOptions, (item, index, i0) => {
- return {
- a: common_vendor.t(item),
- b: index
- };
- }),
- N: _ctx.datePickerValue,
- O: common_vendor.o((...args) => _ctx.onDatePickerChange && _ctx.onDatePickerChange(...args)),
- P: common_vendor.o(() => {
- })
- } : {});
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-561b1502"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/experience/add-education.js.map
|