subMenu.vue 9.3 KB

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