newsList.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view class="container">
  3. <!-- 搜索框区域 -->
  4. <view class="search">
  5. <view class="add">
  6. <image class="img" src="../../static/index/search.png" mode="aspectFit"></image>
  7. </view>
  8. <input class="inp" type="text" v-model="keywords" placeholder="请输入关键字" />
  9. <view class="btnSearch" @click="searchHandler">搜索</view>
  10. </view>
  11. <!-- 资讯列表区域 -->
  12. <scroll-view class="list" scroll-y @scrolltolower="handleLower" v-if="list.length">
  13. <!-- 每一条资讯区域 -->
  14. <view class="box" v-for="item in list" :key="item.id" @click="handleGoDetail(item)">
  15. <uv-image width="253rpx" height="190rpx" radius="8rpx" mode="aspectFill" :src="item.first_img || ''" />
  16. <view class="box_detail">
  17. <view class="detail_title">{{ item.title }}</view>
  18. <view class="detail_time">{{ item.update_time }}</view>
  19. </view>
  20. <!-- 富文本区域 -->
  21. <!-- <mp-html v-if="item.showHtml" @load="htmlLoad(item)" :ref="item.id + 'html'" :content="item.content" /> -->
  22. </view>
  23. </scroll-view>
  24. <!-- 没有数据时展示的页面 -->
  25. <view class="noData" v-if="!list.length">
  26. <img src="../../static/images/noData.png" />
  27. 暂无数据
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. // 搜索框绑定数据
  36. keywords: '',
  37. // 资讯列表
  38. list: [],
  39. // 当前页
  40. pageNews: 1,
  41. // 每页多少条
  42. rowsNews: 8,
  43. // 总条数
  44. totalNews: null
  45. // 控制页面显示隐藏
  46. // showPage: false
  47. }
  48. },
  49. onLoad() {
  50. this.getNews()
  51. },
  52. methods: {
  53. // 获取资讯列表
  54. async getNews() {
  55. const res = await this.$myRequest({
  56. url: '/mhotel/appnewlist.action',
  57. data: {
  58. page: this.pageNews,
  59. rows: this.rowsNews,
  60. key: this.keywords
  61. }
  62. })
  63. // console.log(res)
  64. if (res.code === 200) {
  65. this.list = [...this.list, ...res.rows]
  66. // this.list.forEach((ele) => {
  67. // this.$set(ele, 'showHtml', true)
  68. // })
  69. this.totalNews = res.total
  70. }
  71. },
  72. // 点击搜索按钮回调
  73. searchHandler() {
  74. // this.showPage = false
  75. this.list = []
  76. this.pageNews = 1
  77. this.getNews()
  78. },
  79. // 页面到底触发回调
  80. handleLower() {
  81. if (this.list.length < this.totalNews) {
  82. this.pageNews++
  83. this.getNews()
  84. } else {
  85. uni.showToast({
  86. title: '没有更多数据了',
  87. icon: 'none'
  88. })
  89. }
  90. },
  91. // 跳转资讯详情回调
  92. handleGoDetail(item) {
  93. let info = encodeURIComponent(JSON.stringify(item))
  94. uni.navigateTo({
  95. url: `/pagesSub/newsDetail/newsDetail?info=${info}`
  96. })
  97. }
  98. // 获取富文本信息回调
  99. // htmlLoad(item) {
  100. // let id = item.id + 'html'
  101. // let ctx = this.$refs[id][0]
  102. // let imgs = ctx.imgList[0]
  103. // item.showHtml = false
  104. // item.url = imgs
  105. // if (!this.showPage) {
  106. // this.showPage = true
  107. // }
  108. // }
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .container {
  114. box-sizing: border-box;
  115. padding: 20rpx;
  116. height: 100vh;
  117. background-color: #f2f2f2;
  118. .search {
  119. display: flex;
  120. justify-content: space-between;
  121. align-items: center;
  122. height: 80rpx;
  123. opacity: 1;
  124. border-radius: 70px;
  125. background-color: #fff;
  126. .add {
  127. display: flex;
  128. justify-content: center;
  129. align-items: center;
  130. margin-left: 10rpx;
  131. width: 60rpx;
  132. height: 60rpx;
  133. .img {
  134. width: 30rpx;
  135. height: 30rpx;
  136. }
  137. }
  138. .inp {
  139. height: 60rpx;
  140. line-height: 60rpx;
  141. flex-grow: 1;
  142. font-size: 28rpx;
  143. }
  144. .btnSearch {
  145. margin-right: 10rpx;
  146. width: 100rpx;
  147. height: 60rpx;
  148. line-height: 60rpx;
  149. text-align: center;
  150. opacity: 1;
  151. font-size: 28rpx;
  152. color: #096562;
  153. }
  154. }
  155. .list {
  156. height: calc(100vh - 140rpx);
  157. padding: 20rpx 0;
  158. .box {
  159. box-sizing: border-box;
  160. padding: 20rpx 30rpx 20rpx 20rpx;
  161. margin-bottom: 20rpx;
  162. display: flex;
  163. width: 710rpx;
  164. height: 230rpx;
  165. background-color: #fff;
  166. .box_detail {
  167. flex: 1;
  168. display: flex;
  169. flex-direction: column;
  170. justify-content: space-between;
  171. margin-left: 20rpx;
  172. overflow: hidden;
  173. .detail_title {
  174. font-size: 32rpx;
  175. font-weight: bold;
  176. display: -webkit-box;
  177. -webkit-box-orient: vertical;
  178. -webkit-line-clamp: 2;
  179. overflow: hidden;
  180. }
  181. .detail_time {
  182. color: #666666;
  183. font-size: 24rpx;
  184. }
  185. }
  186. }
  187. }
  188. .noData {
  189. display: flex;
  190. flex-direction: column;
  191. justify-content: center;
  192. align-items: center;
  193. padding-bottom: 65rpx;
  194. img {
  195. margin-top: 80rpx;
  196. width: 600rpx;
  197. height: 600rpx;
  198. }
  199. }
  200. }
  201. </style>