industry-select.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 industryData = common_vendor.ref([]);
  7. const currentIndustry = common_vendor.ref("");
  8. const loadData = async (selectedVal) => {
  9. try {
  10. common_vendor.index.showLoading({ title: "加载中..." });
  11. const [indRes] = await Promise.all([
  12. api_systemIndustry.listIndustry()
  13. ]);
  14. if (indRes.code === 200) {
  15. const industries = indRes.rows || indRes.data || [];
  16. const level1 = industries.filter((i) => i.parentId == 0 || !i.parentId);
  17. const result = level1.map((l1) => {
  18. const level2 = industries.filter((i) => i.parentId == l1.industryId).map((i) => i.industryName);
  19. return {
  20. name: l1.industryName,
  21. expanded: false,
  22. children: level2
  23. };
  24. });
  25. if (selectedVal) {
  26. const parts = selectedVal.split("-");
  27. if (parts.length > 0) {
  28. result.forEach((item) => {
  29. item.expanded = item.name === parts[0];
  30. });
  31. }
  32. } else if (result.length > 0) {
  33. result[0].expanded = true;
  34. }
  35. industryData.value = result;
  36. }
  37. } catch (e) {
  38. common_vendor.index.__f__("error", "at pages/experience/industry-select.js:54", "加载行业数据失败", e);
  39. common_vendor.index.showToast({ title: "加载行业数据失败", icon: "none" });
  40. } finally {
  41. common_vendor.index.hideLoading();
  42. }
  43. };
  44. common_vendor.onLoad((options) => {
  45. let selectedParam = "";
  46. if (options && options.selected) {
  47. currentIndustry.value = decodeURIComponent(options.selected);
  48. selectedParam = currentIndustry.value;
  49. }
  50. common_vendor.index.setNavigationBarTitle({ title: "选择行业" });
  51. loadData(selectedParam);
  52. });
  53. const toggleCategory = (index) => {
  54. industryData.value[index].expanded = !industryData.value[index].expanded;
  55. };
  56. const selectIndustry = (primaryName, secondaryName) => {
  57. const industryVal = `${primaryName}-${secondaryName}`;
  58. currentIndustry.value = industryVal;
  59. common_vendor.index.$emit("select_industry", industryVal);
  60. common_vendor.index.navigateBack();
  61. };
  62. return {
  63. industryData,
  64. currentIndustry,
  65. toggleCategory,
  66. selectIndustry
  67. };
  68. }
  69. };
  70. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  71. return {
  72. a: common_vendor.f(_ctx.industryData, (category, cIdx, i0) => {
  73. return common_vendor.e({
  74. a: common_vendor.t(category.name),
  75. b: common_vendor.n(category.expanded ? "expanded" : ""),
  76. c: common_vendor.o(($event) => _ctx.toggleCategory(cIdx), cIdx),
  77. d: category.expanded
  78. }, category.expanded ? {
  79. e: common_vendor.f(category.children, (tag, tIdx, i1) => {
  80. return {
  81. a: common_vendor.t(tag),
  82. b: tIdx,
  83. c: common_vendor.n(_ctx.currentIndustry === category.name + "-" + tag ? "active" : ""),
  84. d: common_vendor.o(($event) => _ctx.selectIndustry(category.name, tag), tIdx)
  85. };
  86. })
  87. } : {}, {
  88. f: cIdx
  89. });
  90. })
  91. };
  92. }
  93. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ccf07d08"]]);
  94. wx.createPage(MiniProgramPage);
  95. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/experience/industry-select.js.map