list.vue 16 KB

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