list_sec.vue 16 KB

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