job-detail.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. detailed_address: "",
  16. description: [
  17. {
  18. subtitle: "岗位要求",
  19. items: []
  20. }
  21. ]
  22. },
  23. selectedJobId: null,
  24. jobId: null,
  25. mapInfo: {
  26. latitude: 0,
  27. longitude: 0,
  28. markers: []
  29. },
  30. tenant_id: ""
  31. // 租户ID
  32. };
  33. },
  34. onLoad(options) {
  35. this.jobId = options.id;
  36. this.getJobDetail(options.id);
  37. this.getTenantId();
  38. try {
  39. const jobDetailStr = common_vendor.index.getStorageSync("currentJobDetail");
  40. if (jobDetailStr) {
  41. const jobData = JSON.parse(jobDetailStr);
  42. this.jobDetail = {
  43. ...this.jobDetail,
  44. title: jobData.title || this.jobDetail.title,
  45. salary: jobData.salary || this.jobDetail.salary,
  46. department: jobData.department || this.jobDetail.department,
  47. location: jobData.location || this.jobDetail.location,
  48. experience: jobData.experience || this.jobDetail.experience,
  49. benefits: jobData.benefits || this.jobDetail.benefits,
  50. description: jobData.description || this.jobDetail.description,
  51. detailed_address: jobData.detailed_address || this.jobDetail.detailed_address
  52. };
  53. }
  54. } catch (e) {
  55. console.error("获取职位详情失败:", e);
  56. }
  57. },
  58. methods: {
  59. // 获取本地存储的tenant_id
  60. getTenantId() {
  61. const tenantId = common_vendor.index.getStorageSync("tenant_id");
  62. if (tenantId) {
  63. this.tenant_id = tenantId;
  64. return tenantId;
  65. }
  66. return null;
  67. },
  68. async getJobDetail(jobId) {
  69. try {
  70. const { data } = await common_vendor.index.request({
  71. url: `${common_config.apiBaseUrl}/api/mini/job/detail?id=${jobId}&tenant_id=${this.tenant_id || (() => {
  72. try {
  73. const s = common_vendor.index.getStorageSync("userInfo");
  74. return s ? JSON.parse(s).tenant_id || 1 : 1;
  75. } catch {
  76. return 1;
  77. }
  78. })()}`,
  79. method: "GET"
  80. });
  81. if (data.code === 2e3) {
  82. let descriptionItems = [];
  83. if (data.data.description) {
  84. const liRegex = /<li[^>]*>(.*?)<\/li>/g;
  85. const stripTagsRegex = /<[^>]*>/g;
  86. let match;
  87. while ((match = liRegex.exec(data.data.description)) !== null) {
  88. const text = match[1].replace(stripTagsRegex, "").replace(/&nbsp;/g, " ").trim();
  89. if (text) {
  90. descriptionItems.push(text);
  91. }
  92. }
  93. }
  94. if (data.data.requirements) {
  95. descriptionItems.unshift(data.data.requirements);
  96. }
  97. this.jobDetail = {
  98. id: data.data.id,
  99. title: data.data.title || "",
  100. salary: data.data.salary_range ? `${data.data.salary_range}/月` : "",
  101. department: data.data.job_type_name,
  102. //`${data.data.department || ''} ${data.data.job_type === 1 ? '全职' : '兼职'}`,
  103. location: data.data.location || "",
  104. experience: data.data.work_experience_required || "不限",
  105. benefits: data.data.competency_tags || ["五险一金", "带薪年假", "定期体检"],
  106. detailed_address: data.data.detailed_address || "",
  107. description: [
  108. {
  109. subtitle: "岗位要求",
  110. items: descriptionItems
  111. }
  112. ]
  113. };
  114. this.updateMapLocation(data.data.location, data.data.detailed_address);
  115. } else {
  116. common_vendor.index.showToast({
  117. title: "获取职位详情失败",
  118. icon: "none"
  119. });
  120. }
  121. } catch (e) {
  122. console.error("获取职位详情失败:", e);
  123. common_vendor.index.showToast({
  124. title: "获取职位详情失败",
  125. icon: "none"
  126. });
  127. }
  128. },
  129. checkLogin() {
  130. const userInfo = common_vendor.index.getStorageSync("userInfo");
  131. if (!userInfo) {
  132. common_vendor.index.showToast({
  133. title: "请先登录",
  134. icon: "none"
  135. });
  136. return false;
  137. }
  138. return true;
  139. },
  140. // 获取当前职位配置
  141. /* getConfig(selectedJobId){
  142. uni.request({
  143. url: `${apiBaseUrl}/api/job/config/position/${this.jobId}`,
  144. method: 'GET',
  145. data: {
  146. openid: JSON.parse(uni.getStorageSync('userInfo')).openid
  147. },
  148. header: {
  149. 'content-type': 'application/x-www-form-urlencoded'
  150. },
  151. success: (res) => {
  152. // 身份验证成功后,继续提交用户信息
  153. console.log(res);
  154. if (res.statusCode === 200) {
  155. if (res.data.code === 2000) {
  156. uni.setStorageSync('configData', JSON.stringify(res.data.data))
  157. uni.navigateTo({
  158. url: '/pages/Personal/Personal',
  159. fail: (err) => {
  160. console.error('页面跳转失败:', err);
  161. uni.showToast({
  162. title: '页面跳转失败',
  163. icon: 'none'
  164. });
  165. }
  166. });
  167. } else {
  168. }
  169. } else {
  170. uni.hideLoading();
  171. }
  172. },
  173. fail: (err) => {
  174. uni.hideLoading();
  175. uni.showToast({
  176. title: '网络错误,请稍后重试',
  177. icon: 'none'
  178. });
  179. }
  180. });
  181. }, */
  182. // 处理用户信息获取和页面跳转逻辑
  183. handleUserInfoAndNavigation() {
  184. const openid = JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid;
  185. common_vendor.index.request({
  186. url: `${common_config.apiBaseUrl}/api/wechat/user/get_full_info?tenant_id=${this.tenant_id || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || 1}&openid=${openid}`,
  187. method: "GET",
  188. success: (infoRes) => {
  189. if (infoRes.statusCode === 200 && infoRes.data && infoRes.data.data && infoRes.data.data.profile) {
  190. const resumeUrl = infoRes.data.data.profile.resume_url || "";
  191. if (!resumeUrl) {
  192. common_vendor.index.navigateTo({
  193. url: "/pages/uploadResume/uploadResume",
  194. // 假设跳转到上传简历页面
  195. fail: (err) => {
  196. console.error("页面跳转失败:", err);
  197. common_vendor.index.showToast({
  198. title: "页面跳转失败",
  199. icon: "none"
  200. });
  201. }
  202. });
  203. } else {
  204. common_vendor.index.navigateTo({
  205. url: "/pages/Personal/Personal",
  206. fail: (err) => {
  207. console.error("页面跳转失败:", err);
  208. common_vendor.index.showToast({
  209. title: "页面跳转失败",
  210. icon: "none"
  211. });
  212. }
  213. });
  214. }
  215. } else {
  216. common_vendor.index.navigateTo({
  217. url: "/pages/Personal/Personal",
  218. fail: (err) => {
  219. console.error("页面跳转失败:", err);
  220. common_vendor.index.showToast({
  221. title: "页面跳转失败",
  222. icon: "none"
  223. });
  224. }
  225. });
  226. }
  227. },
  228. fail: (err) => {
  229. console.error("获取用户信息失败:", err);
  230. common_vendor.index.navigateTo({
  231. url: "/pages/Personal/Personal",
  232. fail: (err2) => {
  233. console.error("页面跳转失败:", err2);
  234. common_vendor.index.showToast({
  235. title: "页面跳转失败",
  236. icon: "none"
  237. });
  238. }
  239. });
  240. }
  241. });
  242. },
  243. // 获取当前职位配置
  244. getConfig(selectedJobId) {
  245. common_vendor.index.request({
  246. url: `${common_config.apiBaseUrl}/api/job/config/position/${this.jobId}`,
  247. method: "GET",
  248. data: {
  249. openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid
  250. },
  251. header: {
  252. "content-type": "application/x-www-form-urlencoded"
  253. },
  254. success: (res) => {
  255. console.log(res);
  256. if (res.statusCode === 200) {
  257. if (res.data.code === 2e3) {
  258. common_vendor.index.setStorageSync("configData", JSON.stringify(res.data.data));
  259. const configData = res.data.data;
  260. const enableVideoPresentation = (configData == null ? void 0 : configData.enable_video_presentation) || false;
  261. if (enableVideoPresentation) {
  262. const videoUrl = (configData == null ? void 0 : configData.video_presentation_url) || "";
  263. const nextPage = "/pages/Personal/Personal";
  264. common_vendor.index.navigateTo({
  265. url: `/pages/video-briefing/video-briefing?src=${encodeURIComponent(videoUrl)}&next=${encodeURIComponent(nextPage)}`,
  266. fail: (err) => {
  267. console.error("跳转到视频宣讲页面失败:", err);
  268. this.handleUserInfoAndNavigation();
  269. }
  270. });
  271. } else {
  272. this.handleUserInfoAndNavigation();
  273. }
  274. }
  275. } else {
  276. common_vendor.index.hideLoading();
  277. }
  278. },
  279. fail: (err) => {
  280. common_vendor.index.hideLoading();
  281. common_vendor.index.showToast({
  282. title: "网络错误,请稍后重试",
  283. icon: "none"
  284. });
  285. }
  286. });
  287. },
  288. async startInterview() {
  289. if (!this.checkLogin()) {
  290. return;
  291. }
  292. try {
  293. common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.jobDetail));
  294. const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  295. const response = await api_user.applyJob({
  296. job_id: this.jobId,
  297. tenant_id: this.tenant_id || JSON.parse(common_vendor.index.getStorageSync("userInfo")).tenant_id || 1,
  298. openid: userInfo.openid
  299. });
  300. if (response && response.id) {
  301. common_vendor.index.setStorageSync("appId", response.id);
  302. try {
  303. userInfo.appId = response.id;
  304. common_vendor.index.setStorageSync("userInfo", JSON.stringify(userInfo));
  305. } catch (e) {
  306. console.error("更新用户信息失败:", e);
  307. }
  308. this.getConfig(userInfo.appId);
  309. }
  310. } catch (err) {
  311. console.error("申请职位失败:", err);
  312. common_vendor.index.showToast({
  313. title: "申请职位失败,请重试",
  314. icon: "none"
  315. });
  316. }
  317. },
  318. hasHtmlTags(text) {
  319. const htmlRegex = /<[^>]*>/;
  320. return htmlRegex.test(text);
  321. },
  322. formatLocation(location) {
  323. if (!location)
  324. return "";
  325. if (typeof location === "string" && location.startsWith("[")) {
  326. try {
  327. const locationArray = JSON.parse(location.replace(/'/g, '"'));
  328. return locationArray.join(" ") + "" + this.jobDetail.detailed_address || JSON.parse(common_vendor.index.getStorageSync("currentJobDetail")).detailed_address;
  329. } catch (e) {
  330. console.error("解析location失败:", e);
  331. return location;
  332. }
  333. }
  334. if (Array.isArray(location)) {
  335. return location.join(" ") + "" + this.jobDetail.detailed_address || JSON.parse(common_vendor.index.getStorageSync("currentJobDetail")).detailed_address;
  336. }
  337. if (typeof location === "object" && location !== null) {
  338. const { province, city, district } = location;
  339. if (province && city) {
  340. return province + " " + city + (district ? " " + district : "");
  341. }
  342. }
  343. return location + "" + this.jobDetail.detailed_address || JSON.parse(common_vendor.index.getStorageSync("currentJobDetail")).detailed_address;
  344. },
  345. // 更新地图位置信息
  346. async updateMapLocation(location, address) {
  347. try {
  348. let addressStr = "";
  349. if (typeof location === "string" && location.startsWith("[")) {
  350. try {
  351. const locationArray = JSON.parse(location.replace(/'/g, '"'));
  352. addressStr = locationArray.join("") + address;
  353. } catch (e) {
  354. addressStr = location + address;
  355. }
  356. } else if (Array.isArray(location)) {
  357. addressStr = location.join("") + address;
  358. } else if (typeof location === "object" && location !== null) {
  359. const { province, city, district } = location;
  360. addressStr = `${province || ""}${city || ""}${district || ""}${address}`;
  361. } else {
  362. addressStr = location + address;
  363. }
  364. console.log(addressStr, address);
  365. common_vendor.index.request({
  366. url: `https://apis.map.qq.com/ws/geocoder/v1/?address=${encodeURIComponent(addressStr)}&key=ZS4BZ-NKAA7-4VLXR-PHVI4-HAGPH-Z4FJ3`,
  367. // 需要替换为实际的地图Key
  368. success: (res) => {
  369. if (res.data.status === 0) {
  370. const { lat, lng } = res.data.result.location;
  371. this.mapInfo.latitude = lat;
  372. this.mapInfo.longitude = lng;
  373. this.mapInfo.markers = [{
  374. id: 1,
  375. latitude: lat,
  376. longitude: lng,
  377. title: addressStr
  378. }];
  379. } else {
  380. console.error("地址解析失败:", res);
  381. }
  382. },
  383. fail: (err) => {
  384. console.error("地址解析请求失败:", err);
  385. }
  386. });
  387. } catch (error) {
  388. console.error("更新地图位置失败:", error);
  389. }
  390. },
  391. openLocation() {
  392. if (this.mapInfo.latitude && this.mapInfo.longitude) {
  393. common_vendor.index.openLocation({
  394. latitude: this.mapInfo.latitude,
  395. longitude: this.mapInfo.longitude,
  396. name: this.formatLocation(this.jobDetail.location),
  397. // address: this.formatLocation(this.jobDetail.location),
  398. success: function() {
  399. console.log("导航打开成功");
  400. },
  401. fail: function(err) {
  402. console.error("导航打开失败:", err);
  403. common_vendor.index.showToast({
  404. title: "导航打开失败",
  405. icon: "none"
  406. });
  407. }
  408. });
  409. } else {
  410. common_vendor.index.showToast({
  411. title: "暂无位置信息",
  412. icon: "none"
  413. });
  414. }
  415. }
  416. }
  417. };
  418. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  419. return {
  420. a: common_vendor.t($data.jobDetail.title),
  421. b: common_vendor.t($data.jobDetail.salary),
  422. c: common_vendor.t($data.jobDetail.department),
  423. d: common_vendor.t($options.formatLocation($data.jobDetail.location)),
  424. e: common_vendor.t($data.jobDetail.experience),
  425. f: $data.mapInfo.latitude,
  426. g: $data.mapInfo.longitude,
  427. h: $data.mapInfo.markers,
  428. i: common_vendor.o((...args) => $options.openLocation && $options.openLocation(...args)),
  429. j: common_vendor.f($data.jobDetail.description[0].items, (item, index, i0) => {
  430. return common_vendor.e({
  431. a: $options.hasHtmlTags(item)
  432. }, $options.hasHtmlTags(item) ? {
  433. b: item
  434. } : {
  435. c: common_vendor.t(item)
  436. }, {
  437. d: index
  438. });
  439. }),
  440. k: common_vendor.o((...args) => $options.startInterview && $options.startInterview(...args))
  441. };
  442. }
  443. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2bde8e2a"]]);
  444. wx.createPage(MiniProgramPage);