add-education.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_studentEducation = require("../../api/studentEducation.js");
  4. const api_dict = require("../../api/dict.js");
  5. const _sfc_main = {
  6. setup() {
  7. const degreeOptions = common_vendor.ref([]);
  8. const typeOptions = common_vendor.ref([]);
  9. const form = common_vendor.ref({
  10. school: "",
  11. degree: "",
  12. educationType: "",
  13. major: "",
  14. startTime: "",
  15. endTime: "",
  16. desc: ""
  17. });
  18. const isComplete = common_vendor.computed(() => {
  19. return !!(form.value.school && form.value.degree && form.value.major && form.value.startTime && form.value.endTime);
  20. });
  21. const editIndex = common_vendor.ref(-1);
  22. const isEdit = common_vendor.computed(() => editIndex.value !== -1);
  23. const loadDicts = async () => {
  24. try {
  25. const [eduRes, typeRes] = await Promise.all([
  26. api_dict.getDicts("main_education"),
  27. api_dict.getDicts("main_education_all")
  28. ]);
  29. degreeOptions.value = (eduRes.data || []).map((item) => item.dictLabel);
  30. typeOptions.value = (typeRes.data || []).map((item) => item.dictLabel);
  31. if (!form.value.educationType && typeOptions.value.length > 0) {
  32. form.value.educationType = typeOptions.value[0];
  33. }
  34. } catch (e) {
  35. common_vendor.index.__f__("error", "at pages/experience/add-education.js:48", "加载字典失败", e);
  36. }
  37. };
  38. common_vendor.onLoad((options) => {
  39. loadDicts();
  40. if (options && options.index !== void 0) {
  41. editIndex.value = parseInt(options.index);
  42. const data = common_vendor.index.getStorageSync("edit_data_education");
  43. if (data) {
  44. let degreeVal = data.education || data.degree || "";
  45. let typeVal = "";
  46. if (degreeVal.includes(" ")) {
  47. const parts = degreeVal.split(" ");
  48. degreeVal = parts[0];
  49. typeVal = parts[1] || "";
  50. }
  51. if (data.educationType) {
  52. typeVal = data.educationType;
  53. }
  54. form.value = {
  55. id: data.id,
  56. school: data.school || "",
  57. degree: degreeVal,
  58. educationType: typeVal,
  59. major: data.major || "",
  60. startTime: data.startTime || "",
  61. endTime: data.endTime || "",
  62. desc: data.campusExperience || data.desc || ""
  63. };
  64. }
  65. }
  66. common_vendor.index.setNavigationBarTitle({ title: isEdit.value ? "修改教育经历" : "添加教育经历" });
  67. });
  68. const goBack = () => {
  69. common_vendor.index.navigateBack();
  70. };
  71. const showPicker = common_vendor.ref(false);
  72. const pickerValue = common_vendor.ref([0, 0]);
  73. const openPicker = () => {
  74. if (form.value.degree) {
  75. let dIdx = degreeOptions.value.indexOf(form.value.degree);
  76. let tIdx = typeOptions.value.indexOf(form.value.educationType);
  77. if (dIdx === -1)
  78. dIdx = 0;
  79. if (tIdx === -1)
  80. tIdx = 0;
  81. pickerValue.value = [dIdx, tIdx];
  82. } else {
  83. pickerValue.value = [0, 0];
  84. }
  85. showPicker.value = true;
  86. };
  87. const closePicker = () => {
  88. showPicker.value = false;
  89. };
  90. const onPickerChange = (e) => {
  91. pickerValue.value = e.detail.value;
  92. };
  93. const confirmPicker = () => {
  94. const dIdx = pickerValue.value[0] !== void 0 ? pickerValue.value[0] : 0;
  95. const tIdx = pickerValue.value[1] !== void 0 ? pickerValue.value[1] : 0;
  96. if (degreeOptions.value.length > 0) {
  97. form.value.degree = degreeOptions.value[dIdx];
  98. }
  99. if (typeOptions.value.length > 0) {
  100. form.value.educationType = typeOptions.value[tIdx];
  101. }
  102. showPicker.value = false;
  103. };
  104. const yearOptions = [];
  105. const monthOptions = [];
  106. const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
  107. for (let i = 1990; i <= currentYear + 10; i++) {
  108. yearOptions.push(i + "年");
  109. }
  110. for (let i = 1; i <= 12; i++) {
  111. monthOptions.push((i < 10 ? "0" + i : i) + "月");
  112. }
  113. const showDatePicker = common_vendor.ref(false);
  114. const datePickerType = common_vendor.ref("start");
  115. const datePickerValue = common_vendor.ref([currentYear - 1990, 0]);
  116. const openDatePicker = (type) => {
  117. datePickerType.value = type;
  118. const target = type === "start" ? form.value.startTime : form.value.endTime;
  119. if (target) {
  120. const parts = target.split(".");
  121. let yIdx = yearOptions.indexOf(parts[0] + "年");
  122. let mIdx = monthOptions.indexOf(parts[1] + "月");
  123. if (yIdx === -1)
  124. yIdx = currentYear - 1990;
  125. if (mIdx === -1)
  126. mIdx = 0;
  127. datePickerValue.value = [yIdx, mIdx];
  128. } else {
  129. datePickerValue.value = [currentYear - 1990, 0];
  130. }
  131. showDatePicker.value = true;
  132. };
  133. const closeDatePicker = () => {
  134. showDatePicker.value = false;
  135. };
  136. const onDatePickerChange = (e) => {
  137. datePickerValue.value = e.detail.value;
  138. };
  139. const confirmDatePicker = () => {
  140. const yIdx = datePickerValue.value[0] !== void 0 ? datePickerValue.value[0] : currentYear - 1990;
  141. const mIdx = datePickerValue.value[1] !== void 0 ? datePickerValue.value[1] : 0;
  142. const yVal = yearOptions[yIdx].replace("年", "");
  143. const mVal = monthOptions[mIdx].replace("月", "");
  144. const formatted = `${yVal}.${mVal}`;
  145. if (datePickerType.value === "start") {
  146. form.value.startTime = formatted;
  147. } else {
  148. form.value.endTime = formatted;
  149. }
  150. showDatePicker.value = false;
  151. };
  152. const saveForm = async () => {
  153. if (!isComplete.value)
  154. return;
  155. common_vendor.index.showLoading({ title: "保存中..." });
  156. try {
  157. const userInfo = common_vendor.index.getStorageSync("userInfo");
  158. const studentId = userInfo ? userInfo.studentId : null;
  159. if (!studentId) {
  160. common_vendor.index.hideLoading();
  161. common_vendor.index.showToast({ title: "登录失效,请重新登录", icon: "none" });
  162. return;
  163. }
  164. const reqData = {
  165. studentId,
  166. school: form.value.school,
  167. education: form.value.degree,
  168. educationType: form.value.educationType,
  169. major: form.value.major,
  170. startTime: form.value.startTime,
  171. endTime: form.value.endTime,
  172. campusExperience: form.value.desc
  173. };
  174. if (isEdit.value) {
  175. reqData.id = form.value.id;
  176. const res = await api_studentEducation.updateStudentEducation(reqData);
  177. common_vendor.index.hideLoading();
  178. if (res.code === 200) {
  179. common_vendor.index.showToast({ title: "修改成功", icon: "success" });
  180. common_vendor.index.removeStorageSync("edit_data_education");
  181. setTimeout(() => {
  182. common_vendor.index.$emit("refresh_experience");
  183. common_vendor.index.navigateBack();
  184. }, 1e3);
  185. } else {
  186. common_vendor.index.showToast({ title: res.msg || "修改失败", icon: "none" });
  187. }
  188. } else {
  189. const res = await api_studentEducation.addStudentEducation(reqData);
  190. common_vendor.index.hideLoading();
  191. if (res.code === 200) {
  192. common_vendor.index.showToast({ title: "添加成功", icon: "success" });
  193. setTimeout(() => {
  194. common_vendor.index.$emit("refresh_experience");
  195. common_vendor.index.navigateBack();
  196. }, 1e3);
  197. } else {
  198. common_vendor.index.showToast({ title: res.msg || "添加失败", icon: "none" });
  199. }
  200. }
  201. } catch (error) {
  202. common_vendor.index.hideLoading();
  203. common_vendor.index.showToast({ title: "网络异常,保存失败", icon: "none" });
  204. common_vendor.index.__f__("error", "at pages/experience/add-education.js:241", error);
  205. }
  206. };
  207. return {
  208. form,
  209. degreeOptions,
  210. typeOptions,
  211. isComplete,
  212. isEdit,
  213. goBack,
  214. showPicker,
  215. pickerValue,
  216. openPicker,
  217. closePicker,
  218. onPickerChange,
  219. confirmPicker,
  220. showDatePicker,
  221. datePickerType,
  222. datePickerValue,
  223. yearOptions,
  224. monthOptions,
  225. openDatePicker,
  226. closeDatePicker,
  227. onDatePickerChange,
  228. confirmDatePicker,
  229. saveForm
  230. };
  231. }
  232. };
  233. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  234. return common_vendor.e({
  235. a: !_ctx.form.school
  236. }, !_ctx.form.school ? {} : {}, {
  237. b: _ctx.form.school,
  238. c: common_vendor.o(($event) => _ctx.form.school = $event.detail.value),
  239. d: !_ctx.form.degree
  240. }, !_ctx.form.degree ? {} : {}, {
  241. e: common_vendor.t(_ctx.form.degree || "请选择"),
  242. f: common_vendor.n(!_ctx.form.degree ? "is-empty" : ""),
  243. g: common_vendor.o((...args) => _ctx.openPicker && _ctx.openPicker(...args)),
  244. h: !_ctx.form.major
  245. }, !_ctx.form.major ? {} : {}, {
  246. i: _ctx.form.major,
  247. j: common_vendor.o(($event) => _ctx.form.major = $event.detail.value),
  248. k: !_ctx.form.startTime || !_ctx.form.endTime
  249. }, !_ctx.form.startTime || !_ctx.form.endTime ? {} : {}, {
  250. l: common_vendor.t(_ctx.form.startTime || "入学时间"),
  251. m: common_vendor.n(!_ctx.form.startTime ? "is-empty" : ""),
  252. n: common_vendor.o(($event) => _ctx.openDatePicker("start")),
  253. o: common_vendor.t(_ctx.form.endTime || "毕业时间"),
  254. p: common_vendor.n(!_ctx.form.endTime ? "is-empty" : ""),
  255. q: common_vendor.o(($event) => _ctx.openDatePicker("end")),
  256. r: _ctx.form.desc,
  257. s: common_vendor.o(($event) => _ctx.form.desc = $event.detail.value),
  258. t: _ctx.isEdit
  259. }, _ctx.isEdit ? {} : {}, {
  260. v: !_ctx.isComplete ? 1 : "",
  261. w: common_vendor.o((...args) => _ctx.saveForm && _ctx.saveForm(...args)),
  262. x: _ctx.showPicker
  263. }, _ctx.showPicker ? {
  264. y: common_vendor.o((...args) => _ctx.closePicker && _ctx.closePicker(...args)),
  265. z: common_vendor.o((...args) => _ctx.closePicker && _ctx.closePicker(...args)),
  266. A: common_vendor.o((...args) => _ctx.confirmPicker && _ctx.confirmPicker(...args)),
  267. B: common_vendor.f(_ctx.degreeOptions, (item, index, i0) => {
  268. return {
  269. a: common_vendor.t(item),
  270. b: index
  271. };
  272. }),
  273. C: common_vendor.f(_ctx.typeOptions, (item, index, i0) => {
  274. return {
  275. a: common_vendor.t(item),
  276. b: index
  277. };
  278. }),
  279. D: _ctx.pickerValue,
  280. E: common_vendor.o((...args) => _ctx.onPickerChange && _ctx.onPickerChange(...args)),
  281. F: common_vendor.o(() => {
  282. })
  283. } : {}, {
  284. G: _ctx.showDatePicker
  285. }, _ctx.showDatePicker ? {
  286. H: common_vendor.o((...args) => _ctx.closeDatePicker && _ctx.closeDatePicker(...args)),
  287. I: common_vendor.o((...args) => _ctx.closeDatePicker && _ctx.closeDatePicker(...args)),
  288. J: common_vendor.t(_ctx.datePickerType === "start" ? "入学时间" : "毕业时间"),
  289. K: common_vendor.o((...args) => _ctx.confirmDatePicker && _ctx.confirmDatePicker(...args)),
  290. L: common_vendor.f(_ctx.yearOptions, (item, index, i0) => {
  291. return {
  292. a: common_vendor.t(item),
  293. b: index
  294. };
  295. }),
  296. M: common_vendor.f(_ctx.monthOptions, (item, index, i0) => {
  297. return {
  298. a: common_vendor.t(item),
  299. b: index
  300. };
  301. }),
  302. N: _ctx.datePickerValue,
  303. O: common_vendor.o((...args) => _ctx.onDatePickerChange && _ctx.onDatePickerChange(...args)),
  304. P: common_vendor.o(() => {
  305. })
  306. } : {});
  307. }
  308. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-561b1502"]]);
  309. wx.createPage(MiniProgramPage);
  310. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/experience/add-education.js.map