index.vue 5.8 KB

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