list_sec.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <template>
  2. <HomePageHead></HomePageHead>
  3. <HomePageNavigation></HomePageNavigation>
  4. <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>
  5. <!-- 商品列表 goods-->
  6. <main class="index_main">
  7. <section class="index_1 clearfix phone_none">
  8. <div class="shop_head_1 clearfix">
  9. <div class="shop_head_1_name">
  10. <NuxtLink :to="`/${targetSegment}/index.html`"> {{ parent_name }}</NuxtLink>
  11. </div>
  12. </div>
  13. <div class="shop_nav_2">
  14. <a class="shop_nav_2_a" :href="`/${targetSegment}/${item.aLIas_pinyin}/list-1.html`" title=""
  15. v-for="(item, index) in secondNav" :key="index"
  16. :class="{ 'active': item.aLIas_pinyin == targetSegment1 }">{{ item.alias }}</a>
  17. </div>
  18. </section>
  19. <div class="phone_nav pc_none">
  20. <div class="phone_nav_in">
  21. <a class="phone_nav_a" :href="`/${targetSegment}/${item.aLIas_pinyin}/list-1.html`" title=""
  22. v-for="(item, index) in secondNav" :key="index"
  23. :class="{ 'active': item.aLIas_pinyin == targetSegment1 }">{{ item.alias }}</a>
  24. </div>
  25. </div>
  26. <!-- 地区选择 -->
  27. <GoodsSubMenu1></GoodsSubMenu1>
  28. <!-- 三农市场网-商城-商品列表 1-->
  29. <section class="">
  30. <div class="breadcrumb phone_none">
  31. <div class="inner">
  32. <span class="location">当前位置:</span>
  33. <el-breadcrumb :separator-icon="ArrowRight">
  34. <el-breadcrumb-item>
  35. <NuxtLink to="/">首页</NuxtLink>
  36. </el-breadcrumb-item>
  37. <el-breadcrumb-item v-if="parent_name != ''">
  38. <NuxtLink :to="`/${targetSegment}/index.html`"> {{ parent_name }}</NuxtLink>
  39. </el-breadcrumb-item>
  40. <el-breadcrumb-item>{{ navTitle }}</el-breadcrumb-item>
  41. </el-breadcrumb>
  42. </div>
  43. </div>
  44. <div class="breadcrumb_box pc_none">
  45. <span class=" ">当前位置:</span>
  46. <NuxtLink to="/">首页</NuxtLink>
  47. <span class=" ">&gt;</span>
  48. <NuxtLink :to="`/${targetSegment}/index.html`" v-if="parent_name != ''"> {{ parent_name }}</NuxtLink>
  49. <span class=" " v-if="parent_name != ''">&gt;</span>
  50. {{ navTitle }}
  51. </div>
  52. <!-- 商品列表 -->
  53. <div class="categ_table clearfix">
  54. <div class="categ_table_head_box">
  55. <div class="categ_table_td_1">产品图片</div>
  56. <div class="categ_table_td_2">供求信息/公司</div>
  57. <div class="categ_table_td_3">发布时间</div>
  58. <div class="categ_table_td_4">地区</div>
  59. </div>
  60. <div class="categ_table_li" v-for="(item, index) in goodsList" :key="index">
  61. <a class="categ_table_li_a" :href="`/${item.pinyin}/${item.id}.html`" title="">
  62. <div class="categ_table_td_1">
  63. <img class="categ_table_td_1_img" :src="item.imgurl" title="" alt="">
  64. </div>
  65. <div class="categ_table_td_2 ">
  66. <div class="categ_table_td_2_in">
  67. <div class="categ_table_td_2_dot1 dot1">
  68. {{ item.name }}
  69. </div>
  70. <div class="categ_table_td_2_dot2 dot2">
  71. {{ item.description }}
  72. </div>
  73. </div>
  74. </div>
  75. <div class="categ_table_td_3">{{ getTime(item.updated_at, 'year', 1) }}</div>
  76. <div class="categ_table_td_4 dot1">{{ item.city_name }}</div>
  77. </a>
  78. </div>
  79. <div class="empty" v-if="goodsList == false">
  80. <img src="@/public/topic/empty.png" alt="" class="empty_img">
  81. <span class="empty_text">当前暂无数据</span>
  82. </div>
  83. </div>
  84. <div class="pagination1 page_phone_none" v-if="goodstotal > 0">
  85. <el-pagination background
  86. layout="prev, pager, next"
  87. :total="goodstotal"
  88. :page-size="pageSize_goods"
  89. prev-text="上一页"
  90. next-text="下一页" />
  91. </div>
  92. <div class="pagination1 page_pc_none" v-if="goodstotal > 0">
  93. <el-pagination
  94. pager-count="5"
  95. size="small"
  96. background
  97. layout=" pager "
  98. :total="goodstotal"
  99. class="mt-4"
  100. :page-size="pageSize_goods"
  101. />
  102. </div>
  103. </section>
  104. <!-- 三农市场网-商城-商品列表 2-->
  105. </main>
  106. <HomeAdvertising :imgurl="adImg2"></HomeAdvertising>
  107. <HomeFoot></HomeFoot>
  108. </template>
  109. <script setup>
  110. //0.加载页面依赖 start ---------------------------------------->
  111. import { ref, onMounted } from 'vue';
  112. import { ElMessage, ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus';
  113. import { ArrowRight } from '@element-plus/icons-vue'
  114. import { NuxtLink } from '#components';
  115. //0.加载页面依赖 end ---------------------------------------->
  116. //1.获得路由id start ---------------------------------------->
  117. const targetSegment = getRoutePath(1);
  118. const targetSegment1 = getRoutePath(2);
  119. const allSegment = targetSegment + '/' + targetSegment1;
  120. const route = useRoute();
  121. let cityid = route.query.cityid;
  122. let cityId = ref(0)
  123. cityId.value = parseFloat(cityid)
  124. //1.1 获得当前的路由id
  125. let routeId;
  126. let routeType;
  127. let navTitle = ref('')//二级导航标题
  128. let navCid = ref('')//二级导航id
  129. //通过导航路径反向查询导航id
  130. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  131. method: 'GET',
  132. query: {
  133. 'pinyin': allSegment,
  134. },
  135. });
  136. console.log("getRouteId", getRouteId);
  137. if (getRouteId.code == 200) {
  138. navTitle.value = getRouteId.data.alias
  139. navCid.value = getRouteId.data.category_id
  140. } else {
  141. console.log("获得路由id出错!", getRouteId.message)
  142. }
  143. //1.2 获取父级栏目
  144. let parent_name = ref('');//父级名称
  145. let parent_id = ref('');//父级id
  146. let parent_pinyin = ref('');//父级拼音
  147. const getRoutePName = await requestDataPromise('/web/getWebsiteRoute', {
  148. method: 'GET',
  149. query: {
  150. 'pinyin': targetSegment,
  151. },
  152. });
  153. console.log("getRoutePName", getRoutePName);
  154. if (getRoutePName.code == 200) {
  155. routeId = getRoutePName.data.category_id
  156. parent_id.value = getRoutePName.data.category_id
  157. parent_name.value = getRoutePName.data.alias
  158. routeType = getRoutePName.data.type
  159. } else {
  160. console.log("获得路由id出错!", getRoutePName.message)
  161. }
  162. //1.3 获取某个栏目
  163. const getParentId = await requestDataPromise('/web/getOneWebsiteCategory', {
  164. method: 'GET',
  165. query: {
  166. 'catid': parent_id.value,
  167. },
  168. });
  169. console.log("getParentId", getParentId);
  170. if (getParentId.code == 200) {
  171. parent_pinyin.value = getParentId.data.aLIas_pinyin
  172. } else {
  173. console.log("获得路由id出错!", getParentId.message)
  174. }
  175. //1.获得路由id end ---------------------------------------->
  176. //2.选项卡 start ---------------------------------------->
  177. let showTabs = ref(1)
  178. let qhtabs = function (number) {
  179. console.log(number)
  180. showTabs.value = number
  181. }
  182. //2.选项卡 end ---------------------------------------->
  183. //3.广告 start ---------------------------------------->
  184. let adImg1 = ref({})
  185. let adImg2 = ref({})
  186. onMounted(async () => {
  187. //从客户端获取行政职能部门 加快打开速度
  188. const { $webUrl, $CwebUrl } = useNuxtApp();
  189. //广告1
  190. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_list_0001`
  191. const responseAd1 = await fetch(url, {
  192. headers: {
  193. 'Content-Type': 'application/json',
  194. 'Userurl': $CwebUrl,
  195. 'Origin': $CwebUrl
  196. }
  197. });
  198. const resultAd1 = await responseAd1.json();
  199. adImg1.value = resultAd1.data[0];
  200. //广告2
  201. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_list_0002`
  202. const responseAd2 = await fetch(url2, {
  203. headers: {
  204. 'Content-Type': 'application/json',
  205. 'Userurl': $CwebUrl,
  206. 'Origin': $CwebUrl
  207. }
  208. });
  209. const resultAd2 = await responseAd2.json();
  210. adImg2.value = resultAd2.data[0];
  211. })
  212. //3.广告 end ---------------------------------------->
  213. //4.页面数据 start ---------------------------------------->
  214. const secondNav = ref([]);
  215. let getSecondNav = async () => {
  216. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  217. method: 'GET',
  218. query: {
  219. 'placeid': 1,
  220. 'pid': parent_id.value,
  221. 'num': 20,
  222. 'type': 1
  223. },
  224. });
  225. console.log('listData', listData);
  226. if (listData.code == 200) {
  227. secondNav.value = listData.data;
  228. } else {
  229. console.log("错误位置:获取二级栏目列表")
  230. }
  231. }
  232. getSecondNav()
  233. // 获取商品数据列表 start--------------------------------------->
  234. const goodsList = ref()
  235. const page_goods = ref(1)
  236. const pageSize_goods = ref(20)
  237. const goodstotal = ref()
  238. let getshop = async () => {
  239. let params = {
  240. 'catid': navCid.value,
  241. 'city_id': cityId.value,
  242. 'page': page_goods.value,
  243. 'pageSize': pageSize_goods.value,
  244. 'ismix': 1
  245. }
  246. if (cityId.value == undefined || cityId.value == '' || cityId.value == 'NaN') {
  247. //删除变量params中的city_id参数
  248. delete params.city_id
  249. } else {
  250. params.city_id = parseFloat(cityId.value)
  251. }
  252. const getGoodsList = await requestDataPromise('/web/getWebsiteshopList', {
  253. method: 'GET',
  254. query: params
  255. });
  256. console.log("获取数据列表goods", getGoodsList);
  257. if (getGoodsList.code == 200) {
  258. goodsList.value = getGoodsList.data.goods
  259. goodstotal.value = getGoodsList.data.count
  260. }
  261. }
  262. let getshop1 = async () => {
  263. let params = {
  264. 'catid': navCid.value,
  265. 'page': page_goods.value,
  266. 'pageSize': pageSize_goods.value,
  267. 'ismix': 1
  268. }
  269. const getGoodsList = await requestDataPromise('/web/getWebsiteshopList', {
  270. method: 'GET',
  271. query: params
  272. });
  273. // console.log("获取数据列表goods", getGoodsList);
  274. if (getGoodsList.code == 200) {
  275. goodsList.value = getGoodsList.data.goods
  276. goodstotal.value = getGoodsList.data.count
  277. }
  278. }
  279. // getshop1()
  280. //4.4.1 监听cityid
  281. watch(() => route.query.cityid, (newVal, oldVal) => {
  282. if (newVal != undefined) {
  283. cityId.value = parseFloat(newVal)
  284. getshop()
  285. } else {
  286. getshop1()
  287. }
  288. }, {
  289. deep: true,
  290. immediate: true
  291. })
  292. // 获取商品数据 end----------------------------------------->
  293. //4.页面数据 end ---------------------------------------->
  294. //5.设置seo信息 start---------------------------------------->
  295. const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
  296. method: 'GET',
  297. query: {
  298. 'catid': navCid.value
  299. },
  300. });
  301. if (setData.code == 200) {
  302. let seoTitle = setData.data.seo_title;
  303. let seoDescription = setData.data.seo_description;
  304. let seoKeywords = setData.data.seo_keywords;
  305. let seoSuffix = setData.data.suffix;
  306. let seoName = setData.data.website_name;
  307. useSeoMeta({
  308. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  309. meta: [
  310. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  311. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  312. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  313. ]
  314. });
  315. } else {
  316. console.log("设置频道页SEO出错!", setData.message)
  317. }
  318. //5.设置seo信息 end---------------------------------------->
  319. </script>
  320. <style lang="less" scoped>
  321. @import url("@/assets/css/shop/goodsList.less");
  322. .empty {
  323. width: 100%;
  324. height: 300px;
  325. line-height: 300px;
  326. text-align: center;
  327. }
  328. .empty_img {
  329. vertical-align: -30px;
  330. margin-right: 20px;
  331. }
  332. .empty_text {
  333. font-size: 26px;
  334. color: #999;
  335. }
  336. .pagination {
  337. height: 100px;
  338. margin-top: 20px;
  339. }
  340. .pagination1 {
  341. height: 100px;
  342. margin-top: 20px;
  343. }
  344. </style>
  345. <style lang="less" scoped>
  346. @media screen and (min-width:801px){/*pc*/
  347. .page_pc_none{display:none!important;}
  348. .pc_none{display:none;}
  349. }
  350. @media screen and (max-width:800px){/*ipad_phone*/
  351. .index_main{width:100%;margin:0px auto;}
  352. .phone_nav{
  353. width:100%; box-sizing:border-box;background:#fafafa;
  354. margin:10px auto;height:33px;
  355. .phone_nav_in{ width:92%;margin:0px auto;
  356. overflow-x:auto;overflow-y:hidden;
  357. word-break: keep-all; white-space: nowrap;
  358. line-height:33px;
  359. height:33px;
  360. }
  361. .phone_nav_in::-webkit-scrollbar{height:0px;}
  362. .phone_nav_a{display:inline-block;line-height:33px;height:33px;
  363. color:#333;font-size:14px;margin:0px 10px;
  364. }
  365. .phone_nav_a:nth-of-type(1){margin-left:0px;}
  366. }
  367. .phone_nav_a.active{
  368. color:#A01C0E;
  369. }
  370. .breadcrumb_box{
  371. height:22px;width:100%;margin:10px auto;
  372. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  373. width:92%;
  374. font-size:14px;
  375. color:#666;
  376. *{
  377. font-size:14px;
  378. display:inline ;
  379. color:#666;
  380. line-height:22px;height:22px;
  381. margin-right:5px;
  382. }
  383. }
  384. .categ_table{width:92%;margin:0px auto 0px; }
  385. .categ_table_li{
  386. height:auto;padding:10px 0px;overflow:hidden;
  387. a{display:block;overflow:hidden;}
  388. .categ_table_td_1{height:33vw;width:33vw;margin-right:0px; }
  389. .categ_table_td_1_img{width:100%;height:100%;}
  390. .categ_table_td_2{width:55vw; margin-right:0;float:right;height:auto;}
  391. .categ_table_td_2_in{width:100%;display:block;vertical-align:top;height:auto;}
  392. .categ_table_td_2_dot1{width:100%;margin-top:8px;}
  393. .categ_table_td_2_dot2{width:100%;margin:8px 0;-webkit-line-clamp:1;height:18px;}
  394. .categ_table_td_2_dot3{width:100%;-webkit-line-clamp:1;}
  395. .categ_table_td_3{
  396. float:left;text-align:right;width:auto;line-height:22px!important;height:22px;margin:0 4vw;font-size:14px;
  397. border:solid 1px #E9E9E9;
  398. padding:0px 4px;
  399. }
  400. .categ_table_td_4{
  401. padding:0px 4px;
  402. border:solid 1px #E9E9E9;
  403. height:22px;line-height:22px!important;float:left;text-align:right;width:auto;font-size:14px;
  404. }
  405. }
  406. .pagination1{margin:25px auto 0px;width:100%;height:auto;}
  407. .page_phone_none{display:none!important;}
  408. .pagination1 /deep/.el-pagination.is-background .el-pager li{margin:0px 4px;}
  409. .categ_table_head_box{display:none;}
  410. .phone_none{display:none;}
  411. }
  412. </style>