subMenu2.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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中是否含有select参数,如果有就删掉
  108. cityId.value = item.id;
  109. // 复制当前的 query 对象
  110. const newQuery = { ...route.query };
  111. // 更新 cityid
  112. newQuery.cityid = item.id;
  113. // 检查是否有 select 参数,如果有则删除
  114. if ('select' in newQuery) {
  115. delete newQuery.select;
  116. }
  117. // 使用 router.replace 更新 URL
  118. router.replace({
  119. query: newQuery
  120. });
  121. }
  122. //1.5 监听路由变化
  123. watch(() => route.query.cityid, (newVal, oldVal) => {
  124. if(newVal == undefined){
  125. cityId.value = ''
  126. }
  127. })
  128. //1.获得商城导航 end ---------------------------------------->
  129. //2.获得省列表 start ---------------------------------------->
  130. const provinceList1 = ref([]);//省列表1
  131. const provinceList2 = ref([]);//省列表2
  132. const provinceList3 = ref([]);//省列表3
  133. onMounted(async () => {
  134. //获得所有的省
  135. try {
  136. const { $webUrl, $CwebUrl } = useNuxtApp();
  137. const response = await fetch($webUrl + '/web/selectWebsiteArea', {
  138. headers: {
  139. 'Content-Type': 'application/json',
  140. 'Userurl': $CwebUrl,
  141. 'Origin': $CwebUrl
  142. }
  143. });
  144. const result = await response.json();
  145. for(let index in result.data){
  146. if(index < 15){
  147. provinceList1.value.push(result.data[index])
  148. }else if(index > 14 && index < 30){
  149. provinceList2.value.push(result.data[index])
  150. }else if(index > 29){
  151. provinceList3.value.push(result.data[index])
  152. }
  153. }
  154. } catch (error) {
  155. console.error('获取行政区划数据失败:', error);
  156. }
  157. })
  158. //2.获得商城导航 start ---------------------------------------->
  159. //3.地区滚动 start ---------------------------------------->
  160. // 地区选择
  161. const shop_name_num = ref(1)
  162. const shop_name_parent = ref(null)
  163. const shop_name_leng = ref(1)
  164. onMounted(() => {
  165. const shop_name_son = shop_name_parent.value.querySelectorAll("div")
  166. shop_name_leng.value = shop_name_son.length
  167. })
  168. //3.地区滚动 end ---------------------------------------->
  169. </script>
  170. <style lang="less" scoped>
  171. .shop_name_out {
  172. margin-top: 20px;
  173. }
  174. .shop_name_box {
  175. border-top: solid 1px #fff;
  176. .shop_name_box_a {
  177. height: 44px;
  178. line-height: 44px;
  179. color: #fff;
  180. font-weight: bold;
  181. font-size: 20px;
  182. }
  183. .shop_name {
  184. float: left;
  185. height: 44px;
  186. line-height: 44px;
  187. color: #fff;
  188. font-weight: bold;
  189. position: relative;
  190. z-index: 11;
  191. text-align: center;
  192. font-size: 20px;
  193. background: #A01C0E;
  194. padding: 0px 14px;
  195. }
  196. .shop_name_right {
  197. height: 40px;
  198. border-bottom: 1px solid #E8E9EC;
  199. margin-top: 4px;
  200. background: #F8F8F8;
  201. position: relative;
  202. z-index: 2;
  203. }
  204. .shop_name_right::after {
  205. content: '';
  206. display: block;
  207. position: absolute;
  208. top: 0px;
  209. right: 0px;
  210. height: 100%;
  211. width: 16px;
  212. background: url(@/public/img/9.png) no-repeat 0px bottom #fff;
  213. background-size: 100% auto;
  214. }
  215. .shop_name_btn {
  216. width: 24px;
  217. height: 24px;
  218. float: right;
  219. margin: 10px 22px 0px 0px;
  220. background: url(@/public/img/8.png) no-repeat center center;
  221. border-radius: 50%;
  222. background-size: 100% 100%;
  223. }
  224. }
  225. .shop_name_in {
  226. float: left;
  227. height: 40px;
  228. width: 1046px;
  229. float: left;
  230. box-sizing: border-box;
  231. .shop_name_a {
  232. float: left;
  233. height: 27px;
  234. line-height: 27px;
  235. color: #222;
  236. font-size: 20px;
  237. position: relative;
  238. margin: 7px 14.5px 0;
  239. padding: 0px 10px;
  240. cursor: pointer;
  241. }
  242. .shop_name_a::after {
  243. content: '/';
  244. display: block;
  245. position: absolute;
  246. top: 0px;
  247. right: -18px;
  248. height: 100%;
  249. line-height: 27px;
  250. color: #E9E9E9;
  251. font-size: 20px;
  252. }
  253. .shop_name_a:nth-last-of-type(1)::after {
  254. content: '';
  255. display: none;
  256. }
  257. .shop_name_a_only {
  258. background: #A01C0E;
  259. color: #fff;
  260. }
  261. }
  262. .shop_name_out {
  263. margin-top: 20px;
  264. }
  265. .shop_name_box {
  266. border-top: solid 1px #fff;
  267. .shop_name_box_a {
  268. height: 44px;
  269. line-height: 44px;
  270. color: #fff;
  271. font-weight: bold;
  272. font-size: 20px;
  273. }
  274. .shop_name {
  275. float: left;
  276. height: 44px;
  277. line-height: 44px;
  278. color: #fff;
  279. font-weight: bold;
  280. position: relative;
  281. z-index: 11;
  282. text-align: center;
  283. font-size: 20px;
  284. background: #A01C0E;
  285. padding: 0px 14px;
  286. }
  287. .shop_name_right {
  288. height: 40px;
  289. border-bottom: 1px solid #E8E9EC;
  290. margin-top: 4px;
  291. background: #F8F8F8;
  292. position: relative;
  293. z-index: 2;
  294. }
  295. .shop_name_right::after {
  296. content: '';
  297. display: block;
  298. position: absolute;
  299. top: 0px;
  300. right: 0px;
  301. height: 100%;
  302. width: 16px;
  303. background: url(@/public/img/9.png) no-repeat 0px bottom #fff;
  304. background-size: 100% auto;
  305. }
  306. .shop_name_btn {
  307. width: 24px;
  308. height: 24px;
  309. float: right;
  310. margin: 10px 22px 0px 0px;
  311. background: url(@/public/img/8.png) no-repeat center center;
  312. border-radius: 50%;
  313. background-size: 100% 100%;
  314. }
  315. }
  316. .shop_nav {
  317. border: solid 1px #E9E9E9;
  318. background: #fafafa;
  319. margin-top: 20px;
  320. .shop_nav_head {
  321. float: left;
  322. height: 28px;
  323. width: 138px;
  324. margin: 30px 52px 0px 25px;
  325. }
  326. .shop_nav_head_a {
  327. display: block;
  328. height: 28px;
  329. width: 138px;
  330. background: url(@/public/img/7.png) no-repeat left top;
  331. background-size: 100% 100%;
  332. }
  333. }
  334. .clearfix {
  335. overflow: hidden;
  336. }
  337. .shop_nav_in_a {
  338. float: left;
  339. height: 75px;
  340. line-height: 75px;
  341. color: #333;
  342. font-size: 16px;
  343. background: #f8f5f5;
  344. width: 118px;
  345. border-bottom: solid 5px #A01C0E;
  346. font-weight: bold;
  347. margin: 5px 0;
  348. text-align: center;
  349. }
  350. .shop_nav_in_a:nth-of-type(4) {
  351. margin-right: 8px;
  352. }
  353. .shop_nav_in_a:hover {
  354. color: #A01C0E;
  355. }
  356. .shop_nav_in_a_active {
  357. color: #A01C0E;
  358. }
  359. </style>