job-detail.js 15 KB

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