index.vue 9.1 KB

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