SubMenu3.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <!-- 地区选择 -->
  3. <div class="shop_name_out">
  4. <div class="shop_name_box clearfix">
  5. <div class="shop_name">地区选择</div>
  6. <div class="shop_name_right">
  7. <div class="shop_name_in clearfix" ref="shop_name_parent">
  8. <div class=" clearfix" v-show="shop_name_num == 1">
  9. <NuxtLink
  10. :to="`/${targetSegment}/${targetSegment1}/${targetSegment2}/list-1.html?cityid=${item.id}`"
  11. :title="item.name" v-for="item in provinceList1"
  12. :class="['shop_name_a', { 'shop_name_a_only': item.id == cityId }]">
  13. {{ item.abbreviation }}
  14. </NuxtLink>
  15. </div>
  16. <div class=" clearfix" v-show="shop_name_num == 2">
  17. <NuxtLink :class="['shop_name_a', { 'shop_name_a_only': item.id == cityId }]"
  18. :to="`/${targetSegment}/${targetSegment1}/${targetSegment2}/list-1.html?cityid=${item.id}`"
  19. :title="item.name" v-for="item in provinceList2">
  20. {{ item.abbreviation }}
  21. </NuxtLink>
  22. </div>
  23. <div class=" clearfix" v-show="shop_name_num == 3">
  24. <NuxtLink :class="['shop_name_a', { 'shop_name_a_only': item.id == cityId }]"
  25. :to="`/${targetSegment}/${targetSegment1}/${targetSegment2}/list-1.html?cityid=${item.id}`"
  26. :title="item.name" v-for="item in provinceList3">
  27. {{ item.abbreviation }}
  28. </NuxtLink>
  29. </div>
  30. </div>
  31. <div class="shop_name_btn hand"
  32. @click="shop_name_num >= shop_name_leng ? shop_name_num = 1 : shop_name_num++">
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. <!-- 地区选择 -->
  38. </template>
  39. <script setup>
  40. import { ref, onMounted, watch } from 'vue'
  41. //1.获得商城导航 start ---------------------------------------->
  42. //1.1 获得频道导航的id,并且标记导航
  43. //获得当前的完整路径
  44. // const fullPath = route.path;
  45. // //拆分,取出来中间这一段,然后提取数字部分
  46. const targetSegment = getRoutePath(1);
  47. const targetSegment1 = getRoutePath(2);
  48. const targetSegment2 = getRoutePath(3);
  49. // const segments = fullPath.split('/');
  50. // const targetSegment = segments[2];
  51. const navId = ref(0)//当前导航标记哪个
  52. //通过导航路径反向查询导航id
  53. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  54. method: 'GET',
  55. query: {
  56. 'pinyin': targetSegment,
  57. },
  58. });
  59. console.log("getRouteId", getRouteId);
  60. if (getRouteId.code == 200) {
  61. navId.value = parseInt(getRouteId.data.category_id)
  62. } else {
  63. console.log("错误位置:通过url路径查询导航池id")
  64. }
  65. //1.2 获得商城导航
  66. const shopNav = ref("")
  67. const shopNavOnePinyin = ref("")//获得商城导航的第一个 作为默认的跳转链接
  68. let getShowNav = async () => {
  69. const responseStatus = await requestDataPromise('/web/getWebsiteModelCategory', {
  70. method: 'GET',
  71. query: {
  72. placeid: 0,
  73. pid: navId.value,
  74. num: 8,
  75. type: 1
  76. },
  77. });
  78. console.log("responseStatus", responseStatus);
  79. shopNav.value = responseStatus.data
  80. shopNavOnePinyin.value = responseStatus.data[0].aLIas_pinyin
  81. console.log("shopNavOnePinyin", shopNavOnePinyin.value);
  82. }
  83. getShowNav();
  84. //1.3 标记当前选择的地区
  85. const route = useRoute();
  86. //获得详情id
  87. const cityId = ref(route.query.cityid)
  88. watch(route, () => {
  89. cityId.value = route.query.cityid
  90. })
  91. //1.获得商城导航 end ---------------------------------------->
  92. //2.获得省列表 start ---------------------------------------->
  93. const provinceList1 = ref([]);//省列表1
  94. const provinceList2 = ref([]);//省列表2
  95. const provinceList3 = ref([]);//省列表3
  96. onMounted(async () => {
  97. //获得所有的省
  98. try {
  99. const { $webUrl, $CwebUrl } = useNuxtApp();
  100. const response = await fetch($webUrl + '/web/selectWebsiteArea', {
  101. headers: {
  102. 'Content-Type': 'application/json',
  103. 'Userurl': $CwebUrl,
  104. 'Origin': $CwebUrl
  105. }
  106. });
  107. const result = await response.json();
  108. for (let index in result.data) {
  109. if (index < 15) {
  110. provinceList1.value.push(result.data[index])
  111. } else if (index > 14 && index < 30) {
  112. provinceList2.value.push(result.data[index])
  113. } else if (index > 29) {
  114. provinceList3.value.push(result.data[index])
  115. }
  116. }
  117. } catch (error) {
  118. console.error('获取行政区划数据失败:', error);
  119. }
  120. })
  121. //2.获得商城导航 start ---------------------------------------->
  122. //3.地区滚动 start ---------------------------------------->
  123. // 地区选择
  124. const shop_name_num = ref(1)
  125. const shop_name_parent = ref(null)
  126. const shop_name_leng = ref(1)
  127. onMounted(() => {
  128. const shop_name_son = shop_name_parent.value.querySelectorAll("div")
  129. shop_name_leng.value = shop_name_son.length
  130. })
  131. //3.地区滚动 end ---------------------------------------->
  132. </script>
  133. <style lang="less" scoped>
  134. .shop_name_out {
  135. margin-top: 20px;
  136. }
  137. .shop_name_box {
  138. border-top: solid 1px #fff;
  139. .shop_name_box_a {
  140. height: 44px;
  141. line-height: 44px;
  142. color: #fff;
  143. font-weight: bold;
  144. font-size: 20px;
  145. }
  146. .shop_name {
  147. float: left;
  148. height: 44px;
  149. line-height: 44px;
  150. color: #fff;
  151. font-weight: bold;
  152. position: relative;
  153. z-index: 11;
  154. text-align: center;
  155. font-size: 20px;
  156. background: #a91b33;
  157. padding: 0px 14px;
  158. }
  159. .shop_name_right {
  160. height: 40px;
  161. border-bottom: 1px solid #E8E9EC;
  162. margin-top: 4px;
  163. background: #F8F8F8;
  164. position: relative;
  165. z-index: 2;
  166. }
  167. .shop_name_right::after {
  168. content: '';
  169. display: block;
  170. position: absolute;
  171. top: 0px;
  172. right: 0px;
  173. height: 100%;
  174. width: 16px;
  175. background: url(@/public/img/9.png) no-repeat 0px bottom #fff;
  176. background-size: 100% auto;
  177. }
  178. .shop_name_btn {
  179. width: 24px;
  180. height: 24px;
  181. float: right;
  182. margin: 10px 22px 0px 0px;
  183. background: url(@/public/img/8.png) no-repeat center center;
  184. border-radius: 50%;
  185. background-size: 100% 100%;
  186. }
  187. }
  188. .shop_name_in {
  189. float: left;
  190. height: 40px;
  191. width: 1046px;
  192. float: left;
  193. box-sizing: border-box;
  194. .shop_name_a {
  195. float: left;
  196. height: 27px;
  197. line-height: 27px;
  198. color: #222;
  199. font-size: 20px;
  200. position: relative;
  201. margin: 7px 14.5px 0;
  202. padding: 0px 10px;
  203. }
  204. .shop_name_a::after {
  205. content: '/';
  206. display: block;
  207. position: absolute;
  208. top: 0px;
  209. right: -18px;
  210. height: 100%;
  211. line-height: 27px;
  212. color: #E9E9E9;
  213. font-size: 20px;
  214. }
  215. .shop_name_a:nth-last-of-type(1)::after {
  216. content: '';
  217. display: none;
  218. }
  219. .shop_name_a_only {
  220. background: #a91b33;
  221. color: #fff;
  222. }
  223. }
  224. .shop_name_out {
  225. margin-top: 20px;
  226. }
  227. .shop_name_box {
  228. border-top: solid 1px #fff;
  229. .shop_name_box_a {
  230. height: 44px;
  231. line-height: 44px;
  232. color: #fff;
  233. font-weight: bold;
  234. font-size: 20px;
  235. }
  236. .shop_name {
  237. float: left;
  238. height: 44px;
  239. line-height: 44px;
  240. color: #fff;
  241. font-weight: bold;
  242. position: relative;
  243. z-index: 11;
  244. text-align: center;
  245. font-size: 20px;
  246. background: #a91b33;
  247. padding: 0px 14px;
  248. }
  249. .shop_name_right {
  250. height: 40px;
  251. border-bottom: 1px solid #E8E9EC;
  252. margin-top: 4px;
  253. background: #F8F8F8;
  254. position: relative;
  255. z-index: 2;
  256. }
  257. .shop_name_right::after {
  258. content: '';
  259. display: block;
  260. position: absolute;
  261. top: 0px;
  262. right: 0px;
  263. height: 100%;
  264. width: 16px;
  265. background: url(@/public/img/9.png) no-repeat 0px bottom #fff;
  266. background-size: 100% auto;
  267. }
  268. .shop_name_btn {
  269. width: 24px;
  270. height: 24px;
  271. float: right;
  272. margin: 10px 22px 0px 0px;
  273. background: url(@/public/img/8.png) no-repeat center center;
  274. border-radius: 50%;
  275. background-size: 100% 100%;
  276. }
  277. }
  278. .shop_nav {
  279. border: solid 1px #E9E9E9;
  280. background: #fafafa;
  281. margin-top: 20px;
  282. .shop_nav_head {
  283. float: left;
  284. height: 28px;
  285. width: 138px;
  286. margin: 30px 52px 0px 25px;
  287. }
  288. .shop_nav_head_a {
  289. display: block;
  290. height: 28px;
  291. width: 138px;
  292. background: url(@/public/img/7.png) no-repeat left top;
  293. background-size: 100% 100%;
  294. }
  295. }
  296. .clearfix {
  297. overflow: hidden;
  298. }
  299. .shop_nav_in_a {
  300. float: left;
  301. height: 75px;
  302. line-height: 75px;
  303. color: #333;
  304. font-size: 16px;
  305. background: #f8f5f5;
  306. width: 118px;
  307. border-bottom: solid 5px #a91b33;
  308. font-weight: bold;
  309. margin: 5px 0;
  310. text-align: center;
  311. }
  312. .shop_nav_in_a:nth-of-type(4) {
  313. margin-right: 8px;
  314. }
  315. .shop_nav_in_a:hover {
  316. color: #a91b33;
  317. }
  318. .shop_nav_in_a_active {
  319. color: #a91b33;
  320. }
  321. </style>