news.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="container">
  3. <scroll-view scroll-x class="bg-white nav">
  4. <view class="flex text-center">
  5. <view class="cu-item flex-sub" :class="item.value==TabCur?'text-orange cur':''" v-for="item in categoryList"@tap="tabSelect" :data-id="item.value">
  6. {{item.label}}
  7. </view>
  8. </view>
  9. </scroll-view>
  10. <view class="guess-section">
  11. <view
  12. v-for="(item, index) in newsInfo" :key="index"
  13. class="guess-item"
  14. @click="navToDetailPage(item.id)"
  15. >
  16. <view class="cu-card article no-card" >
  17. <view class="cu-item shadow">
  18. <view class="title">
  19. <view class="text-cut">{{item.title}}</view>
  20. </view>
  21. <view class="content">
  22. <image :src="item.titleImg"
  23. mode="aspectFit"></image>
  24. <view class="desc">
  25. <view class="text-content">
  26. <view class="u-content" :selectable="true">
  27. <u-parse :html="item.abstractContent"></u-parse>
  28. </view>
  29. </view>
  30. <view style="margin-bottom: 30upx;">
  31. <view class="cu-tag bg-red light radius">{{item.from}}</view>
  32. <view class="cu-tag bg-green light radius">{{item.gmtUpdate}}</view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view v-show="isLoadMore">
  40. <uni-load-more :status="loadStatus" ></uni-load-more>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. newsInfo: [],
  50. categoryList:[],
  51. pages:1,//页数
  52. limit:10 ,//每次取条目数
  53. loadStatus:'loading', //加载样式:more-加载前样式,loading-加载中样式,nomore-没有数据样式
  54. isLoadMore:false ,//是否加载中
  55. TabCur: 0,
  56. category:0
  57. }
  58. },
  59. //下拉刷新
  60. onPullDownRefresh() {
  61. this.pages = 1
  62. this.isLoadMore = false
  63. this.loadStatus = 'loading'
  64. this.loadData()
  65. setTimeout(function () {
  66. uni.stopPullDownRefresh();
  67. }, 1000);
  68. },
  69. onReachBottom(){ //上拉触底函数
  70. if(!this.isLoadMore){ //此处判断,上锁,防止重复请求
  71. this.isLoadMore=true
  72. this.pages += 1
  73. this.getNewsInfo()
  74. }
  75. },
  76. onLoad() {
  77. uni.showLoading({
  78. title: '正在加载',
  79. mask:true
  80. })
  81. const that = this
  82. that.$api.request('dict', 'getDictDataList',{
  83. dictType: "news_type"
  84. }, failres => {
  85. that.$api.msg(failres.errmsg)
  86. uni.hideLoading()
  87. uni.stopPullDownRefresh()
  88. }).then(res => {
  89. let data = res.data
  90. console.log("categoryList:"+ data)
  91. console.log(data)
  92. that.categoryList = data
  93. uni.hideLoading()
  94. uni.stopPullDownRefresh()
  95. })
  96. this.loadData()
  97. },
  98. methods: {
  99. async loadData() {
  100. const that = this
  101. uni.showLoading({
  102. title: '正在加载',
  103. mask:true
  104. })
  105. that.$api.request('news', 'getNewsInfo',{
  106. category:this.category,
  107. page: this.pages,
  108. limit:this.limit
  109. }, failres => {
  110. that.$api.msg(failres.errmsg)
  111. this.isLoadMore = false
  112. this.loadStatus = 'nomore'
  113. if(this.pages>1){this.pages=1}
  114. uni.hideLoading()
  115. }).then(res => {
  116. let data = res.data
  117. console.log(data)
  118. that.newsInfo = data
  119. uni.hideLoading()
  120. })
  121. },
  122. tabSelect(e) {
  123. this.TabCur = e.currentTarget.dataset.id;
  124. this.category = this.TabCur
  125. this.pages = 1
  126. this.loadData()
  127. },
  128. //详情
  129. navToDetailPage(item) {
  130. let id = item;
  131. uni.navigateTo({
  132. url: `/pageB/news/news_detail?id=${id}`
  133. })
  134. },
  135. getNewsInfo(){
  136. const that = this
  137. var pages=that.pages
  138. var limit=that.limit
  139. uni.showLoading({
  140. title: '正在加载',
  141. mask:true
  142. })
  143. that.$api.request('news', 'getNewsInfo', {
  144. category:this.category,
  145. page: pages,
  146. limit:limit
  147. },failres => {
  148. that.$api.msg(failres.errmsg)
  149. that.isLoadMore=false
  150. that.loadStatus = 'nomore'
  151. if(that.pages>1){that.pages-=1}
  152. uni.hideLoading()
  153. }).then(res => {
  154. let data = res.data
  155. if(data.length > 0){
  156. that.newsInfo = that.newsInfo.concat(data)
  157. that.isLoadMore=false
  158. }
  159. else{
  160. if(that.pages>1){that.pages-=1}
  161. that.isLoadMore=true
  162. that.loadStatus = 'nomore'
  163. }
  164. uni.hideLoading()
  165. })
  166. },
  167. }
  168. }
  169. </script>
  170. <style lang='scss'>
  171. .container{
  172. padding-bottom: 100upx;
  173. }
  174. .cu-form-group input {
  175. text-align: right;
  176. }
  177. .cu-form-group textarea {
  178. text-align: right;
  179. }
  180. .place{
  181. font-size: 40rpx;
  182. line-height: 1;
  183. padding-right: 10upx;
  184. }
  185. .place-center{
  186. font-size: 28rpx;
  187. }
  188. .guess-item{
  189. /* margin-top: 10rpx; */
  190. }
  191. .btn-size{
  192. font-size: 28rpx;
  193. }
  194. .place-bottom{
  195. margin-top: 20rpx;
  196. }
  197. .guess-section{
  198. padding-bottom: 100upx;
  199. display:flex;
  200. flex-wrap:wrap;
  201. padding: 0 30upx;
  202. background: #fff;
  203. .guess-item{
  204. display:flex;
  205. flex-direction: column;
  206. width: 98%;
  207. border-bottom:1px solid #ccc;
  208. }
  209. .image-wrapper{
  210. width: 100%;
  211. height: 330upx;
  212. border-radius: 3px;
  213. overflow: hidden;
  214. image{
  215. width: 100%;
  216. height: 100%;
  217. opacity: 1;
  218. }
  219. }
  220. .title{
  221. font-size: $font-lg;
  222. color: #121212;
  223. }
  224. .price-orther{
  225. font-size: $font-sm;
  226. color:$font-color-base;
  227. }
  228. .price{
  229. font-size: 64rpx;
  230. color: #39b54a;
  231. line-height: 1;
  232. padding-right: 10upx;
  233. }
  234. .goods1{
  235. font-size: $font-sm;
  236. color: $font-color-base;
  237. }
  238. .goods2{
  239. font-size: $font-sm;
  240. color: $font-color-base;
  241. padding-left: 10%;
  242. }
  243. .goods3{
  244. font-size: $font-sm;
  245. color: $font-color-base;
  246. padding-left: 10%;
  247. }
  248. .goods4{
  249. font-size: $font-sm;
  250. color: #ff5500;
  251. }
  252. .goods5{
  253. font-size: $font-sm;
  254. color: $font-color-base;
  255. }
  256. .view-item{
  257. width: 100%;
  258. // line-height: 40upx;
  259. padding-top: 10upx;
  260. }
  261. .confirm-btn {
  262. margin-left: 20%;
  263. }
  264. .date-time {
  265. margin-left: 30%;
  266. }
  267. .padding-xs-tmp {
  268. padding: 15upx 10upx 10upx 10upx;
  269. }
  270. }
  271. </style>