index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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.getCidArticle(0);
  128. this.getArticleBanner();
  129. this.getArticleCate();
  130. this.status = false;
  131. this.page = 1;
  132. this.articleList = [];
  133. },
  134. /**
  135. * 页面上拉触底事件的处理函数
  136. */
  137. onReachBottom: function() {
  138. this.getCidArticle(this.activeCou);
  139. },
  140. methods: {
  141. getArticleHot: function() {
  142. let that = this;
  143. getArticleHotList().then(res => {
  144. that.$set(that, 'articleList', res.data);
  145. });
  146. },
  147. getArticleBanner: function() {
  148. let that = this;
  149. getArticleBannerList().then(res => {
  150. that.imgUrls = res.data;
  151. });
  152. },
  153. getCidArticle(id, type) {
  154. let that = this;
  155. if (type) {
  156. that.status = false
  157. this.activeCou = id
  158. this.$set(this, 'articleList', []);
  159. that.page = 1
  160. }
  161. // if (id == 0) return;
  162. let limit = that.limit;
  163. let page = that.page;
  164. let articleList = that.articleList;
  165. if (that.status) return;
  166. getArticleList(that.activeCou, {
  167. page: page,
  168. limit: limit
  169. }).then(res => {
  170. let articleListNew = [];
  171. let len = res.length;
  172. articleListNew = articleList.concat(res.data);
  173. that.page++;
  174. that.$set(that, 'articleList', articleListNew);
  175. that.status = limit > len;
  176. that.page = that.page;
  177. });
  178. },
  179. getArticleCate() {
  180. let that = this;
  181. getArticleCategoryList().then(res => {
  182. that.$set(that, 'navList', res.data);
  183. });
  184. },
  185. tabSelect(active, e, item) {
  186. this.active = active;
  187. this.scrollLeft = e * 60;
  188. // this.scrollLeft = (active - 1) * 50;
  189. if (this.active == 0) {
  190. this.$set(this, 'coutList', []);
  191. this.$set(this, 'articleList', []);
  192. this.getArticleHot();
  193. } else {
  194. this.$set(this, 'articleList', []);
  195. this.$set(this, 'coutList', []);
  196. if (item.children.length) {
  197. this.page = 1;
  198. this.status = false;
  199. this.activeCou = item.children[0].id || 0
  200. this.coutList = item.children || []
  201. this.$set(this, 'articleList', []);
  202. this.getCidArticle(this.activeCou);
  203. } else {
  204. this.page = 1;
  205. this.status = false;
  206. this.$set(this, 'articleList', []);
  207. this.getCidArticle(item.id, true);
  208. }
  209. }
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang="scss">
  215. .noCommodity {
  216. border-top-width: 0;
  217. padding-bottom: 30rpx;
  218. .emptyBox {
  219. margin-top: 50rpx;
  220. text-align: center;
  221. .tips {
  222. color: #aaa;
  223. font-size: 26rpx;
  224. }
  225. image {
  226. width: 414rpx;
  227. height: 304rpx;
  228. }
  229. }
  230. }
  231. page {
  232. background-color: #fff !important;
  233. }
  234. .newsList .swiper {
  235. width: 100%;
  236. position: relative;
  237. box-sizing: border-box;
  238. padding: 30rpx 30rpx 0 30rpx;
  239. }
  240. .newsList .swiper swiper {
  241. width: 100%;
  242. height: 365rpx;
  243. position: relative;
  244. }
  245. .newsList .swiper .slide-image {
  246. width: 100%;
  247. height: 335rpx;
  248. border-radius: 6rpx;
  249. }
  250. // #ifdef APP-PLUS || H5
  251. .newsList /deep/uni-swiper .uni-swiper-dots-horizontal {
  252. bottom: 20px;
  253. }
  254. .newsList .swiper /deep/.uni-swiper-dot {
  255. width: 12rpx !important;
  256. height: 12rpx !important;
  257. border-radius: 0;
  258. transform: rotate(-45deg);
  259. transform-origin: 0 100%;
  260. }
  261. .newsList .swiper /deep/.uni-swiper-dot~.uni-swiper-dot {
  262. margin-left: 5rpx;
  263. }
  264. // #endif
  265. // #ifdef MP
  266. .newsList /deep/wx-swiper .wx-swiper-dots-horizontal {
  267. bottom: 0;
  268. }
  269. .newsList .swiper /deep/.wx-swiper-dot {
  270. width: 12rpx !important;
  271. height: 12rpx !important;
  272. border-radius: 0;
  273. transform: rotate(-45deg);
  274. transform-origin: 0 100%;
  275. }
  276. .newsList .swiper /deep/.wx-swiper-dot~.wx-swiper-dot {
  277. margin-left: 5rpx;
  278. }
  279. // #endif
  280. .newsList .nav {
  281. padding: 0 30rpx;
  282. width: 100%;
  283. white-space: nowrap;
  284. box-sizing: border-box;
  285. margin-top: 43rpx;
  286. }
  287. .newsList .nav .item {
  288. display: inline-block;
  289. font-size: 32rpx;
  290. color: #999999;
  291. }
  292. .newsList .nav .item.on {
  293. color: #000;
  294. font-size: 36rpx;
  295. font-weight: bold;
  296. }
  297. .newsList .nav .item~.item {
  298. margin-left: 46rpx;
  299. }
  300. .newsList .nav .item .line {
  301. width: 24rpx;
  302. height: 4rpx;
  303. border-radius: 2rpx;
  304. margin: 10rpx auto 0 auto;
  305. }
  306. .newsList .list {
  307. margin-top: 20rpx;
  308. }
  309. .newsList .list .item {
  310. margin: 0 30rpx;
  311. border-bottom: 1rpx solid #f0f0f0;
  312. padding: 35rpx 0;
  313. }
  314. .newsList .list .item .pictrue {
  315. width: 250rpx;
  316. height: 156rpx;
  317. }
  318. .newsList .list .item .pictrue image {
  319. width: 100%;
  320. height: 100%;
  321. border-radius: 6rpx;
  322. }
  323. .newsList .list .item .text {
  324. width: 420rpx;
  325. height: 156rpx;
  326. font-size: 24rpx;
  327. color: #999;
  328. }
  329. .newsList .list .item .text .name {
  330. font-size: 30rpx;
  331. color: #282828;
  332. }
  333. .newsList .list .item .picList .pictrue {
  334. width: 335rpx;
  335. height: 210rpx;
  336. margin-top: 30rpx;
  337. }
  338. .newsList .list .item .picList.on .pictrue {
  339. width: 217rpx;
  340. height: 136rpx;
  341. }
  342. .newsList .list .item .picList .pictrue image {
  343. width: 100%;
  344. height: 100%;
  345. border-radius: 6rpx;
  346. }
  347. .newsList .list .item .time {
  348. text-align: right;
  349. font-size: 24rpx;
  350. color: #999;
  351. margin-top: 22rpx;
  352. }
  353. .coutry-list {
  354. display: flex;
  355. align-items: center;
  356. margin: 10rpx 0;
  357. padding-top: 10rpx;
  358. border-top: 1px solid #F2F2F2;
  359. height: 80rpx;
  360. .coutry {
  361. // background-color: #F5F5F5;
  362. border-radius: 26rpx;
  363. padding: 4rpx 20rpx;
  364. color: #666666;
  365. font-size: 26rpx;
  366. margin-right: 20rpx;
  367. }
  368. .coutry.on {
  369. // background-color: rgba(220, 217, 236, 1);
  370. border-style: solid;
  371. border-width: 2rpx;
  372. color: #E93323;
  373. }
  374. }
  375. </style>