job-detail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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() {
  119. common_vendor.index.request({
  120. url: `${common_config.apiBaseUrl}/api/job/config/position/${this.selectedJobId}`,
  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();
  178. common_vendor.index.navigateTo({
  179. url: "/pages/Personal/Personal",
  180. fail: (err) => {
  181. console.error("页面跳转失败:", err);
  182. common_vendor.index.showToast({
  183. title: "页面跳转失败",
  184. icon: "none"
  185. });
  186. }
  187. });
  188. }
  189. } catch (err) {
  190. console.error("申请职位失败:", err);
  191. common_vendor.index.showToast({
  192. title: "申请职位失败,请重试",
  193. icon: "none"
  194. });
  195. }
  196. },
  197. hasHtmlTags(text) {
  198. const htmlRegex = /<[^>]*>/;
  199. return htmlRegex.test(text);
  200. },
  201. formatLocation(location) {
  202. if (!location)
  203. return "";
  204. if (typeof location === "string" && location.startsWith("[")) {
  205. try {
  206. const locationArray = JSON.parse(location.replace(/'/g, '"'));
  207. return locationArray.join(" ");
  208. } catch (e) {
  209. console.error("解析location失败:", e);
  210. return location;
  211. }
  212. }
  213. if (Array.isArray(location)) {
  214. return location.join(" ");
  215. }
  216. if (typeof location === "object" && location !== null) {
  217. const { province, city, district } = location;
  218. if (province && city) {
  219. return province + " " + city + (district ? " " + district : "");
  220. }
  221. }
  222. return location;
  223. },
  224. // 更新地图位置信息
  225. async updateMapLocation(location) {
  226. try {
  227. let addressStr = "";
  228. if (typeof location === "string" && location.startsWith("[")) {
  229. try {
  230. const locationArray = JSON.parse(location.replace(/'/g, '"'));
  231. addressStr = locationArray.join("");
  232. } catch (e) {
  233. addressStr = location;
  234. }
  235. } else if (Array.isArray(location)) {
  236. addressStr = location.join("");
  237. } else if (typeof location === "object" && location !== null) {
  238. const { province, city, district } = location;
  239. addressStr = `${province || ""}${city || ""}${district || ""}`;
  240. } else {
  241. addressStr = location;
  242. }
  243. common_vendor.index.request({
  244. url: `https://apis.map.qq.com/ws/geocoder/v1/?address=${encodeURIComponent(addressStr)}&key=WJLBZ-SMQYZ-3RNX5-7J4LI-XTZD6-7IBZR`,
  245. // 需要替换为实际的地图Key
  246. success: (res) => {
  247. if (res.data.status === 0) {
  248. const { lat, lng } = res.data.result.location;
  249. this.mapInfo.latitude = lat;
  250. this.mapInfo.longitude = lng;
  251. this.mapInfo.markers = [{
  252. id: 1,
  253. latitude: lat,
  254. longitude: lng,
  255. title: addressStr
  256. }];
  257. } else {
  258. console.error("地址解析失败:", res);
  259. }
  260. },
  261. fail: (err) => {
  262. console.error("地址解析请求失败:", err);
  263. }
  264. });
  265. } catch (error) {
  266. console.error("更新地图位置失败:", error);
  267. }
  268. },
  269. openLocation() {
  270. if (this.mapInfo.latitude && this.mapInfo.longitude) {
  271. common_vendor.index.openLocation({
  272. latitude: this.mapInfo.latitude,
  273. longitude: this.mapInfo.longitude,
  274. name: this.jobDetail.title,
  275. address: this.formatLocation(this.jobDetail.location),
  276. success: function() {
  277. console.log("导航打开成功");
  278. },
  279. fail: function(err) {
  280. console.error("导航打开失败:", err);
  281. common_vendor.index.showToast({
  282. title: "导航打开失败",
  283. icon: "none"
  284. });
  285. }
  286. });
  287. } else {
  288. common_vendor.index.showToast({
  289. title: "暂无位置信息",
  290. icon: "none"
  291. });
  292. }
  293. }
  294. }
  295. };
  296. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  297. return {
  298. a: common_vendor.t($data.jobDetail.title),
  299. b: common_vendor.t($data.jobDetail.salary),
  300. c: common_vendor.t($data.jobDetail.department),
  301. d: common_vendor.t($options.formatLocation($data.jobDetail.location)),
  302. e: common_vendor.t($data.jobDetail.experience),
  303. f: $data.mapInfo.latitude,
  304. g: $data.mapInfo.longitude,
  305. h: $data.mapInfo.markers,
  306. i: common_vendor.o((...args) => $options.openLocation && $options.openLocation(...args)),
  307. j: common_vendor.f($data.jobDetail.description[0].items, (item, index, i0) => {
  308. return common_vendor.e({
  309. a: $options.hasHtmlTags(item)
  310. }, $options.hasHtmlTags(item) ? {
  311. b: item
  312. } : {
  313. c: common_vendor.t(item)
  314. }, {
  315. d: index
  316. });
  317. }),
  318. k: common_vendor.o((...args) => $options.startInterview && $options.startInterview(...args))
  319. };
  320. }
  321. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2bde8e2a"]]);
  322. wx.createPage(MiniProgramPage);