news.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. },
  66. onReachBottom(){ //上拉触底函数
  67. if(!this.isLoadMore){ //此处判断,上锁,防止重复请求
  68. this.isLoadMore=true
  69. this.pages += 1
  70. this.getNewsInfo()
  71. }
  72. },
  73. onLoad() {
  74. uni.showLoading({
  75. title: '正在加载',
  76. mask:true
  77. })
  78. const that = this
  79. that.$api.request('dict', 'getDictDataList',{
  80. dictType: "news_type"
  81. }, failres => {
  82. that.$api.msg(failres.errmsg)
  83. uni.hideLoading()
  84. uni.stopPullDownRefresh()
  85. }).then(res => {
  86. let data = res.data
  87. console.log("categoryList:"+ data)
  88. console.log(data)
  89. that.categoryList = data
  90. uni.hideLoading()
  91. uni.stopPullDownRefresh()
  92. })
  93. this.loadData()
  94. },
  95. methods: {
  96. async loadData() {
  97. const that = this
  98. uni.showLoading({
  99. title: '正在加载',
  100. mask:true
  101. })
  102. that.$api.request('news', 'getNewsInfo',{
  103. category:this.category,
  104. page: this.pages,
  105. limit:this.limit
  106. }, failres => {
  107. that.$api.msg(failres.errmsg)
  108. this.isLoadMore = false
  109. this.loadStatus = 'nomore'
  110. if(this.pages>1){this.pages=1}
  111. uni.hideLoading()
  112. }).then(res => {
  113. let data = res.data
  114. console.log(data)
  115. that.newsInfo = data
  116. uni.hideLoading()
  117. })
  118. },
  119. tabSelect(e) {
  120. this.TabCur = e.currentTarget.dataset.id;
  121. this.category = this.TabCur
  122. this.pages = 1
  123. this.loadData()
  124. },
  125. //详情
  126. navToDetailPage(item) {
  127. let id = item;
  128. uni.navigateTo({
  129. url: `/pageB/news/news_detail?id=${id}`
  130. })
  131. },
  132. getNewsInfo(){
  133. const that = this
  134. var pages=that.pages
  135. var limit=that.limit
  136. uni.showLoading({
  137. title: '正在加载',
  138. mask:true
  139. })
  140. that.$api.request('news', 'getNewsInfo', {
  141. category:this.category,
  142. page: pages,
  143. limit:limit
  144. },failres => {
  145. that.$api.msg(failres.errmsg)
  146. that.isLoadMore=false
  147. that.loadStatus = 'nomore'
  148. if(that.pages>1){that.pages-=1}
  149. uni.hideLoading()
  150. }).then(res => {
  151. let data = res.data
  152. if(data.length > 0){
  153. that.newsInfo = that.newsInfo.concat(data)
  154. that.isLoadMore=false
  155. }
  156. else{
  157. if(that.pages>1){that.pages-=1}
  158. that.isLoadMore=true
  159. that.loadStatus = 'nomore'
  160. }
  161. uni.hideLoading()
  162. })
  163. },
  164. }
  165. }
  166. </script>
  167. <style lang='scss'>
  168. .container{
  169. padding-bottom: 100upx;
  170. }
  171. .cu-form-group input {
  172. text-align: right;
  173. }
  174. .cu-form-group textarea {
  175. text-align: right;
  176. }
  177. .place{
  178. font-size: 40rpx;
  179. line-height: 1;
  180. padding-right: 10upx;
  181. }
  182. .place-center{
  183. font-size: 28rpx;
  184. }
  185. .guess-item{
  186. /* margin-top: 10rpx; */
  187. }
  188. .btn-size{
  189. font-size: 28rpx;
  190. }
  191. .place-bottom{
  192. margin-top: 20rpx;
  193. }
  194. .guess-section{
  195. padding-bottom: 100upx;
  196. display:flex;
  197. flex-wrap:wrap;
  198. padding: 0 30upx;
  199. background: #fff;
  200. .guess-item{
  201. display:flex;
  202. flex-direction: column;
  203. width: 98%;
  204. border-bottom:1px solid #ccc;
  205. }
  206. .image-wrapper{
  207. width: 100%;
  208. height: 330upx;
  209. border-radius: 3px;
  210. overflow: hidden;
  211. image{
  212. width: 100%;
  213. height: 100%;
  214. opacity: 1;
  215. }
  216. }
  217. .title{
  218. font-size: $font-lg;
  219. color: #121212;
  220. }
  221. .price-orther{
  222. font-size: $font-sm;
  223. color:$font-color-base;
  224. }
  225. .price{
  226. font-size: 64rpx;
  227. color: #39b54a;
  228. line-height: 1;
  229. padding-right: 10upx;
  230. }
  231. .goods1{
  232. font-size: $font-sm;
  233. color: $font-color-base;
  234. }
  235. .goods2{
  236. font-size: $font-sm;
  237. color: $font-color-base;
  238. padding-left: 10%;
  239. }
  240. .goods3{
  241. font-size: $font-sm;
  242. color: $font-color-base;
  243. padding-left: 10%;
  244. }
  245. .goods4{
  246. font-size: $font-sm;
  247. color: #ff5500;
  248. }
  249. .goods5{
  250. font-size: $font-sm;
  251. color: $font-color-base;
  252. }
  253. .view-item{
  254. width: 100%;
  255. // line-height: 40upx;
  256. padding-top: 10upx;
  257. }
  258. .confirm-btn {
  259. margin-left: 20%;
  260. }
  261. .date-time {
  262. margin-left: 30%;
  263. }
  264. .padding-xs-tmp {
  265. padding: 15upx 10upx 10upx 10upx;
  266. }
  267. }
  268. </style>