index.js 15 KB

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