123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_config = require("../../common/config.js");
- const api_user = require("../../api/user.js");
- const _sfc_main = {
- data() {
- return {
- jobDetail: {
- title: "",
- salary: "",
- department: "",
- location: "",
- experience: "",
- benefits: [],
- description: [
- {
- subtitle: "岗位要求",
- items: []
- }
- ]
- },
- selectedJobId: null,
- jobId: null
- };
- },
- onLoad(options) {
- this.jobId = options.id;
- this.getJobDetail(options.id);
- try {
- const jobDetailStr = common_vendor.index.getStorageSync("currentJobDetail");
- if (jobDetailStr) {
- const jobData = JSON.parse(jobDetailStr);
- this.jobDetail = {
- ...this.jobDetail,
- title: jobData.title || this.jobDetail.title,
- salary: jobData.salary || this.jobDetail.salary,
- department: jobData.department || this.jobDetail.department,
- location: jobData.location || this.jobDetail.location,
- experience: jobData.experience || this.jobDetail.experience,
- benefits: jobData.benefits || this.jobDetail.benefits,
- description: jobData.description || this.jobDetail.description
- };
- }
- } catch (e) {
- console.error("获取职位详情失败:", e);
- }
- },
- methods: {
- async getJobDetail(jobId) {
- try {
- const { data } = await common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/mini/job/detail?id=${jobId}&tenant_id=1`,
- method: "GET"
- });
- if (data.code === 2e3) {
- let descriptionItems = [];
- if (data.data.description) {
- const liRegex = /<li[^>]*>(.*?)<\/li>/g;
- const stripTagsRegex = /<[^>]*>/g;
- let match;
- while ((match = liRegex.exec(data.data.description)) !== null) {
- const text = match[1].replace(stripTagsRegex, "").replace(/ /g, " ").trim();
- if (text) {
- descriptionItems.push(text);
- }
- }
- }
- if (data.data.requirements) {
- descriptionItems.unshift(data.data.requirements);
- }
- this.jobDetail = {
- id: data.data.id,
- title: data.data.title || "",
- salary: data.data.salary_range ? `${data.data.salary_range}/月` : "",
- department: `${data.data.department || ""} ${data.data.job_type === 1 ? "全职" : "兼职"}`,
- location: data.data.location || "",
- experience: data.data.work_experience_required || "不限",
- benefits: data.data.competency_tags || ["五险一金", "带薪年假", "定期体检"],
- description: [
- {
- subtitle: "岗位要求",
- items: descriptionItems
- }
- ]
- };
- } else {
- common_vendor.index.showToast({
- title: "获取职位详情失败",
- icon: "none"
- });
- }
- } catch (e) {
- console.error("获取职位详情失败:", e);
- common_vendor.index.showToast({
- title: "获取职位详情失败",
- icon: "none"
- });
- }
- },
- checkLogin() {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- if (!userInfo) {
- common_vendor.index.showToast({
- title: "请先登录",
- icon: "none"
- });
- return false;
- }
- return true;
- },
- async startInterview() {
- if (!this.checkLogin()) {
- return;
- }
- try {
- common_vendor.index.setStorageSync("selectedJob", JSON.stringify(this.jobDetail));
- const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
- const response = await api_user.applyJob({
- job_id: this.jobId,
- tenant_id: 1,
- openid: userInfo.openid
- });
- if (response && response.id) {
- common_vendor.index.setStorageSync("appId", response.id);
- try {
- userInfo.appId = response.id;
- common_vendor.index.setStorageSync("userInfo", JSON.stringify(userInfo));
- } catch (e) {
- console.error("更新用户信息失败:", e);
- }
- common_vendor.index.navigateTo({
- url: "/pages/Personal/Personal",
- fail: (err) => {
- console.error("页面跳转失败:", err);
- common_vendor.index.showToast({
- title: "页面跳转失败",
- icon: "none"
- });
- }
- });
- }
- } catch (err) {
- console.error("申请职位失败:", err);
- common_vendor.index.showToast({
- title: "申请职位失败,请重试",
- icon: "none"
- });
- }
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return {
- a: common_vendor.t($data.jobDetail.title),
- b: common_vendor.t($data.jobDetail.salary),
- c: common_vendor.t($data.jobDetail.department),
- d: common_vendor.t($data.jobDetail.location),
- e: common_vendor.t($data.jobDetail.experience),
- f: common_vendor.f($data.jobDetail.description[0].items, (item, index, i0) => {
- return {
- a: common_vendor.t(item),
- b: index
- };
- }),
- g: common_vendor.o((...args) => $options.startInterview && $options.startInterview(...args))
- };
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2bde8e2a"]]);
- wx.createPage(MiniProgramPage);
|