job-detail.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_config = require("../../common/config.js");
  4. const api_user = require("../../api/user.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. jobDetail: {
  9. title: "",
  10. salary: "",
  11. department: "",
  12. location: "",
  13. experience: "",
  14. benefits: [],
  15. description: [
  16. {
  17. subtitle: "岗位要求",
  18. items: []
  19. }
  20. ]
  21. },
  22. selectedJobId: null,
  23. jobId: null
  24. };
  25. },
  26. onLoad(options) {
  27. this.jobId = options.id;
  28. this.getJobDetail(options.id);
  29. try {
  30. const jobDetailStr = common_vendor.index.getStorageSync("currentJobDetail");
  31. if (jobDetailStr) {
  32. const jobData = JSON.parse(jobDetailStr);
  33. this.jobDetail = {
  34. ...this.jobDetail,
  35. title: jobData.title || this.jobDetail.title,
  36. salary: jobData.salary || this.jobDetail.salary,
  37. department: jobData.department || this.jobDetail.department,
  38. location: jobData.location || this.jobDetail.location,
  39. experience: jobData.experience || this.jobDetail.experience,
  40. benefits: jobData.benefits || this.jobDetail.benefits,
  41. description: jobData.description || this.jobDetail.description
  42. };
  43. }
  44. } catch (e) {
  45. console.error("获取职位详情失败:", e);
  46. }
  47. },
  48. methods: {
  49. async getJobDetail(jobId) {
  50. try {
  51. const { data } = await common_vendor.index.request({
  52. url: `${common_config.apiBaseUrl}/api/mini/job/detail?id=${jobId}&tenant_id=1`,
  53. method: "GET"
  54. });
  55. if (data.code === 2e3) {
  56. let descriptionItems = [];
  57. if (data.data.description) {
  58. const liRegex = /<li[^>]*>(.*?)<\/li>/g;
  59. const stripTagsRegex = /<[^>]*>/g;
  60. let match;
  61. while ((match = liRegex.exec(data.data.description)) !== null) {
  62. const text = match[1].replace(stripTagsRegex, "").replace(/&nbsp;/g, " ").trim();
  63. if (text) {
  64. descriptionItems.push(text);
  65. }
  66. }
  67. }
  68. if (data.data.requirements) {
  69. descriptionItems.unshift(data.data.requirements);
  70. }
  71. this.jobDetail = {
  72. id: data.data.id,
  73. title: data.data.title || "",
  74. salary: data.data.salary_range ? `${data.data.salary_range}/月` : "",
  75. department: `${data.data.department || ""} ${data.data.job_type === 1 ? "全职" : "兼职"}`,
  76. location: data.data.location || "",
  77. experience: data.data.work_experience_required || "不限",
  78. benefits: data.data.competency_tags || ["五险一金", "带薪年假", "定期体检"],
  79. description: [
  80. {
  81. subtitle: "岗位要求",
  82. items: descriptionItems
  83. }
  84. ]
  85. };
  86. } else {
  87. common_vendor.index.showToast({
  88. title: "获取职位详情失败",
  89. icon: "none"
  90. });
  91. }
  92. } catch (e) {
  93. console.error("获取职位详情失败:", e);
  94. common_vendor.index.showToast({
  95. title: "获取职位详情失败",
  96. icon: "none"
  97. });
  98. }
  99. },
  100. checkLogin() {
  101. const userInfo = common_vendor.index.getStorageSync("userInfo");
  102. if (!userInfo) {
  103. common_vendor.index.showToast({
  104. title: "请先登录",
  105. icon: "none"
  106. });
  107. return false;
  108. }
  109. return true;
  110. },
  111. async startInterview() {
  112. if (!this.checkLogin()) {
  113. return;
  114. }
  115. try {
  116. common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.jobDetail));
  117. const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  118. const response = await api_user.applyJob({
  119. job_id: this.jobId,
  120. tenant_id: 1,
  121. openid: userInfo.openid
  122. });
  123. if (response && response.id) {
  124. common_vendor.index.setStorageSync("appId", response.id);
  125. try {
  126. userInfo.appId = response.id;
  127. common_vendor.index.setStorageSync("userInfo", JSON.stringify(userInfo));
  128. } catch (e) {
  129. console.error("更新用户信息失败:", e);
  130. }
  131. common_vendor.index.navigateTo({
  132. url: "/pages/Personal/Personal",
  133. fail: (err) => {
  134. console.error("页面跳转失败:", err);
  135. common_vendor.index.showToast({
  136. title: "页面跳转失败",
  137. icon: "none"
  138. });
  139. }
  140. });
  141. }
  142. } catch (err) {
  143. console.error("申请职位失败:", err);
  144. common_vendor.index.showToast({
  145. title: "申请职位失败,请重试",
  146. icon: "none"
  147. });
  148. }
  149. }
  150. }
  151. };
  152. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  153. return {
  154. a: common_vendor.t($data.jobDetail.title),
  155. b: common_vendor.t($data.jobDetail.salary),
  156. c: common_vendor.t($data.jobDetail.department),
  157. d: common_vendor.t($data.jobDetail.location),
  158. e: common_vendor.t($data.jobDetail.experience),
  159. f: common_vendor.f($data.jobDetail.description[0].items, (item, index, i0) => {
  160. return {
  161. a: common_vendor.t(item),
  162. b: index
  163. };
  164. }),
  165. g: common_vendor.o((...args) => $options.startInterview && $options.startInterview(...args))
  166. };
  167. }
  168. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2bde8e2a"]]);
  169. wx.createPage(MiniProgramPage);