index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. var newsTypeCurrent= this.carhelp.get("newsTypeCurrent")
  58. if(newsTypeCurrent!=""){
  59. if(newsTypeCurrent || newsTypeCurrent==0) {
  60. this.newsTypeCurrent = this.carhelp.get("newsTypeCurrent");
  61. this.current = this.newsTypeCurrent;
  62. }
  63. }
  64. this.getType()
  65. //this.getBannerInfo()
  66. },
  67. methods: {
  68. toDetail(item) {
  69. if(this.newstype.shortName == 'HDBG') {
  70. uni.navigateTo({
  71. url: '/pages/news/activityDetails?id='+item.id
  72. })
  73. } else {
  74. uni.navigateTo({
  75. url: '/pages/news/detalis?id='+item.id
  76. })
  77. }
  78. },
  79. getActivityList(bl) {
  80. uni.showLoading({
  81. title: "加载中",
  82. mask: true,
  83. })
  84. if (bl) {
  85. this.list = [];
  86. this.pageIndex = 1;
  87. }
  88. API.activityList({
  89. pageSize:5,
  90. pageIndex: this.pageIndex
  91. }).then((res) => {
  92. this.list = [
  93. ...this.list,
  94. ...res.data.data
  95. ];
  96. this.recordsTotal = res.data.recordsTotal
  97. uni.hideLoading()
  98. }).catch(error => {
  99. uni.showToast({
  100. title: error,icon: "none"
  101. })
  102. })
  103. },
  104. getBannerInfo(code){
  105. uni.showLoading({
  106. title: "加载中",
  107. mask: true,
  108. })
  109. Api_common.getBannerInfo(code).then((res) => {
  110. this.wrapList =res.data;
  111. uni.hideLoading()
  112. }).catch(error => {
  113. uni.showToast({
  114. title: error,icon: "none"
  115. })
  116. })
  117. },
  118. clickBanner(index){
  119. var obj= this.wrapList[index]
  120. uni.navigateTo({
  121. url:obj.linkUrl
  122. })
  123. },
  124. getType() {
  125. uni.showLoading({
  126. title: "加载中",
  127. mask: true,
  128. })
  129. this.pageIndex = 1;
  130. API.newsTypeList().then((res) => {
  131. this.tabList = res.data;
  132. if(this.tabList.length) {
  133. this.newstype = this.tabList[this.newsTypeCurrent];
  134. }
  135. if(this.newstype.shortName == 'HDBG') {
  136. this.getActivityList(true)
  137. } else {
  138. this.getList(true)
  139. }
  140. this.getBannerInfo(this.newstype.shortName)
  141. uni.hideLoading()
  142. }).catch(error => {
  143. uni.showToast({
  144. title: error,icon: "none"
  145. })
  146. })
  147. },
  148. getList(bl) {
  149. if(this.newstype==""){
  150. return
  151. }
  152. uni.showLoading({
  153. title: "加载中",
  154. mask: true,
  155. })
  156. if (bl) {
  157. this.list = [];
  158. this.pageIndex = 1;
  159. }
  160. var data = {
  161. type:this.newstype.shortName,
  162. pageSize:5,
  163. pageIndex: this.pageIndex
  164. };
  165. API.newscontent(data).then((res) => {
  166. this.list = [
  167. ...this.list,
  168. ...res.data.data
  169. ];
  170. this.recordsTotal = res.data.recordsTotal
  171. uni.hideLoading()
  172. }).catch(error => {
  173. uni.showToast({
  174. title: error,icon: "none"
  175. })
  176. })
  177. },
  178. myLoadmore() {
  179. this.pageIndex += 1;
  180. if(this.newstype.shortName == 'HDBG') {
  181. this.getActivityList(true)
  182. } else {
  183. this.getList(true)
  184. }
  185. },
  186. change(index) {
  187. this.current = index;
  188. this.carhelp.set("newsTypeCurrent", index);
  189. if(this.tabList.length){
  190. this.newstype=this.tabList[index]
  191. }
  192. if(this.newstype.shortName == 'HDBG') {
  193. this.getActivityList(true)
  194. } else {
  195. this.getList(true)
  196. }
  197. this.getBannerInfo(this.newstype.shortName)
  198. },
  199. },
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .jpDefault{
  204. padding-top:90px;
  205. display: flex;
  206. flex-direction: column;
  207. align-items: center;
  208. p{
  209. color: #A69F9F;
  210. font-size: 16px;
  211. margin-top: 12px;
  212. }
  213. }
  214. .navbar-tit{
  215. padding-left:15px;
  216. font-size: 24px;
  217. }
  218. .home-head{
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: center;
  222. padding-right: 15px;
  223. background-color: #fff;
  224. z-index: 99;
  225. .homeAdd{
  226. color: #FF5E5E;
  227. span{
  228. margin-left: 3px;
  229. }
  230. }
  231. }
  232. .homeWrap{
  233. padding:0 15px;
  234. }
  235. .newsList{
  236. padding: 15px;
  237. .newsList-item{
  238. display: flex;
  239. margin-bottom: 24px;
  240. .newsList-text{
  241. flex: 1;
  242. min-width: 0;
  243. margin-right: 10px;
  244. display: flex;
  245. flex-direction: column;
  246. justify-content: space-between;
  247. h4{
  248. font-weight: normal;
  249. }
  250. p{
  251. color: #999;
  252. font-size: 12px;
  253. }
  254. }
  255. }
  256. }
  257. </style>