index.jsx 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import { useState, useEffect, useRef } from "react";
  2. import { Swiper, SwiperItem, Image } from "@tarojs/components";
  3. import Taro from "@tarojs/taro";
  4. import { useSelector } from "react-redux";
  5. import { getSystemParsm } from "@/services/common";
  6. import "./index.scss";
  7. import { ROLE_CODE } from "@/constants/user";
  8. import { useMemo } from "react";
  9. const MINI_KANGYANG = "MINI_KANGYANG";
  10. const list = [
  11. {
  12. name: "全部楼盘",
  13. id: 1,
  14. icon: require("@/assets/index-icon9.png"),
  15. router: "/pages/index/buildingList/index",
  16. },
  17. {
  18. name: "品牌地产",
  19. id: 2,
  20. icon: require("@/assets/index-icon8.png"),
  21. router: "/pages/index/brandList/index",
  22. },
  23. {
  24. name: "近期开盘",
  25. id: 3,
  26. icon: require("@/assets/index-icon6.png"),
  27. router: `/pages/index/buildingList/index?isRecentOpening=1`,
  28. },
  29. {
  30. name: "帮我找房",
  31. id: 4,
  32. icon: require("@/assets/index-icon1.png"),
  33. router: "/pages/index/helpToFindHouse/index",
  34. },
  35. {
  36. name: "增值服务",
  37. id: 5,
  38. icon: require("@/assets/index-icon16.png"),
  39. router: "/pages/index/addedValueService/index",
  40. },
  41. {
  42. name: "地图找房",
  43. id: 6,
  44. icon: require("@/assets/index-icon2.png"),
  45. router: "/pages/index/findHouseFromMap/index",
  46. },
  47. {
  48. name: "活动信息",
  49. id: 7,
  50. icon: require("@/assets/index-icon5.png"),
  51. router: "/pages/index/activityList/index?type=dymic",
  52. },
  53. {
  54. name: "团房信息",
  55. id: 8,
  56. icon: require("@/assets/index-icon12.png"),
  57. router: "/pages/index/activityList/index?type=house",
  58. },
  59. {
  60. name: "特价房",
  61. id: 9,
  62. icon: require("@/assets/index-icon11.png"),
  63. router: "/pages/index/specialPriceHouse/index",
  64. },
  65. {
  66. name: "康养",
  67. id: 10,
  68. icon: require("@/assets/index-icon7.png"),
  69. miniapp: MINI_KANGYANG,
  70. },
  71. {
  72. name: "文旅商办",
  73. id: 11,
  74. icon: require("@/assets/index-icon13.png"),
  75. router: `/pages/index/buildingList/index?isCommerce=1`,
  76. },
  77. {
  78. name: "资讯",
  79. id: 12,
  80. icon: require("@/assets/index-icon15.png"),
  81. router: "/pages/index/newsList/index",
  82. },
  83. {
  84. name: "购房百科",
  85. id: 13,
  86. icon: require("@/assets/index-icon4.png"),
  87. router: "/pages/index/encyclopediasOfBuyHouse/index",
  88. },
  89. {
  90. name: "房贷计算",
  91. id: 14,
  92. icon: require("@/assets/index-icon3.png"),
  93. router: "/pages/mine/mortgageCalc/index",
  94. },
  95. ];
  96. const brokerList = [
  97. {
  98. name: "我要推荐",
  99. id: 25,
  100. icon: require("@/assets/index-icon25.png"),
  101. router: "/pages/mine/addCustomer/index",
  102. },
  103. {
  104. name: "我的客户",
  105. id: 23,
  106. icon: require("@/assets/index-icon23.png"),
  107. router: "/pages/mine/myCustomer/index",
  108. },
  109. {
  110. name: "邀请好友",
  111. id: 26,
  112. icon: require("@/assets/index-icon26.png"),
  113. router: "/subpackages/pages/broker/invitation/index",
  114. },
  115. {
  116. name: "我的钱包",
  117. id: 24,
  118. icon: require("@/assets/index-icon24.png"),
  119. router: "/subpackages/pages/broker/myWallet/index",
  120. },
  121. ];
  122. export default function Menu() {
  123. const kangyangRef = useRef();
  124. const city = useSelector((state) => state.city);
  125. const [List, setList] = useState(list);
  126. useEffect(() => {
  127. // 如果是全民经纪人添加专属菜单
  128. if (city.curCity.shortname === BROKER_CITY) {
  129. setList([...brokerList, ...list]);
  130. } else {
  131. setList(list);
  132. }
  133. }, [city.curCity.shortname]);
  134. const MenuList = useMemo(() => {
  135. let Arr = [];
  136. List.map((item) => {
  137. if (Arr.length) {
  138. if (Arr[Arr.length - 1].length < 10) {
  139. Arr[Arr.length - 1].push({ ...item });
  140. } else {
  141. Arr.push([{ ...item }]);
  142. }
  143. } else {
  144. Arr.push([{ ...item }]);
  145. }
  146. });
  147. return Arr
  148. }, [List]);
  149. const MenuClick = (item) => {
  150. return () => {
  151. if (item.router) {
  152. Taro.navigateTo({ url: item.router });
  153. } else if (item.miniapp === MINI_KANGYANG) {
  154. if (kangyangRef.current) {
  155. // 跳转到康养小程序
  156. Taro.navigateToMiniProgram(kangyangRef.current);
  157. }
  158. }
  159. };
  160. };
  161. useEffect(() => {
  162. // 获取康养小程序相关
  163. getSystemParsm(MINI_KANGYANG).then((res) => {
  164. if (res && res.paramValue) {
  165. kangyangRef.current = JSON.parse(res.paramValue);
  166. }
  167. });
  168. }, []);
  169. return (
  170. <view className="components Menu">
  171. <view>
  172. <view>
  173. <Swiper autoplay={false} indicator-dots>
  174. {MenuList.map((item, index) => (
  175. <SwiperItem key={`Banner-${index}`}>
  176. <view className="swiper-item">
  177. {item.map((subItem, subIndex) => (
  178. <view
  179. key={`BannerItem-${subIndex}`}
  180. onClick={MenuClick(subItem)}
  181. >
  182. <Image mode="heightFix" src={subItem.icon || null} />
  183. <text>{subItem.name}</text>
  184. </view>
  185. ))}
  186. </view>
  187. </SwiperItem>
  188. ))}
  189. </Swiper>
  190. </view>
  191. </view>
  192. </view>
  193. );
  194. }