select-resume.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const api_student = require("../../api/student.js");
  5. const api_assessment = require("../../api/assessment.js");
  6. const _sfc_main = {
  7. __name: "select-resume",
  8. setup(__props) {
  9. const isLoading = common_vendor.ref(true);
  10. const delivering = common_vendor.ref(false);
  11. const resumeList = common_vendor.ref([]);
  12. const selectedOssId = common_vendor.ref(null);
  13. const postId = common_vendor.ref(null);
  14. common_vendor.onLoad((options) => {
  15. if (options.postId) {
  16. postId.value = options.postId;
  17. }
  18. fetchResumeList();
  19. });
  20. const fetchResumeList = async () => {
  21. try {
  22. isLoading.value = true;
  23. const userInfo = common_vendor.index.getStorageSync("userInfo");
  24. if (!userInfo || !userInfo.studentId) {
  25. common_vendor.index.showToast({ title: "请先登录", icon: "none" });
  26. setTimeout(() => {
  27. common_vendor.index.navigateTo({ url: "/pages/login/login" });
  28. }, 1e3);
  29. return;
  30. }
  31. const res = await api_student.getAppendixList(userInfo.studentId);
  32. if (res && res.code === 200) {
  33. resumeList.value = res.data.map((item) => ({
  34. id: item.id,
  35. name: item.fileName,
  36. url: item.url,
  37. ossId: item.ossId,
  38. fileSize: item.fileSize
  39. }));
  40. if (resumeList.value.length > 0) {
  41. selectedOssId.value = resumeList.value[0].ossId;
  42. }
  43. }
  44. } catch (err) {
  45. common_vendor.index.__f__("error", "at pages/my/select-resume.vue:107", "获取简历列表失败:", err);
  46. common_vendor.index.showToast({ title: "获取简历列表失败", icon: "none" });
  47. } finally {
  48. isLoading.value = false;
  49. }
  50. };
  51. const selectResume = (item) => {
  52. selectedOssId.value = item.ossId;
  53. };
  54. const formatFileSize = (size) => {
  55. if (!size)
  56. return "";
  57. if (size < 1024)
  58. return size + "B";
  59. if (size < 1024 * 1024)
  60. return (size / 1024).toFixed(1) + "KB";
  61. return (size / (1024 * 1024)).toFixed(1) + "MB";
  62. };
  63. const handleDeliver = async () => {
  64. if (!selectedOssId.value || delivering.value)
  65. return;
  66. const userInfo = common_vendor.index.getStorageSync("userInfo");
  67. if (!userInfo || !userInfo.studentId) {
  68. common_vendor.index.showToast({ title: "请先登录", icon: "none" });
  69. return;
  70. }
  71. try {
  72. delivering.value = true;
  73. common_vendor.index.showLoading({ title: "投递中..." });
  74. const res = await api_assessment.applyPosition({
  75. postId: postId.value,
  76. resumeOssId: selectedOssId.value
  77. });
  78. common_vendor.index.hideLoading();
  79. if (res.code === 200) {
  80. common_vendor.index.setStorageSync(`candidate_applied_${postId.value}`, true);
  81. common_vendor.index.showToast({ title: "投递成功", icon: "success" });
  82. setTimeout(() => {
  83. const pages = getCurrentPages();
  84. if (pages.length > 1) {
  85. common_vendor.index.$emit("resume_delivered", { postId: postId.value });
  86. common_vendor.index.navigateBack();
  87. }
  88. }, 1500);
  89. } else if (res.msg && res.msg.includes("已投递")) {
  90. common_vendor.index.setStorageSync(`candidate_applied_${postId.value}`, true);
  91. common_vendor.index.showToast({ title: "您已投递过该岗位", icon: "none" });
  92. setTimeout(() => {
  93. common_vendor.index.$emit("resume_delivered", { postId: postId.value });
  94. common_vendor.index.navigateBack();
  95. }, 1500);
  96. } else {
  97. common_vendor.index.showToast({ title: res.msg || "投递失败", icon: "none" });
  98. }
  99. } catch (err) {
  100. common_vendor.index.hideLoading();
  101. common_vendor.index.__f__("error", "at pages/my/select-resume.vue:166", "投递失败:", err);
  102. const errMsg = String((err == null ? void 0 : err.msg) || (err == null ? void 0 : err.message) || "");
  103. if (errMsg.includes("已投递")) {
  104. common_vendor.index.setStorageSync(`candidate_applied_${postId.value}`, true);
  105. common_vendor.index.showToast({ title: "您已投递过该岗位", icon: "none" });
  106. setTimeout(() => {
  107. common_vendor.index.$emit("resume_delivered", { postId: postId.value });
  108. common_vendor.index.navigateBack();
  109. }, 1500);
  110. } else {
  111. common_vendor.index.showToast({ title: "网络错误,投递失败", icon: "none" });
  112. }
  113. } finally {
  114. delivering.value = false;
  115. }
  116. };
  117. const goToUpload = () => {
  118. common_vendor.index.navigateBack();
  119. };
  120. return (_ctx, _cache) => {
  121. return common_vendor.e({
  122. a: isLoading.value
  123. }, isLoading.value ? {} : resumeList.value.length > 0 ? {
  124. c: common_vendor.f(resumeList.value, (item, idx, i0) => {
  125. return common_vendor.e({
  126. a: common_vendor.t(item.name),
  127. b: item.fileSize
  128. }, item.fileSize ? {
  129. c: common_vendor.t(formatFileSize(item.fileSize))
  130. } : {}, {
  131. d: selectedOssId.value === item.ossId
  132. }, selectedOssId.value === item.ossId ? {} : {}, {
  133. e: selectedOssId.value === item.ossId ? 1 : "",
  134. f: item.id,
  135. g: common_vendor.o(($event) => selectResume(item), item.id)
  136. });
  137. }),
  138. d: common_assets._imports_0$9
  139. } : common_vendor.e({}, {
  140. f: common_vendor.o(goToUpload)
  141. }), {
  142. b: resumeList.value.length > 0,
  143. g: resumeList.value.length > 0
  144. }, resumeList.value.length > 0 ? {
  145. h: common_vendor.t(delivering.value ? "投递中..." : "确认投递"),
  146. i: !selectedOssId.value ? 1 : "",
  147. j: common_vendor.o(handleDeliver)
  148. } : {});
  149. };
  150. }
  151. };
  152. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4778e1e1"]]);
  153. wx.createPage(MiniProgramPage);
  154. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/select-resume.js.map