index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <view :style="colorStyle">
  3. <view class='newsList'>
  4. <view class='swiper' v-if="imgUrls.length > 0">
  5. <swiper indicator-dots="true" :autoplay="autoplay" :circular="circular" :interval="interval"
  6. :duration="duration" indicator-color="rgba(102,102,102,0.3)" indicator-active-color="#666">
  7. <block v-for="(item,index) in imgUrls" :key="index">
  8. <swiper-item>
  9. <navigator :url="'/pages/extension/news_details/index?id='+item.id">
  10. <image :src="item.image_input[0]" class="slide-image" />
  11. </navigator>
  12. </swiper-item>
  13. </block>
  14. </swiper>
  15. </view>
  16. <view class='nav' v-if="navList.length > 0">
  17. <scroll-view class="scroll-view_x" scroll-x scroll-with-animation :scroll-left="scrollLeft"
  18. style="width:auto;overflow:hidden;">
  19. <block v-for="(item,index) in navList" :key="index">
  20. <view class='item' :class='active==item.id?"on":""' @click='tabSelect(item.id, index, item)'
  21. :id="`news_${item.id}`">
  22. <view>{{item.title}}</view>
  23. <view class='line bg-color' v-if="active==item.id"></view>
  24. </view>
  25. </block>
  26. </scroll-view>
  27. <scroll-view v-if="coutList.length" class="scroll-view_x" scroll-x scroll-with-animation style="width:auto;overflow:hidden;">
  28. <view class="coutry-list">
  29. <view class="coutry" :class='activeCou==coutry.id?"on":""' v-for="(coutry,index) in coutList"
  30. :key="index" @click="getCidArticle(coutry.id,1)">
  31. {{coutry.title}}
  32. </view>
  33. </view>
  34. </scroll-view>
  35. </view>
  36. <view class='list'>
  37. <block v-for="(item,index) in articleList" :key="index">
  38. <navigator :url='"/pages/extension/news_details/index?id="+item.id' hover-class='none'
  39. class='item acea-row row-between-wrapper' v-if="item.image_input.length == 1">
  40. <view class='text acea-row row-column-between'>
  41. <view class='name line2'>{{item.title}}</view>
  42. <view>{{item.add_time}}</view>
  43. </view>
  44. <view class='pictrue'>
  45. <image :src='item.image_input[0]'></image>
  46. </view>
  47. </navigator>
  48. <navigator :url='"/pages/extension/news_details/index?id="+item.id' hover-class='none' class='item'
  49. v-else-if="item.image_input.length == 2">
  50. <view class='title line1'>{{item.title}}</view>
  51. <view class='picList acea-row row-between-wrapper'>
  52. <block v-for="(itemImg,indexImg) in item.image_input" :key="indexImg">
  53. <view class='pictrue'>
  54. <image :src='itemImg'></image>
  55. </view>
  56. </block>
  57. </view>
  58. <view class='time'>{{item.add_time}}</view>
  59. </navigator>
  60. <navigator :url='"/pages/extension/news_details/index?id="+item.id' hover-class='none' class='item'
  61. v-else-if="item.image_input.length > 2">
  62. <view class='title line1'>{{item.title}}</view>
  63. <view class='picList on acea-row row-between-wrapper'>
  64. <block v-for="(itemImg,indexImg) in item.image_input" :key="indexImg">
  65. <view class='pictrue'>
  66. <image :src='itemImg'></image>
  67. </view>
  68. </block>
  69. </view>
  70. <view class='time'>{{item.add_time}}</view>
  71. </navigator>
  72. </block>
  73. </view>
  74. </view>
  75. <view class='noCommodity' v-if="articleList.length == 0 && (page != 1 || active== 0)">
  76. <view class='emptyBox'>
  77. <image :src="imgHost + '/statics/images/empty-box.png'"></image>
  78. </view>
  79. </view>
  80. <!-- #ifndef MP -->
  81. <home></home>
  82. <!-- #endif -->
  83. </view>
  84. </template>
  85. <script>
  86. import {
  87. getArticleCategoryList,
  88. getArticleList,
  89. getArticleHotList,
  90. getArticleBannerList
  91. } from '@/api/api.js';
  92. import home from '@/components/home';
  93. import colors from "@/mixins/color";
  94. import {
  95. HTTP_REQUEST_URL
  96. } from '@/config/app';
  97. export default {
  98. components: {
  99. home
  100. },
  101. mixins: [colors],
  102. data() {
  103. return {
  104. imgHost: HTTP_REQUEST_URL,
  105. coutList: [],
  106. imgUrls: [],
  107. articleList: [],
  108. indicatorDots: false,
  109. circular: true,
  110. autoplay: true,
  111. interval: 3000,
  112. duration: 500,
  113. navList: [],
  114. active: 0,
  115. page: 1,
  116. limit: 8,
  117. status: false,
  118. scrollLeft: 0,
  119. activeCou: 0
  120. };
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function() {
  126. this.getArticleHot();
  127. this.getArticleBanner();
  128. this.getArticleCate();
  129. this.status = false;
  130. this.page = 1;
  131. this.articleList = [];
  132. },
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom: function() {
  137. this.getCidArticle(this.activeCou);
  138. },
  139. methods: {
  140. getArticleHot: function() {
  141. let that = this;
  142. getArticleHotList().then(res => {
  143. that.$set(that, 'articleList', res.data);
  144. });
  145. },
  146. getArticleBanner: function() {
  147. let that = this;
  148. getArticleBannerList().then(res => {
  149. that.imgUrls = res.data;
  150. });
  151. },
  152. getCidArticle(id, type) {
  153. let that = this;
  154. if (type) {
  155. that.status = false
  156. this.activeCou = id
  157. this.$set(this, 'articleList', []);
  158. that.page = 1
  159. }
  160. // if (id == 0) return;
  161. let limit = that.limit;
  162. let page = that.page;
  163. let articleList = that.articleList;
  164. if (that.status) return;
  165. getArticleList(that.activeCou, {
  166. page: page,
  167. limit: limit
  168. }).then(res => {
  169. let articleListNew = [];
  170. let len = res.length;
  171. articleListNew = articleList.concat(res.data);
  172. that.page++;
  173. that.$set(that, 'articleList', articleListNew);
  174. that.status = limit > len;
  175. that.page = that.page;
  176. });
  177. },
  178. getArticleCate() {
  179. let that = this;
  180. getArticleCategoryList().then(res => {
  181. that.$set(that, 'navList', res.data);
  182. });
  183. },
  184. tabSelect(active, e, item) {
  185. this.active = active;
  186. this.scrollLeft = e * 60;
  187. // this.scrollLeft = (active - 1) * 50;
  188. if (this.active == 0) {
  189. this.$set(this, 'coutList', []);
  190. this.$set(this, 'articleList', []);
  191. this.getArticleHot();
  192. } else {
  193. this.$set(this, 'articleList', []);
  194. this.$set(this, 'coutList', []);
  195. if (item.children.length) {
  196. this.page = 1;
  197. this.status = false;
  198. this.activeCou = item.children[0].id || 0
  199. this.coutList = item.children || []
  200. this.$set(this, 'articleList', []);
  201. this.getCidArticle(this.activeCou);
  202. } else {
  203. this.page = 1;
  204. this.status = false;
  205. this.$set(this, 'articleList', []);
  206. this.getCidArticle(item.id, true);
  207. }
  208. }
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss">
  214. .noCommodity {
  215. border-top-width: 0;
  216. padding-bottom: 30rpx;
  217. .emptyBox {
  218. margin-top: 50rpx;
  219. text-align: center;
  220. .tips {
  221. color: #aaa;
  222. font-size: 26rpx;
  223. }
  224. image {
  225. width: 414rpx;
  226. height: 304rpx;
  227. }
  228. }
  229. }
  230. page {
  231. background-color: #fff !important;
  232. }
  233. .newsList .swiper {
  234. width: 100%;
  235. position: relative;
  236. box-sizing: border-box;
  237. padding: 30rpx 30rpx 0 30rpx;
  238. }
  239. .newsList .swiper swiper {
  240. width: 100%;
  241. height: 365rpx;
  242. position: relative;
  243. }
  244. .newsList .swiper .slide-image {
  245. width: 100%;
  246. height: 335rpx;
  247. border-radius: 6rpx;
  248. }
  249. // #ifdef APP-PLUS || H5
  250. .newsList /deep/uni-swiper .uni-swiper-dots-horizontal {
  251. bottom: 20px;
  252. }
  253. .newsList .swiper /deep/.uni-swiper-dot {
  254. width: 12rpx !important;
  255. height: 12rpx !important;
  256. border-radius: 0;
  257. transform: rotate(-45deg);
  258. transform-origin: 0 100%;
  259. }
  260. .newsList .swiper /deep/.uni-swiper-dot~.uni-swiper-dot {
  261. margin-left: 5rpx;
  262. }
  263. // #endif
  264. // #ifdef MP
  265. .newsList /deep/wx-swiper .wx-swiper-dots-horizontal {
  266. bottom: 0;
  267. }
  268. .newsList .swiper /deep/.wx-swiper-dot {
  269. width: 12rpx !important;
  270. height: 12rpx !important;
  271. border-radius: 0;
  272. transform: rotate(-45deg);
  273. transform-origin: 0 100%;
  274. }
  275. .newsList .swiper /deep/.wx-swiper-dot~.wx-swiper-dot {
  276. margin-left: 5rpx;
  277. }
  278. // #endif
  279. .newsList .nav {
  280. padding: 0 30rpx;
  281. width: 100%;
  282. white-space: nowrap;
  283. box-sizing: border-box;
  284. margin-top: 43rpx;
  285. }
  286. .newsList .nav .item {
  287. display: inline-block;
  288. font-size: 32rpx;
  289. color: #999999;
  290. }
  291. .newsList .nav .item.on {
  292. color: #000;
  293. font-size: 36rpx;
  294. font-weight: bold;
  295. }
  296. .newsList .nav .item~.item {
  297. margin-left: 46rpx;
  298. }
  299. .newsList .nav .item .line {
  300. width: 24rpx;
  301. height: 4rpx;
  302. border-radius: 2rpx;
  303. margin: 10rpx auto 0 auto;
  304. }
  305. .newsList .list {
  306. margin-top: 20rpx;
  307. }
  308. .newsList .list .item {
  309. margin: 0 30rpx;
  310. border-bottom: 1rpx solid #f0f0f0;
  311. padding: 35rpx 0;
  312. }
  313. .newsList .list .item .pictrue {
  314. width: 250rpx;
  315. height: 156rpx;
  316. }
  317. .newsList .list .item .pictrue image {
  318. width: 100%;
  319. height: 100%;
  320. border-radius: 6rpx;
  321. }
  322. .newsList .list .item .text {
  323. width: 420rpx;
  324. height: 156rpx;
  325. font-size: 24rpx;
  326. color: #999;
  327. }
  328. .newsList .list .item .text .name {
  329. font-size: 30rpx;
  330. color: #282828;
  331. }
  332. .newsList .list .item .picList .pictrue {
  333. width: 335rpx;
  334. height: 210rpx;
  335. margin-top: 30rpx;
  336. }
  337. .newsList .list .item .picList.on .pictrue {
  338. width: 217rpx;
  339. height: 136rpx;
  340. }
  341. .newsList .list .item .picList .pictrue image {
  342. width: 100%;
  343. height: 100%;
  344. border-radius: 6rpx;
  345. }
  346. .newsList .list .item .time {
  347. text-align: right;
  348. font-size: 24rpx;
  349. color: #999;
  350. margin-top: 22rpx;
  351. }
  352. .coutry-list {
  353. display: flex;
  354. align-items: center;
  355. margin: 10rpx 0;
  356. padding-top: 10rpx;
  357. border-top: 1px solid #F2F2F2;
  358. height: 80rpx;
  359. .coutry {
  360. // background-color: #F5F5F5;
  361. border-radius: 26rpx;
  362. padding: 4rpx 20rpx;
  363. color: #666666;
  364. font-size: 26rpx;
  365. margin-right: 20rpx;
  366. }
  367. .coutry.on {
  368. // background-color: rgba(220, 217, 236, 1);
  369. border-style: solid;
  370. border-width: 2rpx;
  371. color: #E93323;
  372. }
  373. }
  374. </style>