job-detail.js 5.4 KB

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