job-detail.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. mapInfo: {
  25. latitude: 0,
  26. longitude: 0,
  27. markers: []
  28. }
  29. };
  30. },
  31. onLoad(options) {
  32. this.jobId = options.id;
  33. this.getJobDetail(options.id);
  34. try {
  35. const jobDetailStr = common_vendor.index.getStorageSync("currentJobDetail");
  36. if (jobDetailStr) {
  37. const jobData = JSON.parse(jobDetailStr);
  38. this.jobDetail = {
  39. ...this.jobDetail,
  40. title: jobData.title || this.jobDetail.title,
  41. salary: jobData.salary || this.jobDetail.salary,
  42. department: jobData.department || this.jobDetail.department,
  43. location: jobData.location || this.jobDetail.location,
  44. experience: jobData.experience || this.jobDetail.experience,
  45. benefits: jobData.benefits || this.jobDetail.benefits,
  46. description: jobData.description || this.jobDetail.description
  47. };
  48. }
  49. } catch (e) {
  50. console.error("获取职位详情失败:", e);
  51. }
  52. },
  53. methods: {
  54. async getJobDetail(jobId) {
  55. try {
  56. const { data } = await common_vendor.index.request({
  57. url: `${common_config.apiBaseUrl}/api/mini/job/detail?id=${jobId}&tenant_id=1`,
  58. method: "GET"
  59. });
  60. if (data.code === 2e3) {
  61. let descriptionItems = [];
  62. if (data.data.description) {
  63. const liRegex = /<li[^>]*>(.*?)<\/li>/g;
  64. const stripTagsRegex = /<[^>]*>/g;
  65. let match;
  66. while ((match = liRegex.exec(data.data.description)) !== null) {
  67. const text = match[1].replace(stripTagsRegex, "").replace(/&nbsp;/g, " ").trim();
  68. if (text) {
  69. descriptionItems.push(text);
  70. }
  71. }
  72. }
  73. if (data.data.requirements) {
  74. descriptionItems.unshift(data.data.requirements);
  75. }
  76. this.jobDetail = {
  77. id: data.data.id,
  78. title: data.data.title || "",
  79. salary: data.data.salary_range ? `${data.data.salary_range}/月` : "",
  80. department: `${data.data.department || ""} ${data.data.job_type === 1 ? "全职" : "兼职"}`,
  81. location: data.data.location || "",
  82. experience: data.data.work_experience_required || "不限",
  83. benefits: data.data.competency_tags || ["五险一金", "带薪年假", "定期体检"],
  84. description: [
  85. {
  86. subtitle: "岗位要求",
  87. items: descriptionItems
  88. }
  89. ]
  90. };
  91. this.updateMapLocation(data.data.location);
  92. } else {
  93. common_vendor.index.showToast({
  94. title: "获取职位详情失败",
  95. icon: "none"
  96. });
  97. }
  98. } catch (e) {
  99. console.error("获取职位详情失败:", e);
  100. common_vendor.index.showToast({
  101. title: "获取职位详情失败",
  102. icon: "none"
  103. });
  104. }
  105. },
  106. checkLogin() {
  107. const userInfo = common_vendor.index.getStorageSync("userInfo");
  108. if (!userInfo) {
  109. common_vendor.index.showToast({
  110. title: "请先登录",
  111. icon: "none"
  112. });
  113. return false;
  114. }
  115. return true;
  116. },
  117. // 获取当前职位配置
  118. getConfig(selectedJobId) {
  119. common_vendor.index.request({
  120. url: `${common_config.apiBaseUrl}/api/job/config/position/${this.jobId}`,
  121. method: "GET",
  122. data: {
  123. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid
  124. },
  125. header: {
  126. "content-type": "application/x-www-form-urlencoded"
  127. },
  128. success: (res) => {
  129. console.log(res);
  130. if (res.statusCode === 200) {
  131. if (res.data.code === 2e3) {
  132. common_vendor.index.setStorageSync("configData", JSON.stringify(res.data.data));
  133. common_vendor.index.navigateTo({
  134. url: "/pages/Personal/Personal",
  135. fail: (err) => {
  136. console.error("页面跳转失败:", err);
  137. common_vendor.index.showToast({
  138. title: "页面跳转失败",
  139. icon: "none"
  140. });
  141. }
  142. });
  143. }
  144. } else {
  145. common_vendor.index.hideLoading();
  146. }
  147. },
  148. fail: (err) => {
  149. common_vendor.index.hideLoading();
  150. common_vendor.index.showToast({
  151. title: "网络错误,请稍后重试",
  152. icon: "none"
  153. });
  154. }
  155. });
  156. },
  157. async startInterview() {
  158. if (!this.checkLogin()) {
  159. return;
  160. }
  161. try {
  162. common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.jobDetail));
  163. const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  164. const response = await api_user.applyJob({
  165. job_id: this.jobId,
  166. tenant_id: 1,
  167. openid: userInfo.openid
  168. });
  169. if (response && response.id) {
  170. common_vendor.index.setStorageSync("appId", response.id);
  171. try {
  172. userInfo.appId = response.id;
  173. common_vendor.index.setStorageSync("userInfo", JSON.stringify(userInfo));
  174. } catch (e) {
  175. console.error("更新用户信息失败:", e);
  176. }
  177. this.getConfig(userInfo.appId);
  178. }
  179. } catch (err) {
  180. console.error("申请职位失败:", err);
  181. common_vendor.index.showToast({
  182. title: "申请职位失败,请重试",
  183. icon: "none"
  184. });
  185. }
  186. },
  187. hasHtmlTags(text) {
  188. const htmlRegex = /<[^>]*>/;
  189. return htmlRegex.test(text);
  190. },
  191. formatLocation(location) {
  192. if (!location)
  193. return "";
  194. if (typeof location === "string" && location.startsWith("[")) {
  195. try {
  196. const locationArray = JSON.parse(location.replace(/'/g, '"'));
  197. return locationArray.join(" ");
  198. } catch (e) {
  199. console.error("解析location失败:", e);
  200. return location;
  201. }
  202. }
  203. if (Array.isArray(location)) {
  204. return location.join(" ");
  205. }
  206. if (typeof location === "object" && location !== null) {
  207. const { province, city, district } = location;
  208. if (province && city) {
  209. return province + " " + city + (district ? " " + district : "");
  210. }
  211. }
  212. return location;
  213. },
  214. // 更新地图位置信息
  215. async updateMapLocation(location) {
  216. try {
  217. let addressStr = "";
  218. if (typeof location === "string" && location.startsWith("[")) {
  219. try {
  220. const locationArray = JSON.parse(location.replace(/'/g, '"'));
  221. addressStr = locationArray.join("");
  222. } catch (e) {
  223. addressStr = location;
  224. }
  225. } else if (Array.isArray(location)) {
  226. addressStr = location.join("");
  227. } else if (typeof location === "object" && location !== null) {
  228. const { province, city, district } = location;
  229. addressStr = `${province || ""}${city || ""}${district || ""}`;
  230. } else {
  231. addressStr = location;
  232. }
  233. common_vendor.index.request({
  234. url: `https://apis.map.qq.com/ws/geocoder/v1/?address=${encodeURIComponent(addressStr)}&key=ZS4BZ-NKAA7-4VLXR-PHVI4-HAGPH-Z4FJ3`,
  235. // 需要替换为实际的地图Key
  236. success: (res) => {
  237. if (res.data.status === 0) {
  238. const { lat, lng } = res.data.result.location;
  239. this.mapInfo.latitude = lat;
  240. this.mapInfo.longitude = lng;
  241. this.mapInfo.markers = [{
  242. id: 1,
  243. latitude: lat,
  244. longitude: lng,
  245. title: addressStr
  246. }];
  247. } else {
  248. console.error("地址解析失败:", res);
  249. }
  250. },
  251. fail: (err) => {
  252. console.error("地址解析请求失败:", err);
  253. }
  254. });
  255. } catch (error) {
  256. console.error("更新地图位置失败:", error);
  257. }
  258. },
  259. openLocation() {
  260. if (this.mapInfo.latitude && this.mapInfo.longitude) {
  261. common_vendor.index.openLocation({
  262. latitude: this.mapInfo.latitude,
  263. longitude: this.mapInfo.longitude,
  264. name: this.jobDetail.title,
  265. address: this.formatLocation(this.jobDetail.location),
  266. success: function() {
  267. console.log("导航打开成功");
  268. },
  269. fail: function(err) {
  270. console.error("导航打开失败:", err);
  271. common_vendor.index.showToast({
  272. title: "导航打开失败",
  273. icon: "none"
  274. });
  275. }
  276. });
  277. } else {
  278. common_vendor.index.showToast({
  279. title: "暂无位置信息",
  280. icon: "none"
  281. });
  282. }
  283. }
  284. }
  285. };
  286. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  287. return {
  288. a: common_vendor.t($data.jobDetail.title),
  289. b: common_vendor.t($data.jobDetail.salary),
  290. c: common_vendor.t($data.jobDetail.department),
  291. d: common_vendor.t($options.formatLocation($data.jobDetail.location)),
  292. e: common_vendor.t($data.jobDetail.experience),
  293. f: $data.mapInfo.latitude,
  294. g: $data.mapInfo.longitude,
  295. h: $data.mapInfo.markers,
  296. i: common_vendor.o((...args) => $options.openLocation && $options.openLocation(...args)),
  297. j: common_vendor.f($data.jobDetail.description[0].items, (item, index, i0) => {
  298. return common_vendor.e({
  299. a: $options.hasHtmlTags(item)
  300. }, $options.hasHtmlTags(item) ? {
  301. b: item
  302. } : {
  303. c: common_vendor.t(item)
  304. }, {
  305. d: index
  306. });
  307. }),
  308. k: common_vendor.o((...args) => $options.startInterview && $options.startInterview(...args))
  309. };
  310. }
  311. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2bde8e2a"]]);
  312. wx.createPage(MiniProgramPage);