job-detail.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. title: data.data.title || "",
  73. salary: data.data.salary_range ? `${data.data.salary_range}/月` : "",
  74. department: `${data.data.department || ""} ${data.data.job_type === 1 ? "全职" : "兼职"}`,
  75. location: data.data.location || "",
  76. experience: data.data.work_experience_required || "不限",
  77. benefits: data.data.competency_tags || ["五险一金", "带薪年假", "定期体检"],
  78. description: [
  79. {
  80. subtitle: "岗位要求",
  81. items: descriptionItems
  82. }
  83. ]
  84. };
  85. } else {
  86. common_vendor.index.showToast({
  87. title: "获取职位详情失败",
  88. icon: "none"
  89. });
  90. }
  91. } catch (e) {
  92. console.error("获取职位详情失败:", e);
  93. common_vendor.index.showToast({
  94. title: "获取职位详情失败",
  95. icon: "none"
  96. });
  97. }
  98. },
  99. checkLogin() {
  100. const userInfo = common_vendor.index.getStorageSync("userInfo");
  101. if (!userInfo) {
  102. common_vendor.index.showToast({
  103. title: "请先登录",
  104. icon: "none"
  105. });
  106. return false;
  107. }
  108. return true;
  109. },
  110. async startInterview() {
  111. if (!this.checkLogin()) {
  112. return;
  113. }
  114. try {
  115. common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.jobDetail));
  116. const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  117. const response = await api_user.applyJob({
  118. job_id: this.jobId,
  119. tenant_id: 1,
  120. openid: userInfo.openid
  121. });
  122. if (response && response.id) {
  123. common_vendor.index.setStorageSync("appId", response.id);
  124. try {
  125. userInfo.appId = response.id;
  126. common_vendor.index.setStorageSync("userInfo", JSON.stringify(userInfo));
  127. } catch (e) {
  128. console.error("更新用户信息失败:", e);
  129. }
  130. common_vendor.index.navigateTo({
  131. url: "/pages/Personal/Personal",
  132. fail: (err) => {
  133. console.error("页面跳转失败:", err);
  134. common_vendor.index.showToast({
  135. title: "页面跳转失败",
  136. icon: "none"
  137. });
  138. }
  139. });
  140. }
  141. } catch (err) {
  142. console.error("申请职位失败:", err);
  143. common_vendor.index.showToast({
  144. title: "申请职位失败,请重试",
  145. icon: "none"
  146. });
  147. }
  148. }
  149. }
  150. };
  151. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  152. return {
  153. a: common_vendor.t($data.jobDetail.title),
  154. b: common_vendor.t($data.jobDetail.salary),
  155. c: common_vendor.t($data.jobDetail.department),
  156. d: common_vendor.t($data.jobDetail.location),
  157. e: common_vendor.t($data.jobDetail.experience),
  158. f: common_vendor.f($data.jobDetail.description[0].items, (item, index, i0) => {
  159. return {
  160. a: common_vendor.t(item),
  161. b: index
  162. };
  163. }),
  164. g: common_vendor.o((...args) => $options.startInterview && $options.startInterview(...args))
  165. };
  166. }
  167. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2bde8e2a"]]);
  168. wx.createPage(MiniProgramPage);