subMenu.vue 9.7 KB

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