index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view>
  3. <view class="top-content">
  4. <!-- 这里是状态栏 -->
  5. <view class="status_bar" :style="{height: statusBarHeight}"></view>
  6. <view class="top-title">健康百科</view>
  7. <!-- 搜索框 -->
  8. <view class="search-cont">
  9. <view class="inner">
  10. <image class="icon-search" src="https://kntobs.jnmyunl.com/shop/images/search.png" mode=""></image>
  11. <input type="text" v-model="searchValue" placeholder="输入关键字搜索" confirm-type="search" @confirm="doSearch" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  12. </view>
  13. </view>
  14. <view class="keyword-list">
  15. <!-- 关键字列表 -->
  16. <scroll-view scroll-x="true" >
  17. <view class="inner">
  18. <view v-for="(item,index) in cates" :key="index" :class="choseCateId == item.cateId?'item active':'item'" @click="choseCate(item)">
  19. {{ item.cateName }}
  20. </view>
  21. </view>
  22. </scroll-view>
  23. </view>
  24. </view>
  25. <!-- 知识列表 -->
  26. <mescroll-body :top="top" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  27. <view class="know-list">
  28. <view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
  29. <view class="left">
  30. <view class="title ellipsis2">{{ item.title }}</view>
  31. <view class="info-box">
  32. <view class="readers">
  33. <view class="head-box" v-if="item.viewsList!=null&&item.viewsList.length>0">
  34. <view class="head" v-for="(subitem,j) in item.viewsList" :key="j" v-if="subitem!=null">
  35. <image :src="subitem.avatar==null?'https://kntobs.jnmyunl.com/shop/images/detault_head.jpg':subitem.avatar" mode=""></image>
  36. </view>
  37. </view>
  38. <view class="readings">
  39. <image class="eye" src="https://kntobs.jnmyunl.com/shop/images/eye.png" ></image>
  40. <text class="num">{{item.views}}</text>
  41. </view>
  42. </view>
  43. <view class="time">{{item.publishTime}}</view>
  44. </view>
  45. </view>
  46. <view class="right">
  47. <image :src="item.imageUrl" mode="aspectFill"></image>
  48. </view>
  49. </view>
  50. </view>
  51. </mescroll-body>
  52. <!-- <tabbar :actindex="1"></tabbar> -->
  53. <floating-customer-service></floating-customer-service>
  54. </view>
  55. </template>
  56. <script>
  57. import {getArticleCate,getArticleList} from '@/api/article'
  58. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  59. import FloatingCustomerService from "@/components/FloatingCustomerService/index.vue"
  60. export default {
  61. components: {
  62. FloatingCustomerService
  63. },
  64. mixins: [MescrollMixin],
  65. data() {
  66. return {
  67. top:'0px',
  68. cates:[],
  69. choseCateId:0,
  70. // 状态栏的高度
  71. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  72. searchValue: '',
  73. mescroll:null,
  74. // 上拉加载的配置
  75. downOption:{
  76. },
  77. upOption: {
  78. onScroll:true,
  79. use: true, // 是否启用上拉加载; 默认true
  80. page: {
  81. num: 1, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  82. size: 10 // 每页数据的数量,默认10
  83. },
  84. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  85. empty: {
  86. icon:'https://kntobs.jnmyunl.com/shop/images/no_data.png',
  87. tip: '暂无数据'
  88. },
  89. textNoMore:'已经到底了'
  90. },
  91. // 列表数据
  92. dataList: [],
  93. };
  94. },
  95. onShow() {
  96. this.getArticleCate();
  97. var that=this;
  98. setTimeout(function(){
  99. let query = uni.createSelectorQuery().select(".top-content");
  100.     query.boundingClientRect(function(data) { //data - 各种参数
  101.       console.log(data.height) // 获取元素宽度
  102. that.top=data.height+"px";
  103.    }).exec()
  104. },500);
  105. // let info1 = uni.createSelectorQuery().select(".keyword-list");
  106. //     info1.boundingClientRect(function(data) { //data - 各种参数
  107. //       console.log(data.height) // 获取元素宽度
  108. //    }).exec()
  109. },
  110. methods:{
  111. doSearch(){
  112. console.log(this.searchValue)
  113. this.mescroll.resetUpScroll()
  114. },
  115. getArticleCate(){
  116. var that=this;
  117. let data = {};
  118. getArticleCate(data).then(
  119. res => {
  120. if(res.code==200){
  121. this.cates=res.data;
  122. }else{
  123. uni.showToast({
  124. icon:'none',
  125. title: "请求失败",
  126. });
  127. }
  128. },
  129. rej => {}
  130. );
  131. },
  132. mescrollInit(mescroll) {
  133. this.mescroll = mescroll;
  134. },
  135. /*下拉刷新的回调 */
  136. downCallback(mescroll) {
  137. mescroll.resetUpScroll()
  138. },
  139. upCallback(page) {
  140. //联网加载数据
  141. console.log('-----',page)
  142. var that = this;
  143. var data = {
  144. keyword:this.searchValue,
  145. cateId:this.choseCateId,
  146. page: page.num,
  147. pageSize: page.size
  148. };
  149. getArticleList(data).then(res => {
  150. if(res.code==200){
  151. //设置列表数据
  152. if (page.num == 1) {
  153. that.dataList = res.data.list;
  154. } else {
  155. that.dataList = that.dataList.concat(res.data.list);
  156. }
  157. that.mescroll.endBySize(res.data.list.length, res.data.total);
  158. }else{
  159. uni.showToast({
  160. icon:'none',
  161. title: "请求失败",
  162. });
  163. that.dataList = null;
  164. that.mescroll.endErr();
  165. }
  166. });
  167. },
  168. // 关键词选择
  169. choseCate(item) {
  170. this.choseCateId = item.cateId;
  171. this.mescroll.resetUpScroll()
  172. },
  173. // 查看详情
  174. showDetail(item) {
  175. uni.navigateTo({
  176. url: './detail?articleId=' + item.articleId
  177. })
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="scss">
  183. .status_bar {
  184. width: 100%;
  185. background-color: #FFFFFF;
  186. }
  187. .top-content{
  188. width: 100%;
  189. position: fixed;
  190. top: 0;
  191. left: 0;
  192. z-index: 10;
  193. }
  194. .top-title{
  195. height: 88upx;
  196. line-height: 88upx;
  197. font-size: 42upx;
  198. font-family: Source Han Sans CN;
  199. font-weight: bold;
  200. color: #222222;
  201. padding-left: 41upx;
  202. background-color: #FFFFFF;
  203. }
  204. .search-cont{
  205. padding: 16upx 30upx;
  206. background-color: #FFFFFF;
  207. .inner{
  208. box-sizing: border-box;
  209. width: 100%;
  210. height: 72upx;
  211. background: #F7F7F7;
  212. border-radius: 36upx;
  213. display: flex;
  214. align-items: center;
  215. padding: 0 30upx;
  216. .icon-search{
  217. width: 28upx;
  218. height: 28upx;
  219. margin-right: 20upx;
  220. }
  221. input{
  222. height: 60upx;
  223. line-height: 60upx;
  224. flex: 1;
  225. }
  226. }
  227. }
  228. .keyword-list{
  229. box-sizing: border-box;
  230. background: #fff;
  231. padding: 10upx 27upx;
  232. height: 100upx;
  233. .inner{
  234. display: flex;
  235. }
  236. .item{
  237. flex-shrink: 0;
  238. padding: 0 24upx;
  239. height: 64upx;
  240. line-height: 64upx;
  241. font-size: 28upx;
  242. font-family: PingFang SC;
  243. font-weight: 500;
  244. color: #2BC7B9;
  245. background: #F5FFFE;
  246. border: 1px solid #2BC7B9;
  247. border-radius: 32upx;
  248. margin: 0 20upx 20upx 0;
  249. &.active{
  250. color: #FFFFFF;
  251. background: #2BC7B9;
  252. border: 1px solid #2BC7B9;
  253. }
  254. }
  255. }
  256. .know-list{
  257. margin-top: 20upx;
  258. padding: 0 10upx;
  259. .item{
  260. box-sizing: border-box;
  261. height: 271upx;
  262. background: #FFFFFF;
  263. border-radius: 16upx;
  264. padding: 40upx 30upx;
  265. display: flex;
  266. align-items: center;
  267. justify-content: space-between;
  268. margin-bottom: 20upx;
  269. .left{
  270. flex: 1;
  271. padding-right: 40upx;
  272. height: 190upx;
  273. display: flex;
  274. flex-direction: column;
  275. justify-content: space-between;
  276. .title{
  277. font-size: 32upx;
  278. font-family: PingFang SC;
  279. font-weight: 500;
  280. color: #111111;
  281. line-height: 48upx;
  282. }
  283. .info-box{
  284. width: 100%;
  285. display: flex;
  286. align-items: center;
  287. justify-content: space-between;
  288. .readers{
  289. display: flex;
  290. align-items: center;
  291. .head-box{
  292. margin-right: 27upx;
  293. display: flex;
  294. align-items: center;
  295. .head{
  296. width: 48upx;
  297. height: 48upx;
  298. border-radius: 50%;
  299. overflow: hidden;
  300. box-shadow: 0 0 0 1px #fff;
  301. margin-right: -10upx;
  302. image{
  303. width: 100%;
  304. height: 100%;
  305. }
  306. }
  307. }
  308. .readings{
  309. display: flex;
  310. align-items: center;
  311. .eye{
  312. width: 26upx;
  313. height: 20upx;
  314. margin-right: 9upx;
  315. }
  316. .num{
  317. font-size: 24upx;
  318. font-family: PingFang SC;
  319. font-weight: 500;
  320. color: #999999;
  321. line-height: 1;
  322. }
  323. }
  324. }
  325. .time{
  326. font-size: 24upx;
  327. line-height: 1;
  328. font-family: PingFang SC;
  329. font-weight: 500;
  330. color: #999999;
  331. }
  332. }
  333. }
  334. .right{
  335. width: 250upx;
  336. height: 190upx;
  337. border-radius: 8upx;
  338. overflow: hidden;
  339. image{
  340. width: 100%;
  341. height: 100%;
  342. }
  343. }
  344. }
  345. }
  346. </style>