| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const api_systemIndustry = require("../../api/systemIndustry.js");
- const _sfc_main = {
- setup() {
- const searchQuery = common_vendor.ref("");
- const activeIndex = common_vendor.ref(0);
- const scrollIntoId = common_vendor.ref("category-0");
- const currentSelected = common_vendor.ref("");
- let sectionHeights = [];
- let isClickScrolling = false;
- let clickTimer = null;
- const instance = common_vendor.getCurrentInstance();
- const positionData = common_vendor.ref([]);
- const loadData = async (selectedVal) => {
- try {
- common_vendor.index.showLoading({ title: "加载中..." });
- const [indRes, skillRes] = await Promise.all([
- api_systemIndustry.listIndustry(),
- api_systemIndustry.listIndustrySkill()
- ]);
- if (indRes.code === 200 && skillRes.code === 200) {
- const industries = indRes.rows || indRes.data || [];
- const skills = skillRes.rows || skillRes.data || [];
- const level1 = industries.filter((i) => i.parentId == 0 || !i.parentId);
- const result = level1.map((l1) => {
- const level2 = industries.filter((i) => i.parentId == l1.industryId);
- const sections = level2.map((l2) => {
- const level3 = skills.filter((s) => s.industryId == l2.industryId).map((s) => s.skillName);
- return {
- name: l2.industryName,
- id: l2.industryId,
- children: level3
- };
- });
- return {
- name: l1.industryName,
- id: l1.industryId,
- sections
- };
- });
- positionData.value = result;
- if (selectedVal) {
- for (let i = 0; i < result.length; i++) {
- let found = false;
- for (let j = 0; j < result[i].sections.length; j++) {
- if (result[i].sections[j].children.includes(selectedVal)) {
- activeIndex.value = i;
- scrollIntoId.value = "category-" + i;
- found = true;
- break;
- }
- }
- if (found)
- break;
- }
- }
- setTimeout(() => {
- calculateSectionHeights();
- }, 500);
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/experience/position-select.js:82", "加载职位结构失败", e);
- common_vendor.index.showToast({ title: "加载职位失败", icon: "none" });
- } finally {
- common_vendor.index.hideLoading();
- }
- };
- const searchResults = common_vendor.computed(() => {
- if (!searchQuery.value)
- return [];
- const q = searchQuery.value.toLowerCase();
- const results = [];
- positionData.value.forEach((l1) => {
- l1.sections.forEach((l2) => {
- l2.children.forEach((pos) => {
- if (pos.toLowerCase().includes(q)) {
- results.push(pos);
- }
- });
- });
- });
- return results;
- });
- common_vendor.onLoad((options) => {
- let selectedParam = "";
- if (options && options.selected) {
- currentSelected.value = decodeURIComponent(options.selected);
- selectedParam = currentSelected.value;
- }
- common_vendor.index.setNavigationBarTitle({ title: "选择职位名称" });
- loadData(selectedParam);
- });
- const calculateSectionHeights = () => {
- const query = common_vendor.index.createSelectorQuery().in(instance.proxy);
- query.selectAll(".category-wrapper").boundingClientRect((rects) => {
- if (rects && rects.length > 0) {
- let currentTop = 0;
- sectionHeights = rects.map((r) => {
- let top = currentTop;
- currentTop += r.height;
- return top;
- });
- }
- }).exec();
- };
- const onRightScroll = (e) => {
- if (isClickScrolling || sectionHeights.length === 0)
- return;
- const scrollTop = e.detail.scrollTop;
- let currentIndex = 0;
- for (let i = 0; i < sectionHeights.length; i++) {
- if (scrollTop >= sectionHeights[i] - 15) {
- currentIndex = i;
- } else {
- break;
- }
- }
- if (activeIndex.value !== currentIndex) {
- activeIndex.value = currentIndex;
- }
- };
- const selectMenu = (index) => {
- activeIndex.value = index;
- scrollIntoId.value = "category-" + index;
- isClickScrolling = true;
- clearTimeout(clickTimer);
- clickTimer = setTimeout(() => {
- isClickScrolling = false;
- }, 600);
- };
- const selectPosition = (posName) => {
- common_vendor.index.$emit("select_position", posName);
- common_vendor.index.navigateBack();
- };
- return {
- searchQuery,
- activeIndex,
- scrollIntoId,
- currentSelected,
- positionData,
- searchResults,
- selectMenu,
- selectPosition,
- onRightScroll
- };
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: _ctx.searchQuery,
- b: common_vendor.o(($event) => _ctx.searchQuery = $event.detail.value),
- c: !_ctx.searchQuery
- }, !_ctx.searchQuery ? {
- d: common_vendor.f(_ctx.positionData, (item, index, i0) => {
- return common_vendor.e({
- a: common_vendor.t(item.name),
- b: _ctx.activeIndex === index
- }, _ctx.activeIndex === index ? {} : {}, {
- c: index,
- d: common_vendor.n(_ctx.activeIndex === index ? "active" : ""),
- e: common_vendor.o(($event) => _ctx.selectMenu(index), index)
- });
- }),
- e: common_vendor.f(_ctx.positionData, (item, index, i0) => {
- return {
- a: common_vendor.f(item.sections, (sub, sIdx, i1) => {
- return {
- a: common_vendor.t(sub.name),
- b: common_vendor.f(sub.children, (pos, pIdx, i2) => {
- return {
- a: common_vendor.t(pos),
- b: common_vendor.n(pos === _ctx.currentSelected ? "selected" : ""),
- c: pIdx,
- d: common_vendor.o(($event) => _ctx.selectPosition(pos), pIdx)
- };
- }),
- c: "sub-" + sIdx
- };
- }),
- b: "wrapper-" + index,
- c: "category-" + index
- };
- }),
- f: _ctx.scrollIntoId,
- g: common_vendor.o((...args) => _ctx.onRightScroll && _ctx.onRightScroll(...args))
- } : common_vendor.e({
- h: _ctx.searchResults.length > 0
- }, _ctx.searchResults.length > 0 ? {
- i: common_vendor.f(_ctx.searchResults, (pos, index, i0) => {
- return {
- a: common_vendor.t(pos),
- b: common_vendor.n(pos === _ctx.currentSelected ? "selected" : ""),
- c: index,
- d: common_vendor.o(($event) => _ctx.selectPosition(pos), index)
- };
- })
- } : {}));
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-94bd4fd3"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/experience/position-select.js.map
|