offer.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const api_offer = require("../../api/offer.js");
  5. const utils_request = require("../../utils/request.js");
  6. const _sfc_main = {
  7. __name: "offer",
  8. setup(__props) {
  9. const showAcceptModal = common_vendor.ref(false);
  10. const showRejectModal = common_vendor.ref(false);
  11. const countdown = common_vendor.ref(10);
  12. let timer = null;
  13. const currentOffer = common_vendor.ref(null);
  14. const offers = common_vendor.ref([]);
  15. const loading = common_vendor.ref(false);
  16. const protocolHtml = common_vendor.ref("");
  17. const loadOfferConfig = async () => {
  18. try {
  19. const res = await utils_request.request({ url: "/miniapp/auth/agreement?type=offer", method: "GET" });
  20. if (res.code === 200 && res.data && res.data.content) {
  21. protocolHtml.value = res.data.content;
  22. }
  23. } catch (e) {
  24. common_vendor.index.__f__("error", "at pages/my/offer.vue:122", "获取Offer协议失败", e);
  25. }
  26. };
  27. const fetchOfferList = async () => {
  28. loading.value = true;
  29. try {
  30. const res = await api_offer.getOfferList();
  31. if (res.code === 200) {
  32. offers.value = res.data.map((item) => ({
  33. id: item.id,
  34. jobName: item.postName || "未知岗位",
  35. company: item.companyName || "未知企业",
  36. fileName: item.offerFileName || "offer.pdf",
  37. fileUrl: item.offerFileUrl,
  38. studentStatus: item.studentStatus || "pending",
  39. enterpriseStatus: item.enterpriseStatus || "pending",
  40. statusText: getStatusText(item.studentStatus, item.enterpriseStatus),
  41. status: item.studentStatus === "pending" ? "pending" : item.studentStatus,
  42. offerTime: item.offerTime,
  43. createTime: formatTime(item.createTime)
  44. }));
  45. }
  46. } catch (error) {
  47. common_vendor.index.showToast({ title: "获取Offer列表失败", icon: "none" });
  48. } finally {
  49. loading.value = false;
  50. }
  51. };
  52. const formatTime = (time) => {
  53. if (!time)
  54. return "--";
  55. const d = new Date(time);
  56. const year = d.getFullYear();
  57. const month = String(d.getMonth() + 1).padStart(2, "0");
  58. const day = String(d.getDate()).padStart(2, "0");
  59. const hour = String(d.getHours()).padStart(2, "0");
  60. const minute = String(d.getMinutes()).padStart(2, "0");
  61. return `${year}-${month}-${day} ${hour}:${minute}`;
  62. };
  63. const getStatusBadge = (offer) => {
  64. if (offer.enterpriseStatus === "pending")
  65. return "审核中";
  66. if (offer.enterpriseStatus === "adopted")
  67. return "已录用";
  68. if (offer.enterpriseStatus === "rejected")
  69. return "未通过";
  70. return "未知";
  71. };
  72. const getResultDesc = (enterpriseStatus) => {
  73. switch (enterpriseStatus) {
  74. case "adopted":
  75. return "企业已录用,请确认Offer";
  76. case "rejected":
  77. return "很遗憾,该岗位暂不匹配";
  78. default:
  79. return "";
  80. }
  81. };
  82. const getStatusText = (studentStatus, enterpriseStatus) => {
  83. if (enterpriseStatus === "rejected")
  84. return "已拒绝";
  85. if (studentStatus === "accepted")
  86. return "已接受";
  87. if (studentStatus === "rejected")
  88. return "已拒绝";
  89. return "待确认";
  90. };
  91. const handleAccept = (offer) => {
  92. currentOffer.value = offer;
  93. showAcceptModal.value = true;
  94. startCountdown();
  95. };
  96. const handleReject = (offer) => {
  97. currentOffer.value = offer;
  98. showRejectModal.value = true;
  99. };
  100. const startCountdown = () => {
  101. countdown.value = 10;
  102. if (timer)
  103. clearInterval(timer);
  104. timer = setInterval(() => {
  105. if (countdown.value > 0) {
  106. countdown.value--;
  107. } else {
  108. clearInterval(timer);
  109. }
  110. }, 1e3);
  111. };
  112. const confirmAccept = async () => {
  113. if (!currentOffer.value)
  114. return;
  115. try {
  116. const res = await api_offer.acceptOffer(currentOffer.value.id);
  117. if (res.code === 200) {
  118. common_vendor.index.showToast({ title: "已接受Offer", icon: "success" });
  119. fetchOfferList();
  120. } else {
  121. common_vendor.index.showToast({ title: res.msg || "操作失败", icon: "none" });
  122. }
  123. } catch (error) {
  124. common_vendor.index.showToast({ title: "操作失败,请重试", icon: "none" });
  125. } finally {
  126. showAcceptModal.value = false;
  127. }
  128. };
  129. const confirmReject = async () => {
  130. if (!currentOffer.value)
  131. return;
  132. try {
  133. const res = await api_offer.rejectOffer(currentOffer.value.id);
  134. if (res.code === 200) {
  135. common_vendor.index.showToast({ title: "已拒绝Offer", icon: "none" });
  136. fetchOfferList();
  137. } else {
  138. common_vendor.index.showToast({ title: res.msg || "操作失败", icon: "none" });
  139. }
  140. } catch (error) {
  141. common_vendor.index.showToast({ title: "操作失败,请重试", icon: "none" });
  142. } finally {
  143. showRejectModal.value = false;
  144. }
  145. };
  146. common_vendor.onMounted(() => {
  147. loadOfferConfig();
  148. fetchOfferList();
  149. });
  150. const openFile = (url) => {
  151. if (!url) {
  152. common_vendor.index.showToast({ title: "文件链接无效", icon: "none" });
  153. return;
  154. }
  155. const getFileType = (fileUrl) => {
  156. const match = fileUrl.match(/\.(\w+)(\?|$)/);
  157. return match ? match[1].toLowerCase() : "pdf";
  158. };
  159. const fileType = getFileType(url);
  160. common_vendor.index.showLoading({ title: "加载中..." });
  161. common_vendor.index.downloadFile({
  162. url,
  163. success: (res) => {
  164. if (res.statusCode === 200) {
  165. const filePath = res.tempFilePath;
  166. common_vendor.index.openDocument({
  167. filePath,
  168. fileType,
  169. showMenu: true,
  170. success: () => {
  171. common_vendor.index.hideLoading();
  172. },
  173. fail: (err) => {
  174. common_vendor.index.hideLoading();
  175. common_vendor.index.showToast({ title: "预览失败", icon: "none" });
  176. }
  177. });
  178. }
  179. },
  180. fail: (err) => {
  181. common_vendor.index.hideLoading();
  182. common_vendor.index.showToast({ title: "下载失败", icon: "none" });
  183. }
  184. });
  185. };
  186. return (_ctx, _cache) => {
  187. return common_vendor.e({
  188. a: loading.value
  189. }, loading.value ? {} : offers.value.length === 0 ? {
  190. c: common_assets._imports_0$12
  191. } : {
  192. d: common_vendor.f(offers.value, (offer, index, i0) => {
  193. return common_vendor.e({
  194. a: common_vendor.t(offer.company),
  195. b: common_vendor.t(offer.jobName),
  196. c: common_vendor.t(getStatusBadge(offer)),
  197. d: common_vendor.n(offer.enterpriseStatus === "pending" ? "pending" : offer.enterpriseStatus === "adopted" ? "adopted" : "rejected"),
  198. e: common_vendor.t(offer.createTime),
  199. f: offer.enterpriseStatus !== "pending"
  200. }, offer.enterpriseStatus !== "pending" ? common_vendor.e({
  201. g: offer.enterpriseStatus === "adopted"
  202. }, offer.enterpriseStatus === "adopted" ? {
  203. h: common_assets._imports_1$3
  204. } : {
  205. i: common_assets._imports_2$6
  206. }, {
  207. j: common_vendor.t(getResultDesc(offer.enterpriseStatus)),
  208. k: common_vendor.n(offer.enterpriseStatus),
  209. l: offer.enterpriseStatus === "adopted" && offer.studentStatus === "pending"
  210. }, offer.enterpriseStatus === "adopted" && offer.studentStatus === "pending" ? {
  211. m: common_vendor.o(($event) => handleReject(offer), index),
  212. n: common_vendor.o(($event) => handleAccept(offer), index)
  213. } : offer.studentStatus !== "pending" ? {
  214. p: common_vendor.t(offer.statusText),
  215. q: common_vendor.n(offer.studentStatus)
  216. } : {}, {
  217. o: offer.studentStatus !== "pending"
  218. }) : {}, {
  219. r: offer.enterpriseStatus === "adopted" && offer.fileUrl
  220. }, offer.enterpriseStatus === "adopted" && offer.fileUrl ? {
  221. s: common_assets._imports_0$9,
  222. t: common_vendor.t(offer.fileName),
  223. v: common_vendor.o(($event) => openFile(offer.fileUrl), index)
  224. } : {}, {
  225. w: index
  226. });
  227. })
  228. }, {
  229. b: offers.value.length === 0,
  230. e: common_vendor.o(fetchOfferList),
  231. f: showAcceptModal.value
  232. }, showAcceptModal.value ? {
  233. g: protocolHtml.value,
  234. h: common_vendor.o(($event) => showAcceptModal.value = false),
  235. i: common_vendor.t(countdown.value > 0 ? countdown.value + "s后确认接受" : "已阅读,确认接受"),
  236. j: countdown.value > 0,
  237. k: common_vendor.o(confirmAccept)
  238. } : {}, {
  239. l: showRejectModal.value
  240. }, showRejectModal.value ? {
  241. m: common_vendor.o(($event) => showRejectModal.value = false),
  242. n: common_vendor.o(confirmReject)
  243. } : {});
  244. };
  245. }
  246. };
  247. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-644b8877"]]);
  248. wx.createPage(MiniProgramPage);
  249. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/offer.js.map