add-work.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_studentExperience = require("../../api/studentExperience.js");
  4. const _sfc_main = {
  5. setup() {
  6. const form = common_vendor.ref({
  7. // Note: form fields map to MainStudentExperienceBo fields
  8. company: "",
  9. industry: "",
  10. startTime: "",
  11. endTime: "",
  12. positionName: "",
  13. department: "",
  14. content: "",
  15. // maps to desc
  16. isIntern: false,
  17. isHidden: false
  18. });
  19. const isComplete = common_vendor.computed(() => {
  20. return !!(form.value.company && form.value.industry && form.value.startTime && form.value.positionName && form.value.content);
  21. });
  22. const editIndex = common_vendor.ref(-1);
  23. const isEdit = common_vendor.computed(() => editIndex.value !== -1);
  24. common_vendor.onLoad((options) => {
  25. if (options && options.index !== void 0) {
  26. editIndex.value = parseInt(options.index);
  27. const data = common_vendor.index.getStorageSync("edit_data_work");
  28. if (data) {
  29. form.value = {
  30. id: data.id,
  31. company: data.company || "",
  32. industry: data.industry || "",
  33. startTime: data.startTime || "",
  34. endTime: data.endTime || "",
  35. positionName: data.jobTitle || data.positionName || "",
  36. department: data.department || "",
  37. content: data.workContent || data.content || "",
  38. isIntern: data.isInternship === 1 || data.isIntern || false,
  39. isHidden: !!data.isHidden
  40. };
  41. }
  42. }
  43. common_vendor.index.setNavigationBarTitle({ title: isEdit.value ? "修改工作经历" : "添加工作经历" });
  44. common_vendor.index.$on("select_industry", (val) => {
  45. form.value.industry = val;
  46. });
  47. common_vendor.index.$on("select_position", (val) => {
  48. form.value.positionName = val;
  49. });
  50. });
  51. const goBack = () => {
  52. common_vendor.index.navigateBack();
  53. };
  54. const openIndustrySelector = () => {
  55. const currentSelected = form.value.industry ? encodeURIComponent(form.value.industry) : "";
  56. common_vendor.index.navigateTo({
  57. url: `/pages/experience/industry-select?selected=${currentSelected}`
  58. });
  59. };
  60. const openPositionSelector = () => {
  61. const currentSelected = form.value.positionName ? encodeURIComponent(form.value.positionName) : "";
  62. common_vendor.index.navigateTo({
  63. url: `/pages/experience/position-select?selected=${currentSelected}`
  64. });
  65. };
  66. const yearOptions = [];
  67. const monthOptions = [];
  68. const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
  69. for (let i = 1990; i <= currentYear + 10; i++) {
  70. yearOptions.push(i + "年");
  71. }
  72. for (let i = 1; i <= 12; i++) {
  73. monthOptions.push((i < 10 ? "0" + i : i) + "月");
  74. }
  75. const showDatePicker = common_vendor.ref(false);
  76. const datePickerType = common_vendor.ref("start");
  77. const datePickerValue = common_vendor.ref([currentYear - 1990, 0]);
  78. const tempStartTime = common_vendor.ref("");
  79. const tempEndTime = common_vendor.ref("");
  80. const switchDateTab = (type) => {
  81. datePickerType.value = type;
  82. const target = type === "start" ? tempStartTime.value : tempEndTime.value;
  83. if (target && target !== "至今") {
  84. const parts = target.split(".");
  85. let yIdx = yearOptions.indexOf(parts[0] + "年");
  86. let mIdx = monthOptions.indexOf(parts[1] + "月");
  87. if (yIdx === -1)
  88. yIdx = currentYear - 1990;
  89. if (mIdx === -1)
  90. mIdx = 0;
  91. datePickerValue.value = [yIdx, mIdx];
  92. } else {
  93. datePickerValue.value = [currentYear - 1990, 0];
  94. if (type === "start" && !tempStartTime.value) {
  95. tempStartTime.value = `${currentYear}.01`;
  96. }
  97. }
  98. };
  99. const openDatePicker = (type) => {
  100. tempStartTime.value = form.value.startTime;
  101. tempEndTime.value = form.value.endTime;
  102. showDatePicker.value = true;
  103. switchDateTab(type);
  104. };
  105. const closeDatePicker = () => {
  106. showDatePicker.value = false;
  107. };
  108. const onDatePickerChange = (e) => {
  109. datePickerValue.value = e.detail.value;
  110. const yIdx = datePickerValue.value[0] !== void 0 ? datePickerValue.value[0] : currentYear - 1990;
  111. const mIdx = datePickerValue.value[1] !== void 0 ? datePickerValue.value[1] : 0;
  112. const yVal = yearOptions[yIdx].replace("年", "");
  113. const mVal = monthOptions[mIdx].replace("月", "");
  114. const formatted = `${yVal}.${mVal}`;
  115. if (datePickerType.value === "start") {
  116. tempStartTime.value = formatted;
  117. } else {
  118. tempEndTime.value = formatted;
  119. }
  120. };
  121. const confirmDatePicker = () => {
  122. form.value.startTime = tempStartTime.value;
  123. form.value.endTime = tempEndTime.value;
  124. showDatePicker.value = false;
  125. };
  126. const saveForm = async () => {
  127. if (!isComplete.value)
  128. return;
  129. common_vendor.index.showLoading({ title: "保存中..." });
  130. try {
  131. const userInfo = common_vendor.index.getStorageSync("userInfo");
  132. const studentId = userInfo ? userInfo.studentId : null;
  133. if (!studentId) {
  134. common_vendor.index.hideLoading();
  135. common_vendor.index.showToast({ title: "登录失效,请重新登录", icon: "none" });
  136. return;
  137. }
  138. const reqData = {
  139. studentId,
  140. company: form.value.company,
  141. industry: form.value.industry,
  142. jobTitle: form.value.positionName,
  143. department: form.value.department,
  144. startTime: form.value.startTime,
  145. endTime: form.value.endTime,
  146. workContent: form.value.content,
  147. isInternship: form.value.isIntern ? 1 : 0,
  148. isHidden: form.value.isHidden ? 1 : 0
  149. };
  150. if (isEdit.value) {
  151. reqData.id = form.value.id;
  152. const res = await api_studentExperience.updateStudentExperience(reqData);
  153. common_vendor.index.hideLoading();
  154. if (res.code === 200) {
  155. common_vendor.index.showToast({ title: "修改成功", icon: "success" });
  156. common_vendor.index.removeStorageSync("edit_data_work");
  157. setTimeout(() => {
  158. common_vendor.index.$emit("refresh_experience");
  159. common_vendor.index.navigateBack();
  160. }, 1e3);
  161. } else {
  162. common_vendor.index.showToast({ title: res.msg || "修改失败", icon: "none" });
  163. }
  164. } else {
  165. const res = await api_studentExperience.addStudentExperience(reqData);
  166. common_vendor.index.hideLoading();
  167. if (res.code === 200) {
  168. common_vendor.index.showToast({ title: "添加成功", icon: "success" });
  169. setTimeout(() => {
  170. common_vendor.index.$emit("refresh_experience");
  171. common_vendor.index.navigateBack();
  172. }, 1e3);
  173. } else {
  174. common_vendor.index.showToast({ title: res.msg || "添加失败", icon: "none" });
  175. }
  176. }
  177. } catch (error) {
  178. common_vendor.index.hideLoading();
  179. common_vendor.index.showToast({ title: "网络异常,保存失败", icon: "none" });
  180. common_vendor.index.__f__("error", "at pages/experience/add-work.js:203", error);
  181. }
  182. };
  183. return {
  184. form,
  185. isComplete,
  186. isEdit,
  187. goBack,
  188. openIndustrySelector,
  189. openPositionSelector,
  190. showDatePicker,
  191. datePickerType,
  192. datePickerValue,
  193. yearOptions,
  194. monthOptions,
  195. tempStartTime,
  196. tempEndTime,
  197. openDatePicker,
  198. closeDatePicker,
  199. switchDateTab,
  200. onDatePickerChange,
  201. confirmDatePicker,
  202. saveForm
  203. };
  204. }
  205. };
  206. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  207. return common_vendor.e({
  208. a: !_ctx.form.company
  209. }, !_ctx.form.company ? {} : {}, {
  210. b: _ctx.form.company,
  211. c: common_vendor.o(($event) => _ctx.form.company = $event.detail.value),
  212. d: common_vendor.t(_ctx.form.industry || "请选择"),
  213. e: common_vendor.n(!_ctx.form.industry ? "is-empty" : ""),
  214. f: common_vendor.o((...args) => _ctx.openIndustrySelector && _ctx.openIndustrySelector(...args)),
  215. g: common_vendor.t(_ctx.form.startTime || "入职时间"),
  216. h: common_vendor.n(!_ctx.form.startTime ? "is-empty" : ""),
  217. i: common_vendor.o(($event) => _ctx.openDatePicker("start")),
  218. j: common_vendor.t(_ctx.form.endTime || "至今"),
  219. k: common_vendor.n(!_ctx.form.endTime ? "is-empty" : ""),
  220. l: common_vendor.o(($event) => _ctx.openDatePicker("end")),
  221. m: common_vendor.t(_ctx.form.positionName || "请选择"),
  222. n: common_vendor.n(!_ctx.form.positionName ? "is-empty" : ""),
  223. o: common_vendor.o((...args) => _ctx.openPositionSelector && _ctx.openPositionSelector(...args)),
  224. p: _ctx.form.department,
  225. q: common_vendor.o(($event) => _ctx.form.department = $event.detail.value),
  226. r: _ctx.form.content,
  227. s: common_vendor.o(($event) => _ctx.form.content = $event.detail.value),
  228. t: _ctx.form.isIntern,
  229. v: common_vendor.o((e) => _ctx.form.isIntern = e.detail.value),
  230. w: _ctx.form.isHidden,
  231. x: common_vendor.o((e) => _ctx.form.isHidden = e.detail.value),
  232. y: _ctx.isEdit
  233. }, _ctx.isEdit ? {} : {}, {
  234. z: !_ctx.isComplete ? 1 : "",
  235. A: common_vendor.o((...args) => _ctx.saveForm && _ctx.saveForm(...args)),
  236. B: _ctx.showDatePicker
  237. }, _ctx.showDatePicker ? {
  238. C: common_vendor.o((...args) => _ctx.closeDatePicker && _ctx.closeDatePicker(...args)),
  239. D: common_vendor.t(_ctx.tempStartTime || "请选择"),
  240. E: common_vendor.n(_ctx.datePickerType === "start" ? "active" : ""),
  241. F: common_vendor.o(($event) => _ctx.switchDateTab("start")),
  242. G: common_vendor.t(_ctx.tempEndTime || "至今"),
  243. H: common_vendor.n(_ctx.datePickerType === "end" ? "active" : ""),
  244. I: common_vendor.o(($event) => _ctx.switchDateTab("end")),
  245. J: common_vendor.f(_ctx.yearOptions, (item, index, i0) => {
  246. return {
  247. a: common_vendor.t(item),
  248. b: index
  249. };
  250. }),
  251. K: common_vendor.f(_ctx.monthOptions, (item, index, i0) => {
  252. return {
  253. a: common_vendor.t(item),
  254. b: index
  255. };
  256. }),
  257. L: _ctx.datePickerValue,
  258. M: common_vendor.o((...args) => _ctx.onDatePickerChange && _ctx.onDatePickerChange(...args)),
  259. N: common_vendor.o((...args) => _ctx.confirmDatePicker && _ctx.confirmDatePicker(...args)),
  260. O: common_vendor.o(() => {
  261. })
  262. } : {});
  263. }
  264. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ab00616a"]]);
  265. wx.createPage(MiniProgramPage);
  266. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/experience/add-work.js.map