index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <view>
  3. <u-navbar :is-back="false" :border-bottom="false"><view class="navbar-tit">资讯</view></u-navbar>
  4. <view class="home-head">
  5. <view class="homeTab">
  6. <u-tabs :list="tabList" :current="current" @change="change" :show-bar="false" active-color="#333" inactive-color="#c4c0c0"></u-tabs>
  7. </view>
  8. </view>
  9. <view class="homeWrap" v-if="wrapList.length">
  10. <u-swiper :list="wrapList" @click="clickBanner" :img-mode="'aspectFit'" :name="'picUrl'" height="294" border-radius="24"></u-swiper>
  11. </view>
  12. <view class="newsList" v-if="list.length">
  13. <view class="newsList-item" v-for="(item ,index) in list" :key="item.id"
  14. @click="toDetail(item)">
  15. <view class="newsList-text">
  16. <h4 class="u-line-2" v-text="item.title">
  17. </h4>
  18. <p>{{item.createTime}}</p>
  19. </view>
  20. <u-image v-if="current == 3" class="newsList-img" :src="item.image?item.image:'/static/img/default_img.png'" height="150" width="200" border-radius="10"></u-image>
  21. <u-image v-else class="newsList-img" :src="item.images?item.images:'/static/img/default_img.png'" height="150" width="200" border-radius="10"></u-image>
  22. </view>
  23. <u-divider color="#B6BDC3" v-if="list.length ==recordsTotal" style="margin-top:20px;">已经到底了</u-divider>
  24. </view>
  25. <view class="jpDefault" v-else>
  26. <u-image width="179px" height="126px" src="/static/img/default1.png"></u-image>
  27. <p>暂无资讯内容</p>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import * as API from '@/apis/news.js'
  33. import * as Api_common from '@/apis/common.js'
  34. export default {
  35. data() {
  36. return {
  37. form:{
  38. },
  39. newstype:'',
  40. typelist: [],
  41. pageIndex: 1,
  42. recordsTotal: 0,
  43. list: [],
  44. tabList: [],
  45. current: 0,
  46. wrapList: [
  47. ],
  48. newsTypeCurrent: 0,
  49. }
  50. },
  51. onReachBottom() {
  52. if (this.list.length < this.recordsTotal) {
  53. this.myLoadmore();
  54. }
  55. },
  56. onShow() {
  57. if(this.carhelp.get("newsTypeCurrent") != null) {
  58. this.newsTypeCurrent = this.carhelp.get("newsTypeCurrent");
  59. this.current = this.newsTypeCurrent;
  60. }
  61. this.getType()
  62. //this.getBannerInfo()
  63. },
  64. methods: {
  65. toDetail(item) {
  66. if(this.newstype.shortName == 'HDBG') {
  67. uni.navigateTo({
  68. url: '/pages/news/activityDetails?id='+item.id
  69. })
  70. } else {
  71. uni.navigateTo({
  72. url: '/pages/news/detalis?id='+item.id
  73. })
  74. }
  75. },
  76. getActivityList(bl) {
  77. uni.showLoading({
  78. title: "加载中",
  79. mask: true,
  80. })
  81. if (bl) {
  82. this.list = [];
  83. this.pageIndex = 1;
  84. }
  85. API.activityList({
  86. pageSize:5,
  87. pageIndex: this.pageIndex
  88. }).then((res) => {
  89. this.list = [
  90. ...this.list,
  91. ...res.data.data
  92. ];
  93. this.recordsTotal = res.data.recordsTotal
  94. uni.hideLoading()
  95. }).catch(error => {
  96. uni.showToast({
  97. title: error,icon: "none"
  98. })
  99. })
  100. },
  101. getBannerInfo(code){
  102. uni.showLoading({
  103. title: "加载中",
  104. mask: true,
  105. })
  106. Api_common.getBannerInfo(code).then((res) => {
  107. this.wrapList =res.data;
  108. }).catch(error => {
  109. uni.showToast({
  110. title: error,icon: "none"
  111. })
  112. })
  113. },
  114. clickBanner(index){
  115. var obj= this.wrapList[index]
  116. uni.navigateTo({
  117. url:obj.linkUrl
  118. })
  119. },
  120. getType() {
  121. uni.showLoading({
  122. title: "加载中",
  123. mask: true,
  124. })
  125. this.pageIndex = 1;
  126. API.newsTypeList().then((res) => {
  127. this.tabList = res.data;
  128. if(this.tabList.length) {
  129. this.newstype = this.tabList[this.newsTypeCurrent];
  130. }
  131. if(this.newstype.shortName == 'HDBG') {
  132. this.getActivityList(true)
  133. } else {
  134. this.getList(true)
  135. }
  136. this.getBannerInfo(this.newstype.shortName)
  137. uni.hideLoading()
  138. }).catch(error => {
  139. uni.showToast({
  140. title: error,icon: "none"
  141. })
  142. })
  143. },
  144. getList(bl) {
  145. if(this.newstype==""){
  146. return
  147. }
  148. uni.showLoading({
  149. title: "加载中",
  150. mask: true,
  151. })
  152. if (bl) {
  153. this.list = [];
  154. this.pageIndex = 1;
  155. }
  156. var data = {
  157. type:this.newstype.shortName,
  158. pageSize:5,
  159. pageIndex: this.pageIndex
  160. };
  161. API.newscontent(data).then((res) => {
  162. this.list = [
  163. ...this.list,
  164. ...res.data.data
  165. ];
  166. this.recordsTotal = res.data.recordsTotal
  167. uni.hideLoading()
  168. }).catch(error => {
  169. uni.showToast({
  170. title: error,icon: "none"
  171. })
  172. })
  173. },
  174. myLoadmore() {
  175. this.pageIndex += 1;
  176. if(this.newstype.shortName == 'HDBG') {
  177. this.getActivityList(true)
  178. } else {
  179. this.getList(true)
  180. }
  181. },
  182. change(index) {
  183. this.current = index;
  184. this.carhelp.set("newsTypeCurrent", index);
  185. if(this.tabList.length){
  186. this.newstype=this.tabList[index]
  187. }
  188. if(this.newstype.shortName == 'HDBG') {
  189. this.getActivityList(true)
  190. } else {
  191. this.getList(true)
  192. }
  193. this.getBannerInfo(this.newstype.shortName)
  194. },
  195. },
  196. }
  197. </script>
  198. <style lang="scss" scoped>
  199. .jpDefault{
  200. padding-top:90px;
  201. display: flex;
  202. flex-direction: column;
  203. align-items: center;
  204. p{
  205. color: #A69F9F;
  206. font-size: 16px;
  207. margin-top: 12px;
  208. }
  209. }
  210. .navbar-tit{
  211. padding-left:15px;
  212. font-size: 24px;
  213. }
  214. .home-head{
  215. display: flex;
  216. justify-content: space-between;
  217. align-items: center;
  218. padding-right: 15px;
  219. background-color: #fff;
  220. z-index: 99;
  221. .homeAdd{
  222. color: #FF5E5E;
  223. span{
  224. margin-left: 3px;
  225. }
  226. }
  227. }
  228. .homeWrap{
  229. padding:0 15px;
  230. }
  231. .newsList{
  232. padding: 15px;
  233. .newsList-item{
  234. display: flex;
  235. margin-bottom: 24px;
  236. .newsList-text{
  237. flex: 1;
  238. min-width: 0;
  239. margin-right: 10px;
  240. display: flex;
  241. flex-direction: column;
  242. justify-content: space-between;
  243. h4{
  244. font-weight: normal;
  245. }
  246. p{
  247. color: #999;
  248. font-size: 12px;
  249. }
  250. }
  251. }
  252. }
  253. </style>