index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.title" @input="toInput" placeholder="搜索标题">
  5. </view>
  6. <view class="two">
  7. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  8. <view class="list-scroll-view">
  9. <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
  10. <view class="list_1">
  11. <view class="left">
  12. <image class="image"
  13. :src="item.doctor.icon&&item.doctor.icon.length>0?item.doctor.icon[0].url:config.user_url[0].url"
  14. mode="">
  15. </image>
  16. <text>{{item.doctor.name||'暂无'}}</text>
  17. </view>
  18. <view class="right">{{item.create_time||'暂无'}}</view>
  19. </view>
  20. <view class="list_2">
  21. <image class="image" :src="item.img_url&&item.img_url.length>0?item.img_url[0].url:''"
  22. mode="">
  23. </image>
  24. </view>
  25. <view class="list_3">
  26. <text>{{item.title||'暂无标题'}}</text>
  27. </view>
  28. </view>
  29. <view class="is_bottom" v-if="is_bottom">
  30. <text>{{config.bottom_title||'到底了!'}}</text>
  31. </view>
  32. </view>
  33. </scroll-view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. config: {},
  42. user: {},
  43. searchInfo: {},
  44. list: [],
  45. total: 0,
  46. skip: 0,
  47. limit: 5,
  48. page: 0,
  49. // 数据是否触底
  50. is_bottom: false,
  51. scrollTop: 0,
  52. }
  53. },
  54. onLoad: async function(e) {
  55. const that = this;
  56. that.searchToken();
  57. that.searchConfig();
  58. },
  59. onShow: async function() {
  60. const that = this;
  61. that.clearPage();
  62. await that.search();
  63. },
  64. onPullDownRefresh: async function() {
  65. const that = this;
  66. that.clearPage();
  67. await that.search();
  68. uni.stopPullDownRefresh();
  69. },
  70. methods: {
  71. // 用户信息
  72. searchToken() {
  73. const that = this;
  74. try {
  75. const res = uni.getStorageSync('token');
  76. if (res) {
  77. const user = that.$jwt(res);
  78. that.$set(that, `user`, user);
  79. }
  80. } catch (e) {}
  81. },
  82. searchConfig() {
  83. const that = this;
  84. try {
  85. const res = uni.getStorageSync('config');
  86. if (res) that.$set(that, `config`, res);
  87. } catch (e) {}
  88. },
  89. async search() {
  90. const that = this;
  91. let info = {
  92. skip: that.skip,
  93. limit: that.limit,
  94. is_use: '0'
  95. }
  96. const res = await that.$api(`/article`, 'GET', {
  97. ...info,
  98. ...that.searchInfo
  99. })
  100. if (res.errcode == '0') {
  101. let list = [...that.list, ...res.data];
  102. that.$set(that, `list`, list)
  103. that.$set(that, `total`, res.total)
  104. } else {
  105. uni.showToast({
  106. title: res.errmsg,
  107. icon: 'none'
  108. });
  109. }
  110. },
  111. // 输入框
  112. toInput(e) {
  113. const that = this;
  114. if (that.searchInfo.title) that.$set(that.searchInfo, `title`, e.detail.value)
  115. else that.$set(that, `searchInfo`, {})
  116. that.clearPage();
  117. that.search();
  118. },
  119. // 查看详情
  120. toInfo(item) {
  121. uni.navigateTo({
  122. url: `/pagesScience/science/index?id=${item.id||item._id}&title=${item.title}`
  123. })
  124. },
  125. // 分页
  126. toPage(e) {
  127. const that = this;
  128. let list = that.list;
  129. let limit = that.limit;
  130. if (that.total > list.length) {
  131. uni.showLoading({
  132. title: '加载中',
  133. mask: true
  134. })
  135. let page = that.page + 1;
  136. that.$set(that, `page`, page)
  137. let skip = page * limit;
  138. that.$set(that, `skip`, skip)
  139. that.search();
  140. uni.hideLoading();
  141. } else that.$set(that, `is_bottom`, true)
  142. },
  143. toScroll(e) {
  144. const that = this;
  145. let up = that.scrollTop;
  146. that.$set(that, `scrollTop`, e.detail.scrollTop);
  147. let num = Math.sign(up - e.detail.scrollTop);
  148. if (num == 1) that.$set(that, `is_bottom`, false);
  149. },
  150. // 清空列表
  151. clearPage() {
  152. const that = this;
  153. that.$set(that, `list`, [])
  154. that.$set(that, `skip`, 0)
  155. that.$set(that, `limit`, 5)
  156. that.$set(that, `page`, 0)
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. .main {
  163. display: flex;
  164. flex-direction: column;
  165. width: 100vw;
  166. height: 100vh;
  167. .one {
  168. display: flex;
  169. justify-content: center;
  170. align-items: center;
  171. padding: 2vw;
  172. input {
  173. width: 100%;
  174. padding: 2vw;
  175. background-color: var(--f1Color);
  176. font-size: var(--font14Size);
  177. border-radius: 5px;
  178. }
  179. }
  180. .two {
  181. position: relative;
  182. flex-grow: 1;
  183. background-color: var(--f9Color);
  184. margin: 2vw 0 0 0;
  185. .list {
  186. background-color: var(--mainColor);
  187. border: 1px solid var(--f5Color);
  188. padding: 2vw 0;
  189. margin: 2vw 2vw 0 2vw;
  190. border-radius: 10px;
  191. .list_1 {
  192. display: flex;
  193. justify-content: space-between;
  194. align-items: center;
  195. padding: 2vw;
  196. .left {
  197. display: flex;
  198. align-items: center;
  199. font-size: var(--font16Size);
  200. color: var(--f191Color);
  201. .image {
  202. width: 10vw;
  203. height: 10vw;
  204. border-radius: 10vw;
  205. margin: 0 2vw 0 0;
  206. }
  207. }
  208. .right {
  209. font-size: var(--font12Size);
  210. color: var(--f99Color);
  211. }
  212. }
  213. .list_2 {
  214. .image {
  215. width: 100%;
  216. height: 30vh;
  217. }
  218. }
  219. .list_3 {
  220. padding: 2vw;
  221. font-size: var(--font16Size);
  222. }
  223. }
  224. }
  225. }
  226. .scroll-view {
  227. position: absolute;
  228. top: 0;
  229. left: 0;
  230. right: 0;
  231. bottom: 0;
  232. .list-scroll-view {
  233. display: flex;
  234. flex-direction: column;
  235. }
  236. }
  237. .is_bottom {
  238. width: 100%;
  239. text-align: center;
  240. text {
  241. padding: 2vw 0;
  242. display: inline-block;
  243. color: var(--f85Color);
  244. font-size: var(--font14Size);
  245. }
  246. }
  247. </style>