index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. <u-search shape="square" :show-action="false" placeholder="请输入公证员姓名" @focus="toChange"></u-search>
  5. </view>
  6. <view class="bottom">
  7. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  8. <view class="list-scroll-view">
  9. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  10. <view class="list_1">
  11. <view class="left">
  12. <image class="image" :src="item.logo&&item.logo.length>0?item.logo[0].url:''">
  13. </image>
  14. </view>
  15. <view class="right">
  16. <view class="name textOver">{{item.zw||'暂无'}}: {{item.name||'暂无'}}</view>
  17. <view class="other">
  18. <text>专业: {{item.speciality||"暂无"}}</text>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="is_bottom" v-if="is_bottom">
  24. <text>{{config.bottom_title||'没有更多了!'}}</text>
  25. </view>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. </view>
  30. </template>
  31. <script setup lang="ts">
  32. import { getCurrentInstance, ref } from 'vue';
  33. //该依赖已内置不需要单独安装
  34. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  35. // 请求接口
  36. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  37. // 搜索
  38. const searchName = ref('');
  39. // 基本信息
  40. const config = ref({ logo: [] });
  41. // 列表
  42. const list = ref([]);
  43. const total = ref(0);
  44. const skip = ref(0);
  45. const limit = ref(6);
  46. const page = ref(0);
  47. // 数据是否触底
  48. const is_bottom = ref(false);
  49. const scrollTop = ref(0);
  50. onShow(async () => {
  51. await searchConfig();
  52. await clearPage();
  53. await search();
  54. })
  55. onPullDownRefresh(async () => {
  56. await clearPage();
  57. await search();
  58. uni.stopPullDownRefresh();
  59. })
  60. // config信息
  61. const searchConfig = async () => {
  62. config.value = uni.getStorageSync('config');
  63. };
  64. // 查询
  65. const search = async () => {
  66. const info = {
  67. skip: skip.value,
  68. limit: limit.value,
  69. is_use: '0'
  70. }
  71. if (searchName.value) info.name = searchName.value
  72. const res = await $api('personnel', 'GET', info);
  73. if (res.errcode === 0) {
  74. list.value = list.value.concat(res.data)
  75. total.value = res.total
  76. } else {
  77. uni.showToast({
  78. title: res.errmsg || '',
  79. icon: 'error',
  80. });
  81. }
  82. };
  83. // 搜索
  84. const toChange = async (e) => {
  85. if (e) searchName.value = e
  86. else searchName.value = ''
  87. await clearPage();
  88. await search();
  89. };
  90. // 查看详情
  91. const toView = (item) => {
  92. uni.navigateTo({
  93. url: `/pagesHome/personnel/detail?id=${item.id || item._id}`
  94. })
  95. };
  96. // 分页
  97. const toPage = () => {
  98. if (total.value > list.value.length) {
  99. uni.showLoading({
  100. title: '加载中',
  101. mask: true
  102. })
  103. page.value = page.value + 1;
  104. skip.value = page.value * limit.value;
  105. search();
  106. uni.hideLoading();
  107. } else is_bottom.value = true
  108. };
  109. // 清空列表
  110. const clearPage = () => {
  111. list.value = []
  112. skip.value = 0
  113. limit.value = 6
  114. page.value = 0
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. .content {
  119. display: flex;
  120. flex-direction: column;
  121. width: 100vw;
  122. height: 100vh;
  123. .top {
  124. margin: 2vw;
  125. }
  126. .bottom {
  127. position: relative;
  128. flex-grow: 1;
  129. background-color: var(--f1Color);
  130. .list {
  131. width: 46vw;
  132. margin: 2vw 0 0 0;
  133. border-radius: 5px;
  134. border: 1px solid var(--f5Color);
  135. background-color: var(--mainColor);
  136. .list_1 {
  137. .left {
  138. .image {
  139. width: 100%;
  140. height: 125px;
  141. border-radius: 5px 5px 0 0;
  142. }
  143. }
  144. .right {
  145. display: flex;
  146. flex-direction: column;
  147. justify-content: space-between;
  148. padding: 2vw;
  149. .name {
  150. margin: 2vw 0;
  151. font-size: var(--font16Size);
  152. }
  153. .other {
  154. font-size: var(--font14Size);
  155. color: var(--f85Color);
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. .scroll-view {
  163. position: absolute;
  164. top: 0;
  165. left: 0;
  166. right: 0;
  167. bottom: 0;
  168. .list-scroll-view {
  169. display: flex;
  170. justify-content: space-between;
  171. flex-wrap: wrap;
  172. padding: 0 2vw;
  173. }
  174. }
  175. .is_bottom {
  176. width: 100%;
  177. text-align: center;
  178. text {
  179. padding: 2vw 0;
  180. display: inline-block;
  181. color: var(--f85Color);
  182. font-size: var(--font12Size);
  183. }
  184. }
  185. </style>