| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const api_studentExperience = require("../../api/studentExperience.js");
- const _sfc_main = {
- setup() {
- const form = common_vendor.ref({
- // Note: form fields map to MainStudentExperienceBo fields
- company: "",
- industry: "",
- startTime: "",
- endTime: "",
- positionName: "",
- department: "",
- content: "",
- // maps to desc
- isIntern: false,
- isHidden: false
- });
- const isComplete = common_vendor.computed(() => {
- return !!(form.value.company && form.value.industry && form.value.startTime && form.value.positionName && form.value.content);
- });
- const editIndex = common_vendor.ref(-1);
- const isEdit = common_vendor.computed(() => editIndex.value !== -1);
- common_vendor.onLoad((options) => {
- if (options && options.index !== void 0) {
- editIndex.value = parseInt(options.index);
- const data = common_vendor.index.getStorageSync("edit_data_work");
- if (data) {
- form.value = {
- id: data.id,
- company: data.company || "",
- industry: data.industry || "",
- startTime: data.startTime || "",
- endTime: data.endTime || "",
- positionName: data.jobTitle || data.positionName || "",
- department: data.department || "",
- content: data.workContent || data.content || "",
- isIntern: data.isInternship === 1 || data.isIntern || false,
- isHidden: !!data.isHidden
- };
- }
- }
- common_vendor.index.setNavigationBarTitle({ title: isEdit.value ? "修改工作经历" : "添加工作经历" });
- common_vendor.index.$on("select_industry", (val) => {
- form.value.industry = val;
- });
- common_vendor.index.$on("select_position", (val) => {
- form.value.positionName = val;
- });
- });
- const goBack = () => {
- common_vendor.index.navigateBack();
- };
- const openIndustrySelector = () => {
- const currentSelected = form.value.industry ? encodeURIComponent(form.value.industry) : "";
- common_vendor.index.navigateTo({
- url: `/pages/experience/industry-select?selected=${currentSelected}`
- });
- };
- const openPositionSelector = () => {
- const currentSelected = form.value.positionName ? encodeURIComponent(form.value.positionName) : "";
- common_vendor.index.navigateTo({
- url: `/pages/experience/position-select?selected=${currentSelected}`
- });
- };
- 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 tempStartTime = common_vendor.ref("");
- const tempEndTime = common_vendor.ref("");
- const switchDateTab = (type) => {
- datePickerType.value = type;
- const target = type === "start" ? tempStartTime.value : tempEndTime.value;
- if (target && 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];
- if (type === "start" && !tempStartTime.value) {
- tempStartTime.value = `${currentYear}.01`;
- }
- }
- };
- const openDatePicker = (type) => {
- tempStartTime.value = form.value.startTime;
- tempEndTime.value = form.value.endTime;
- showDatePicker.value = true;
- switchDateTab(type);
- };
- const closeDatePicker = () => {
- showDatePicker.value = false;
- };
- const onDatePickerChange = (e) => {
- datePickerValue.value = e.detail.value;
- 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") {
- tempStartTime.value = formatted;
- } else {
- tempEndTime.value = formatted;
- }
- };
- const confirmDatePicker = () => {
- form.value.startTime = tempStartTime.value;
- form.value.endTime = tempEndTime.value;
- 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,
- company: form.value.company,
- industry: form.value.industry,
- jobTitle: form.value.positionName,
- department: form.value.department,
- startTime: form.value.startTime,
- endTime: form.value.endTime,
- workContent: form.value.content,
- isInternship: form.value.isIntern ? 1 : 0,
- isHidden: form.value.isHidden ? 1 : 0
- };
- if (isEdit.value) {
- reqData.id = form.value.id;
- const res = await api_studentExperience.updateStudentExperience(reqData);
- common_vendor.index.hideLoading();
- if (res.code === 200) {
- common_vendor.index.showToast({ title: "修改成功", icon: "success" });
- common_vendor.index.removeStorageSync("edit_data_work");
- 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_studentExperience.addStudentExperience(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-work.js:203", error);
- }
- };
- return {
- form,
- isComplete,
- isEdit,
- goBack,
- openIndustrySelector,
- openPositionSelector,
- showDatePicker,
- datePickerType,
- datePickerValue,
- yearOptions,
- monthOptions,
- tempStartTime,
- tempEndTime,
- openDatePicker,
- closeDatePicker,
- switchDateTab,
- onDatePickerChange,
- confirmDatePicker,
- saveForm
- };
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: !_ctx.form.company
- }, !_ctx.form.company ? {} : {}, {
- b: _ctx.form.company,
- c: common_vendor.o(($event) => _ctx.form.company = $event.detail.value),
- d: common_vendor.t(_ctx.form.industry || "请选择"),
- e: common_vendor.n(!_ctx.form.industry ? "is-empty" : ""),
- f: common_vendor.o((...args) => _ctx.openIndustrySelector && _ctx.openIndustrySelector(...args)),
- g: common_vendor.t(_ctx.form.startTime || "入职时间"),
- h: common_vendor.n(!_ctx.form.startTime ? "is-empty" : ""),
- i: common_vendor.o(($event) => _ctx.openDatePicker("start")),
- j: common_vendor.t(_ctx.form.endTime || "至今"),
- k: common_vendor.n(!_ctx.form.endTime ? "is-empty" : ""),
- l: common_vendor.o(($event) => _ctx.openDatePicker("end")),
- m: common_vendor.t(_ctx.form.positionName || "请选择"),
- n: common_vendor.n(!_ctx.form.positionName ? "is-empty" : ""),
- o: common_vendor.o((...args) => _ctx.openPositionSelector && _ctx.openPositionSelector(...args)),
- p: _ctx.form.department,
- q: common_vendor.o(($event) => _ctx.form.department = $event.detail.value),
- r: _ctx.form.content,
- s: common_vendor.o(($event) => _ctx.form.content = $event.detail.value),
- t: _ctx.form.isIntern,
- v: common_vendor.o((e) => _ctx.form.isIntern = e.detail.value),
- w: _ctx.form.isHidden,
- x: common_vendor.o((e) => _ctx.form.isHidden = e.detail.value),
- y: _ctx.isEdit
- }, _ctx.isEdit ? {} : {}, {
- z: !_ctx.isComplete ? 1 : "",
- A: common_vendor.o((...args) => _ctx.saveForm && _ctx.saveForm(...args)),
- B: _ctx.showDatePicker
- }, _ctx.showDatePicker ? {
- C: common_vendor.o((...args) => _ctx.closeDatePicker && _ctx.closeDatePicker(...args)),
- D: common_vendor.t(_ctx.tempStartTime || "请选择"),
- E: common_vendor.n(_ctx.datePickerType === "start" ? "active" : ""),
- F: common_vendor.o(($event) => _ctx.switchDateTab("start")),
- G: common_vendor.t(_ctx.tempEndTime || "至今"),
- H: common_vendor.n(_ctx.datePickerType === "end" ? "active" : ""),
- I: common_vendor.o(($event) => _ctx.switchDateTab("end")),
- J: common_vendor.f(_ctx.yearOptions, (item, index, i0) => {
- return {
- a: common_vendor.t(item),
- b: index
- };
- }),
- K: common_vendor.f(_ctx.monthOptions, (item, index, i0) => {
- return {
- a: common_vendor.t(item),
- b: index
- };
- }),
- L: _ctx.datePickerValue,
- M: common_vendor.o((...args) => _ctx.onDatePickerChange && _ctx.onDatePickerChange(...args)),
- N: common_vendor.o((...args) => _ctx.confirmDatePicker && _ctx.confirmDatePicker(...args)),
- O: common_vendor.o(() => {
- })
- } : {});
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ab00616a"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/experience/add-work.js.map
|