job-detail.js 11 KB

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