position-select.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_systemIndustry = require("../../api/systemIndustry.js");
  4. const _sfc_main = {
  5. setup() {
  6. const searchQuery = common_vendor.ref("");
  7. const activeIndex = common_vendor.ref(0);
  8. const scrollIntoId = common_vendor.ref("category-0");
  9. const currentSelected = common_vendor.ref("");
  10. let sectionHeights = [];
  11. let isClickScrolling = false;
  12. let clickTimer = null;
  13. const instance = common_vendor.getCurrentInstance();
  14. const positionData = common_vendor.ref([]);
  15. const loadData = async (selectedVal) => {
  16. try {
  17. common_vendor.index.showLoading({ title: "加载中..." });
  18. const [indRes, skillRes] = await Promise.all([
  19. api_systemIndustry.listIndustry(),
  20. api_systemIndustry.listIndustrySkill()
  21. ]);
  22. if (indRes.code === 200 && skillRes.code === 200) {
  23. const industries = indRes.rows || indRes.data || [];
  24. const skills = skillRes.rows || skillRes.data || [];
  25. const level1 = industries.filter((i) => i.parentId == 0 || !i.parentId);
  26. const result = level1.map((l1) => {
  27. const level2 = industries.filter((i) => i.parentId == l1.industryId);
  28. const sections = level2.map((l2) => {
  29. const level3 = skills.filter((s) => s.industryId == l2.industryId).map((s) => s.skillName);
  30. return {
  31. name: l2.industryName,
  32. id: l2.industryId,
  33. children: level3
  34. };
  35. });
  36. return {
  37. name: l1.industryName,
  38. id: l1.industryId,
  39. sections
  40. };
  41. });
  42. positionData.value = result;
  43. if (selectedVal) {
  44. for (let i = 0; i < result.length; i++) {
  45. let found = false;
  46. for (let j = 0; j < result[i].sections.length; j++) {
  47. if (result[i].sections[j].children.includes(selectedVal)) {
  48. activeIndex.value = i;
  49. scrollIntoId.value = "category-" + i;
  50. found = true;
  51. break;
  52. }
  53. }
  54. if (found)
  55. break;
  56. }
  57. }
  58. setTimeout(() => {
  59. calculateSectionHeights();
  60. }, 500);
  61. }
  62. } catch (e) {
  63. common_vendor.index.__f__("error", "at pages/experience/position-select.js:82", "加载职位结构失败", e);
  64. common_vendor.index.showToast({ title: "加载职位失败", icon: "none" });
  65. } finally {
  66. common_vendor.index.hideLoading();
  67. }
  68. };
  69. const searchResults = common_vendor.computed(() => {
  70. if (!searchQuery.value)
  71. return [];
  72. const q = searchQuery.value.toLowerCase();
  73. const results = [];
  74. positionData.value.forEach((l1) => {
  75. l1.sections.forEach((l2) => {
  76. l2.children.forEach((pos) => {
  77. if (pos.toLowerCase().includes(q)) {
  78. results.push(pos);
  79. }
  80. });
  81. });
  82. });
  83. return results;
  84. });
  85. common_vendor.onLoad((options) => {
  86. let selectedParam = "";
  87. if (options && options.selected) {
  88. currentSelected.value = decodeURIComponent(options.selected);
  89. selectedParam = currentSelected.value;
  90. }
  91. common_vendor.index.setNavigationBarTitle({ title: "选择职位名称" });
  92. loadData(selectedParam);
  93. });
  94. const calculateSectionHeights = () => {
  95. const query = common_vendor.index.createSelectorQuery().in(instance.proxy);
  96. query.selectAll(".category-wrapper").boundingClientRect((rects) => {
  97. if (rects && rects.length > 0) {
  98. let currentTop = 0;
  99. sectionHeights = rects.map((r) => {
  100. let top = currentTop;
  101. currentTop += r.height;
  102. return top;
  103. });
  104. }
  105. }).exec();
  106. };
  107. const onRightScroll = (e) => {
  108. if (isClickScrolling || sectionHeights.length === 0)
  109. return;
  110. const scrollTop = e.detail.scrollTop;
  111. let currentIndex = 0;
  112. for (let i = 0; i < sectionHeights.length; i++) {
  113. if (scrollTop >= sectionHeights[i] - 15) {
  114. currentIndex = i;
  115. } else {
  116. break;
  117. }
  118. }
  119. if (activeIndex.value !== currentIndex) {
  120. activeIndex.value = currentIndex;
  121. }
  122. };
  123. const selectMenu = (index) => {
  124. activeIndex.value = index;
  125. scrollIntoId.value = "category-" + index;
  126. isClickScrolling = true;
  127. clearTimeout(clickTimer);
  128. clickTimer = setTimeout(() => {
  129. isClickScrolling = false;
  130. }, 600);
  131. };
  132. const selectPosition = (posName) => {
  133. common_vendor.index.$emit("select_position", posName);
  134. common_vendor.index.navigateBack();
  135. };
  136. return {
  137. searchQuery,
  138. activeIndex,
  139. scrollIntoId,
  140. currentSelected,
  141. positionData,
  142. searchResults,
  143. selectMenu,
  144. selectPosition,
  145. onRightScroll
  146. };
  147. }
  148. };
  149. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  150. return common_vendor.e({
  151. a: _ctx.searchQuery,
  152. b: common_vendor.o(($event) => _ctx.searchQuery = $event.detail.value),
  153. c: !_ctx.searchQuery
  154. }, !_ctx.searchQuery ? {
  155. d: common_vendor.f(_ctx.positionData, (item, index, i0) => {
  156. return common_vendor.e({
  157. a: common_vendor.t(item.name),
  158. b: _ctx.activeIndex === index
  159. }, _ctx.activeIndex === index ? {} : {}, {
  160. c: index,
  161. d: common_vendor.n(_ctx.activeIndex === index ? "active" : ""),
  162. e: common_vendor.o(($event) => _ctx.selectMenu(index), index)
  163. });
  164. }),
  165. e: common_vendor.f(_ctx.positionData, (item, index, i0) => {
  166. return {
  167. a: common_vendor.f(item.sections, (sub, sIdx, i1) => {
  168. return {
  169. a: common_vendor.t(sub.name),
  170. b: common_vendor.f(sub.children, (pos, pIdx, i2) => {
  171. return {
  172. a: common_vendor.t(pos),
  173. b: common_vendor.n(pos === _ctx.currentSelected ? "selected" : ""),
  174. c: pIdx,
  175. d: common_vendor.o(($event) => _ctx.selectPosition(pos), pIdx)
  176. };
  177. }),
  178. c: "sub-" + sIdx
  179. };
  180. }),
  181. b: "wrapper-" + index,
  182. c: "category-" + index
  183. };
  184. }),
  185. f: _ctx.scrollIntoId,
  186. g: common_vendor.o((...args) => _ctx.onRightScroll && _ctx.onRightScroll(...args))
  187. } : common_vendor.e({
  188. h: _ctx.searchResults.length > 0
  189. }, _ctx.searchResults.length > 0 ? {
  190. i: common_vendor.f(_ctx.searchResults, (pos, index, i0) => {
  191. return {
  192. a: common_vendor.t(pos),
  193. b: common_vendor.n(pos === _ctx.currentSelected ? "selected" : ""),
  194. c: index,
  195. d: common_vendor.o(($event) => _ctx.selectPosition(pos), index)
  196. };
  197. })
  198. } : {}));
  199. }
  200. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-94bd4fd3"]]);
  201. wx.createPage(MiniProgramPage);
  202. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/experience/position-select.js.map