index.vue 9.3 KB

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