subMenu2.vue 10 KB

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