subMenu2.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <!-- 商城首页 -->
  3. <nav class="shop_nav clearfix phone_none">
  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. <div class="phone_nav pc_none">
  20. <NuxtLink
  21. class="phone_nav_a phone_nav_a_head"
  22. to="/xiangcunshangcheng/index.html" >
  23. 商城首页
  24. </NuxtLink>
  25. <div class="phone_nav_in">
  26. <NuxtLink
  27. :class="['phone_nav_a', { 'phone_nav_a_active': item.category_id == navId }]"
  28. :to="`/xiangcunshangcheng/${item.aLIas_pinyin}/index.html`"
  29. v-for="item in shopNav"
  30. >
  31. {{item.alias}}
  32. </NuxtLink>
  33. </div>
  34. </div>
  35. <!-- 地区选择 -->
  36. <div class="shop_name_out">
  37. <div class="shop_name_box clearfix">
  38. <div class="shop_name">地区选择</div>
  39. <div class="shop_name_right">
  40. <div class="shop_name_in clearfix" ref="shop_name_parent">
  41. <div class=" clearfix" v-show="shop_name_num == 1">
  42. <span
  43. @click="setUrlParam(item)"
  44. :title="item.name"
  45. v-for="item in provinceList1"
  46. :class="['shop_name_a', { 'shop_name_a_only': item.id == cityId }]"
  47. >
  48. {{ item.abbreviation }}
  49. </span>
  50. </div>
  51. <div class=" clearfix" v-show="shop_name_num == 2">
  52. <span
  53. :class="['shop_name_a', { 'shop_name_a_only': item.id == cityId }]"
  54. @click="setUrlParam(item)"
  55. :title="item.name"
  56. v-for="item in provinceList2"
  57. >
  58. {{ item.abbreviation }}
  59. </span>
  60. </div>
  61. <div class=" clearfix" v-show="shop_name_num == 3">
  62. <span
  63. :class="['shop_name_a', { 'shop_name_a_only': item.id == cityId }]"
  64. @click="setUrlParam(item)"
  65. :title="item.name"
  66. v-for="item in provinceList3"
  67. >
  68. {{ item.abbreviation }}
  69. </span>
  70. </div>
  71. </div>
  72. <div class="shop_name_btn hand"
  73. @click="shop_name_num >= shop_name_leng ? shop_name_num = 1 : shop_name_num++">
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. <!-- 地区选择 -->
  79. </template>
  80. <script setup>
  81. import { ref, onMounted ,watch } from 'vue'
  82. //1.获得商城导航 start ---------------------------------------->
  83. //1.1 获得商城导航
  84. const shopNav = ref("")
  85. let getShowNav = async () => {
  86. const responseStatus = await requestDataPromise('/web/getWebsiteModelCategory', {
  87. method: 'GET',
  88. query: {
  89. placeid:0,
  90. pid:346,
  91. num:8
  92. },
  93. });
  94. shopNav.value = responseStatus.data
  95. }
  96. getShowNav();
  97. //1.2 标记当前选择的地区
  98. const route = useRoute();
  99. const router = useRouter();
  100. //获得详情id
  101. const cityId = ref(route.query.cityid)
  102. //1.3 获得频道导航的id,并且标记导航
  103. //获得当前的完整路径
  104. const fullPath = route.path;
  105. //拆分,取出来中间这一段,然后提取数字部分
  106. const segments = fullPath.split('/');
  107. const targetSegment = segments[2];
  108. const navId = ref(0)//当前导航标记哪个
  109. //通过导航路径反向查询导航id
  110. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  111. method: 'GET',
  112. query: {
  113. 'pinyin': targetSegment,
  114. },
  115. });
  116. if (getRouteId.code == 200) {
  117. navId.value = parseInt(getRouteId.data.category_id)
  118. } else {
  119. console.log("错误位置:通过url路径查询导航池id")
  120. }
  121. //1.4设置url中的参数
  122. const setUrlParam = (item) => {
  123. //获得当前的url
  124. const currentUrl = window.location.href;
  125. //判断url中是否含有select参数,如果有就删掉
  126. cityId.value = item.id;
  127. // 复制当前的 query 对象
  128. const newQuery = { ...route.query };
  129. // 更新 cityid
  130. newQuery.cityid = item.id;
  131. // 检查是否有 select 参数,如果有则删除
  132. if ('select' in newQuery) {
  133. delete newQuery.select;
  134. }
  135. // 使用 router.replace 更新 URL
  136. router.replace({
  137. path: route.path,
  138. query: newQuery
  139. });
  140. }
  141. //1.5 监听路由变化
  142. watch(() => route.query.cityid, (newVal, oldVal) => {
  143. if(newVal == undefined){
  144. cityId.value = ''
  145. }
  146. })
  147. //1.获得商城导航 end ---------------------------------------->
  148. //2.获得省列表 start ---------------------------------------->
  149. const provinceList1 = ref([]);//省列表1
  150. const provinceList2 = ref([]);//省列表2
  151. const provinceList3 = ref([]);//省列表3
  152. onMounted(async () => {
  153. //获得所有的省
  154. try {
  155. const { $webUrl, $CwebUrl } = useNuxtApp();
  156. const response = await fetch($webUrl + '/web/selectWebsiteArea', {
  157. headers: {
  158. 'Content-Type': 'application/json',
  159. 'Userurl': $CwebUrl,
  160. 'Origin': $CwebUrl
  161. }
  162. });
  163. const result = await response.json();
  164. for(let index in result.data){
  165. if(index < 15){
  166. provinceList1.value.push(result.data[index])
  167. }else if(index > 14 && index < 30){
  168. provinceList2.value.push(result.data[index])
  169. }else if(index > 29){
  170. provinceList3.value.push(result.data[index])
  171. }
  172. }
  173. } catch (error) {
  174. console.error('获取行政区划数据失败:', error);
  175. }
  176. })
  177. //2.获得商城导航 start ---------------------------------------->
  178. //3.地区滚动 start ---------------------------------------->
  179. // 地区选择
  180. const shop_name_num = ref(1)
  181. const shop_name_parent = ref(null)
  182. const shop_name_leng = ref(1)
  183. onMounted(() => {
  184. const shop_name_son = shop_name_parent.value.querySelectorAll("div")
  185. shop_name_leng.value = shop_name_son.length
  186. })
  187. //3.地区滚动 end ---------------------------------------->
  188. </script>
  189. <style lang="less" scoped>
  190. .shop_name_out {
  191. margin-top: 20px;
  192. }
  193. .shop_name_box {
  194. border-top: solid 1px #fff;
  195. .shop_name_box_a {
  196. height: 44px;
  197. line-height: 44px;
  198. color: #fff;
  199. font-weight: bold;
  200. font-size: 20px;
  201. }
  202. .shop_name {
  203. float: left;
  204. height: 44px;
  205. line-height: 44px;
  206. color: #fff;
  207. font-weight: bold;
  208. position: relative;
  209. z-index: 11;
  210. text-align: center;
  211. font-size: 20px;
  212. background: #A01C0E;
  213. padding: 0px 14px;
  214. }
  215. .shop_name_right {
  216. height: 40px;
  217. border-bottom: 1px solid #E8E9EC;
  218. margin-top: 4px;
  219. background: #F8F8F8;
  220. position: relative;
  221. z-index: 2;
  222. }
  223. .shop_name_right::after {
  224. content: '';
  225. display: block;
  226. position: absolute;
  227. top: 0px;
  228. right: 0px;
  229. height: 100%;
  230. width: 16px;
  231. background: url(@/public/img/9.png) no-repeat 0px bottom #fff;
  232. background-size: 100% auto;
  233. }
  234. .shop_name_btn {
  235. width: 24px;
  236. height: 24px;
  237. float: right;
  238. margin: 10px 22px 0px 0px;
  239. background: url(@/public/img/8.png) no-repeat center center;
  240. border-radius: 50%;
  241. background-size: 100% 100%;
  242. }
  243. }
  244. .shop_name_in {
  245. float: left;
  246. height: 40px;
  247. width: 1046px;
  248. float: left;
  249. box-sizing: border-box;
  250. .shop_name_a {
  251. float: left;
  252. height: 27px;
  253. line-height: 27px;
  254. color: #222;
  255. font-size: 20px;
  256. position: relative;
  257. margin: 7px 14.5px 0;
  258. padding: 0px 10px;
  259. cursor: pointer;
  260. }
  261. .shop_name_a::after {
  262. content: '/';
  263. display: block;
  264. position: absolute;
  265. top: 0px;
  266. right: -18px;
  267. height: 100%;
  268. line-height: 27px;
  269. color: #E9E9E9;
  270. font-size: 20px;
  271. }
  272. .shop_name_a:nth-last-of-type(1)::after {
  273. content: '';
  274. display: none;
  275. }
  276. .shop_name_a_only {
  277. background: #A01C0E;
  278. color: #fff;
  279. }
  280. }
  281. .shop_name_out {
  282. margin-top: 20px;
  283. }
  284. .shop_name_box {
  285. border-top: solid 1px #fff;
  286. .shop_name_box_a {
  287. height: 44px;
  288. line-height: 44px;
  289. color: #fff;
  290. font-weight: bold;
  291. font-size: 20px;
  292. }
  293. .shop_name {
  294. float: left;
  295. height: 44px;
  296. line-height: 44px;
  297. color: #fff;
  298. font-weight: bold;
  299. position: relative;
  300. z-index: 11;
  301. text-align: center;
  302. font-size: 20px;
  303. background: #A01C0E;
  304. padding: 0px 14px;
  305. }
  306. .shop_name_right {
  307. height: 40px;
  308. border-bottom: 1px solid #E8E9EC;
  309. margin-top: 4px;
  310. background: #F8F8F8;
  311. position: relative;
  312. z-index: 2;
  313. }
  314. .shop_name_right::after {
  315. content: '';
  316. display: block;
  317. position: absolute;
  318. top: 0px;
  319. right: 0px;
  320. height: 100%;
  321. width: 16px;
  322. background: url(@/public/img/9.png) no-repeat 0px bottom #fff;
  323. background-size: 100% auto;
  324. }
  325. .shop_name_btn {
  326. width: 24px;
  327. height: 24px;
  328. float: right;
  329. margin: 10px 22px 0px 0px;
  330. background: url(@/public/img/8.png) no-repeat center center;
  331. border-radius: 50%;
  332. background-size: 100% 100%;
  333. }
  334. }
  335. .shop_nav {
  336. border: solid 1px #E9E9E9;
  337. background: #fafafa;
  338. margin-top: 20px;
  339. .shop_nav_head {
  340. float: left;
  341. height: 28px;
  342. width: 138px;
  343. margin: 30px 52px 0px 25px;
  344. }
  345. .shop_nav_head_a {
  346. display: block;
  347. height: 28px;
  348. width: 138px;
  349. background: url(@/public/img/7.png) no-repeat left top;
  350. background-size: 100% 100%;
  351. }
  352. }
  353. .clearfix {
  354. overflow: hidden;
  355. }
  356. .shop_nav_in_a {
  357. float: left;
  358. height: 75px;
  359. line-height: 75px;
  360. color: #333;
  361. font-size: 16px;
  362. background: #f8f5f5;
  363. width: 118px;
  364. border-bottom: solid 5px #A01C0E;
  365. font-weight: bold;
  366. margin: 5px 0;
  367. text-align: center;
  368. }
  369. .shop_nav_in_a:nth-of-type(4) {
  370. margin-right: 8px;
  371. }
  372. .shop_nav_in_a:hover {
  373. color: #A01C0E;
  374. }
  375. .shop_nav_in_a_active {
  376. color: #A01C0E;
  377. }
  378. </style>
  379. <style lang="less" scoped>
  380. @media screen and (min-width:801px){/*pc*/
  381. .pc_none{display:none;}
  382. }
  383. @media screen and (max-width:800px){/*ipad_phone*/
  384. .index_main{width:100%;margin:0px auto;}
  385. .phone_nav{
  386. width:100%; box-sizing:border-box;background:#fafafa;
  387. margin:10px auto;height:33px;padding:0px 4%;
  388. .phone_nav_in{
  389. overflow-x:auto;overflow-y:hidden;word-break: keep-all; white-space: nowrap;
  390. height:33px;line-height:33px;
  391. }
  392. .phone_nav_in::-webkit-scrollbar{height:0px;}
  393. .phone_nav_a_head{float:left;}
  394. .phone_nav_a{display:inline-block;line-height:33px;height:33px;
  395. color:#333;font-size:14px;margin:0px 10px;
  396. }
  397. .phone_nav_a:nth-of-type(1){margin-left:0px;}
  398. }
  399. .router-link-exact-active.phone_nav_a{
  400. color:#A01C0E;
  401. }
  402. .shop_name_out{display:none;}
  403. .phone_none{display:none;}
  404. }
  405. </style>