index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const api_position = require("../../api/position.js");
  5. const api_message = require("../../api/message.js");
  6. const api_collection = require("../../api/collection.js");
  7. const api_assessment = require("../../api/assessment.js");
  8. const api_order = require("../../api/order.js");
  9. const _sfc_main = {
  10. __name: "index",
  11. setup(__props) {
  12. const isCollected = common_vendor.ref(false);
  13. const collectionId = common_vendor.ref(null);
  14. const jobInfo = common_vendor.ref({});
  15. const tags = common_vendor.ref([]);
  16. const jobState = common_vendor.ref("initial");
  17. const btnText = common_vendor.computed(() => {
  18. switch (jobState.value) {
  19. case "initial":
  20. return "咨询";
  21. case "paid":
  22. return "开始测评";
  23. case "assessed":
  24. return "投递简历";
  25. case "added":
  26. return "已投递";
  27. default:
  28. return "咨询";
  29. }
  30. });
  31. const positionId = common_vendor.ref(null);
  32. const checkState = async () => {
  33. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:140", "Checking job state for position:", positionId.value);
  34. const userInfo = common_vendor.index.getStorageSync("userInfo");
  35. if (!userInfo || !userInfo.studentId || !positionId.value) {
  36. jobState.value = "initial";
  37. return;
  38. }
  39. const appliedKey = `candidate_applied_${positionId.value}`;
  40. if (common_vendor.index.getStorageSync(appliedKey)) {
  41. jobState.value = "added";
  42. return;
  43. }
  44. try {
  45. if (!jobInfo.value || !jobInfo.value.postName) {
  46. const jobRes = await api_position.getPositionDetail(positionId.value);
  47. if (jobRes.code === 200 && jobRes.data) {
  48. jobInfo.value = jobRes.data;
  49. }
  50. }
  51. const evalRes = await api_assessment.getAssessmentList({ positionId: positionId.value, pageNum: 1, pageSize: 100 });
  52. const fallbackPaidKey = `audit_paid_pos_${positionId.value}`;
  53. const isFallbackPaid = !!common_vendor.index.getStorageSync(fallbackPaidKey);
  54. let isAnyEvalPaid = evalRes.code === 200 && evalRes.rows ? evalRes.rows.some((e) => common_vendor.index.getStorageSync(`audit_paid_${e.id}`)) || isFallbackPaid : isFallbackPaid || !!common_vendor.index.getStorageSync(`audit_paid_${positionId.value}`);
  55. if (!isAnyEvalPaid) {
  56. try {
  57. const orderRes = await api_order.listOrder({
  58. orderStatus: 1,
  59. buyerId: userInfo.studentId
  60. });
  61. if (orderRes.code === 200 && orderRes.rows) {
  62. isAnyEvalPaid = orderRes.rows.some((order) => {
  63. var _a;
  64. const remark = order.remark || "";
  65. const matchPost = ((_a = jobInfo.value) == null ? void 0 : _a.postName) && remark.includes(jobInfo.value.postName);
  66. const matchEval = evalRes.rows && evalRes.rows.some((e) => e.evaluationName && remark.includes(e.evaluationName));
  67. return matchPost || matchEval;
  68. });
  69. }
  70. } catch (e) {
  71. common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:191", "[JobDetail] 订单校验失败:", e);
  72. }
  73. }
  74. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:195", "[JobDetail] 支付状态最终综合判定:", isAnyEvalPaid);
  75. if (evalRes.code !== 200 || !evalRes.rows || evalRes.rows.length === 0) {
  76. jobState.value = isAnyEvalPaid ? "paid" : "initial";
  77. return;
  78. }
  79. linkedAssessmentId.value = evalRes.rows[0].id;
  80. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:205", "[JobDetail] 关联测评ID:", linkedAssessmentId.value);
  81. const recordRes = await api_assessment.getAssessmentRecordList(userInfo.studentId);
  82. if (recordRes.code !== 200 || !recordRes.data) {
  83. jobState.value = isAnyEvalPaid ? "paid" : "initial";
  84. return;
  85. }
  86. const evaluationIds = evalRes.rows.map((e) => e.id);
  87. const passedRecord = recordRes.data.find(
  88. (r) => r.finalResult === "1" && evaluationIds.includes(r.evaluationId)
  89. );
  90. if (passedRecord) {
  91. jobState.value = "assessed";
  92. } else if (isAnyEvalPaid) {
  93. jobState.value = "paid";
  94. } else {
  95. jobState.value = "initial";
  96. }
  97. } catch (err) {
  98. common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:231", "检查状态失败:", err);
  99. jobState.value = "initial";
  100. }
  101. };
  102. const latitude = common_vendor.ref(31.22863);
  103. const longitude = common_vendor.ref(121.45039);
  104. const markers = common_vendor.ref([]);
  105. const fetchDetail = async (id) => {
  106. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:241", "fetchDetail called with id:", id);
  107. common_vendor.index.showLoading({ title: "加载中..." });
  108. try {
  109. const res = await api_position.getPositionDetail(id);
  110. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:245", "getPositionDetail响应:", res);
  111. if (res.code === 200 && res.data) {
  112. jobInfo.value = res.data;
  113. positionId.value = res.data.id;
  114. const data = res.data;
  115. if (data.latitude && data.longitude) {
  116. latitude.value = parseFloat(data.latitude);
  117. longitude.value = parseFloat(data.longitude);
  118. markers.value = [{
  119. id: 1,
  120. latitude: latitude.value,
  121. longitude: longitude.value,
  122. title: data.postName || "办公地点",
  123. iconPath: "/static/icons/location.svg",
  124. width: 32,
  125. height: 32,
  126. callout: {
  127. content: data.workAddress || data.workProvince + data.workCity + data.workDistrict,
  128. color: "#333333",
  129. fontSize: 12,
  130. borderRadius: 8,
  131. padding: 8,
  132. bgColor: "#ffffff",
  133. display: "ALWAYS",
  134. boxShadow: "0 4rpx 12rpx rgba(0,0,0,0.1)"
  135. }
  136. }];
  137. } else {
  138. markers.value = [];
  139. }
  140. let t = [];
  141. if (data.postTypeLabel)
  142. t.push(data.postTypeLabel);
  143. if (data.schoolRequirementLabel)
  144. t.push(data.schoolRequirementLabel);
  145. if (data.gradeRequirementLabel)
  146. t.push(data.gradeRequirementLabel);
  147. if (data.welfareTags) {
  148. t.push(...data.welfareTags.split(",").filter(Boolean));
  149. }
  150. tags.value = t;
  151. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:289", "准备检查收藏状态, id:", id);
  152. checkCollectionStatus(id);
  153. }
  154. } catch (err) {
  155. common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:293", "获取岗位详情失败:", err);
  156. } finally {
  157. common_vendor.index.hideLoading();
  158. }
  159. };
  160. const checkCollectionStatus = async (id) => {
  161. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:301", "checkCollectionStatus called with id:", id);
  162. const userInfo = common_vendor.index.getStorageSync("userInfo");
  163. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:303", "checkCollectionStatus userInfo:", userInfo);
  164. if (!userInfo || !userInfo.studentId) {
  165. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:305", "checkCollectionStatus: 用户未登录");
  166. return;
  167. }
  168. try {
  169. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:310", "调用checkCollection API, studentId:", userInfo.studentId, "targetId:", id, "type: job");
  170. const res = await api_collection.checkCollection(userInfo.studentId, id, "job");
  171. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:312", "checkCollection API响应:", res);
  172. if (res.code === 200 && res.data) {
  173. isCollected.value = true;
  174. collectionId.value = res.data.id;
  175. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:316", "设置为已收藏, collectionId:", res.data.id);
  176. } else {
  177. isCollected.value = false;
  178. collectionId.value = null;
  179. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:320", "设置为未收藏");
  180. }
  181. } catch (err) {
  182. common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:323", "检查收藏状态失败", err);
  183. }
  184. };
  185. const toggleCollect = async () => {
  186. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:329", "toggleCollect clicked");
  187. const userInfo = common_vendor.index.getStorageSync("userInfo");
  188. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:331", "userInfo:", userInfo);
  189. if (!userInfo || !userInfo.studentId) {
  190. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:334", "用户未登录");
  191. common_vendor.index.showToast({ title: "请先登录", icon: "none" });
  192. setTimeout(() => {
  193. common_vendor.index.navigateTo({ url: "/pages/login/login" });
  194. }, 1e3);
  195. return;
  196. }
  197. if (!jobInfo.value.id) {
  198. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:343", "jobInfo.value.id 为空:", jobInfo.value);
  199. return;
  200. }
  201. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:347", "准备发送收藏请求, jobInfo.value.id:", jobInfo.value.id);
  202. common_vendor.index.showLoading({ title: isCollected.value ? "取消收藏中..." : "收藏中..." });
  203. try {
  204. if (isCollected.value) {
  205. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:353", "取消收藏, collectionId:", collectionId.value);
  206. if (collectionId.value) {
  207. const res = await api_collection.delCollection(collectionId.value);
  208. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:356", "取消收藏响应:", res);
  209. if (res.code === 200) {
  210. isCollected.value = false;
  211. collectionId.value = null;
  212. common_vendor.index.showToast({ title: "已取消收藏", icon: "none" });
  213. }
  214. }
  215. } else {
  216. const requestData = {
  217. studentId: userInfo.studentId,
  218. targetId: jobInfo.value.id,
  219. type: "job"
  220. };
  221. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:370", "添加收藏请求数据:", requestData);
  222. const res = await api_collection.addCollection(requestData);
  223. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:372", "添加收藏响应:", res);
  224. if (res.code === 200) {
  225. isCollected.value = true;
  226. checkCollectionStatus(jobInfo.value.id);
  227. common_vendor.index.showToast({ title: "收藏成功", icon: "success" });
  228. } else {
  229. common_vendor.index.showToast({ title: res.msg || "收藏失败", icon: "none" });
  230. }
  231. }
  232. } catch (err) {
  233. common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:383", "操作收藏失败", err);
  234. common_vendor.index.showToast({ title: "操作失败", icon: "none" });
  235. } finally {
  236. common_vendor.index.hideLoading();
  237. }
  238. };
  239. common_vendor.onLoad((options) => {
  240. if (options.id) {
  241. positionId.value = options.id;
  242. fetchDetail(options.id);
  243. }
  244. common_vendor.index.$on("payment_done", (data) => {
  245. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:397", "收到 payment_done 事件:", data);
  246. checkState();
  247. });
  248. common_vendor.index.$on("resume_delivered", (data) => {
  249. common_vendor.index.__f__("log", "at pages/jobdetail/index.vue:402", "收到 resume_delivered 事件:", data);
  250. if (data && data.postId == positionId.value) {
  251. jobState.value = "added";
  252. }
  253. });
  254. });
  255. common_vendor.onShow(() => {
  256. if (positionId.value) {
  257. checkState();
  258. }
  259. });
  260. common_vendor.onUnmounted(() => {
  261. common_vendor.index.$off("payment_done");
  262. common_vendor.index.$off("resume_delivered");
  263. });
  264. const handleMainAction = async () => {
  265. if (jobState.value === "initial") {
  266. try {
  267. common_vendor.index.showLoading({ title: "正在连接客服..." });
  268. const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
  269. const userId = userInfo.studentId || null;
  270. const userName = userInfo.name || "用户";
  271. const userAvatar = userInfo.avatarUrl || "/static/images/user_avatar.svg";
  272. const res = await api_message.createOrGetSession({
  273. sessionType: 1,
  274. fromUserId: userId,
  275. fromUserName: userName,
  276. fromUserAvatar: userAvatar,
  277. sourceId: "job_" + positionId.value
  278. });
  279. common_vendor.index.hideLoading();
  280. if (res.data) {
  281. const session = res.data;
  282. common_vendor.index.navigateTo({
  283. url: `/pages/chat/chat?sessionId=${session.sessionId}&sessionNo=${session.sessionNo || ""}&fromUserId=${userId}&userName=${encodeURIComponent(userName)}&jobName=${encodeURIComponent(jobInfo.value.postName || "")}&type=job&positionId=${positionId.value}&salaryRange=${encodeURIComponent(jobInfo.value.salaryRange || "")}&companyName=${encodeURIComponent(jobInfo.value.companyName || "")}&workCity=${encodeURIComponent(jobInfo.value.workCity || "")}`
  284. });
  285. } else {
  286. common_vendor.index.showToast({ title: "创建会话失败", icon: "none" });
  287. }
  288. } catch (err) {
  289. common_vendor.index.hideLoading();
  290. common_vendor.index.__f__("error", "at pages/jobdetail/index.vue:451", "创建会话失败:", err);
  291. common_vendor.index.showToast({ title: "连接失败,请重试", icon: "none" });
  292. }
  293. } else if (jobState.value === "paid") {
  294. common_vendor.index.navigateTo({
  295. url: `/pages/assessment/remind?family=audit&id=${linkedAssessmentId.value || ""}`
  296. });
  297. } else if (jobState.value === "assessed") {
  298. const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
  299. if (!userInfo.studentId) {
  300. common_vendor.index.showToast({ title: "请先登录", icon: "none" });
  301. setTimeout(() => {
  302. common_vendor.index.navigateTo({ url: "/pages/login/login" });
  303. }, 1e3);
  304. return;
  305. }
  306. common_vendor.index.navigateTo({
  307. url: `/pages/my/select-resume?postId=${positionId.value}`
  308. });
  309. }
  310. };
  311. return (_ctx, _cache) => {
  312. return common_vendor.e({
  313. a: common_vendor.t(jobInfo.value.postName || ""),
  314. b: jobInfo.value.isUrgent === 1
  315. }, jobInfo.value.isUrgent === 1 ? {} : {}, {
  316. c: common_vendor.t(jobInfo.value.salaryRange || "面议"),
  317. d: common_assets._imports_2$2,
  318. e: common_vendor.t(jobInfo.value.workProvince || ""),
  319. f: common_vendor.t(jobInfo.value.workCity ? "·" + jobInfo.value.workCity : ""),
  320. g: common_vendor.t(jobInfo.value.workDistrict ? "·" + jobInfo.value.workDistrict : ""),
  321. h: common_assets._imports_0$2,
  322. i: common_vendor.t(jobInfo.value.recruitNum || 1),
  323. j: common_assets._imports_1$1,
  324. k: common_vendor.t(jobInfo.value.registrationEndDate ? jobInfo.value.registrationEndDate.split(" ")[0] : "长期有效"),
  325. l: jobInfo.value.companyAvatar || "/static/images/hr_avatar.svg",
  326. m: common_vendor.t(jobInfo.value.companyName || "平台推荐"),
  327. n: common_vendor.f(tags.value, (tag, k0, i0) => {
  328. return {
  329. a: common_vendor.t(tag),
  330. b: tag
  331. };
  332. }),
  333. o: jobInfo.value.postDescription
  334. }, jobInfo.value.postDescription ? {
  335. p: jobInfo.value.postDescription
  336. } : {}, {
  337. q: latitude.value,
  338. r: longitude.value,
  339. s: markers.value,
  340. t: jobInfo.value.companyAvatar || "/static/images/logo1.png",
  341. v: common_vendor.t(jobInfo.value.companyName || "未知企业"),
  342. w: isCollected.value ? "/static/icons/star_filled.svg" : "/static/icons/star_hollow.svg",
  343. x: common_vendor.t(isCollected.value ? "已收藏" : "收藏"),
  344. y: common_vendor.o(toggleCollect),
  345. z: common_vendor.t(btnText.value),
  346. A: common_vendor.n(jobState.value),
  347. B: common_vendor.o(handleMainAction)
  348. });
  349. };
  350. }
  351. };
  352. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-dc9d1727"]]);
  353. wx.createPage(MiniProgramPage);
  354. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/jobdetail/index.js.map