SubMenu1.vue 9.4 KB

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