team.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="main">
  3. <view class="first">
  4. <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索球队名称">
  5. </view>
  6. <view class="second">
  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" mode="aspectFill" :src="item.logo||config.logoUrl"></image>
  13. </view>
  14. <view class="right">
  15. <view class="name">
  16. {{item.name||'暂无名称'}}
  17. <text class="label"
  18. :class="[item.user_type=='0'?'label_1':'label_2']">{{item.label||'队长'}}</text>
  19. </view>
  20. <view class="other">
  21. {{item.activity||'暂无活动'}}
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="is_bottom" v-if="is_bottom">
  27. <text>{{config.bottomTitle||'到底了!'}}</text>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. </view>
  32. </view>
  33. </template>
  34. <script setup lang="ts">
  35. import { ref, toRefs, getCurrentInstance } from 'vue';
  36. //该依赖已内置不需要单独安装
  37. import { onShow } from "@dcloudio/uni-app";
  38. // 请求接口
  39. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  40. interface PropsItem {
  41. id ?: number,
  42. name ?: string,
  43. activity ?: string,
  44. logo ?: string,
  45. label ?: string,
  46. user_type ?: string,
  47. };
  48. // 用户信息
  49. const user = ref({});
  50. // 查询
  51. const searchInfo = ref({});
  52. // 列表
  53. const list = ref<PropsItem[]>([{ id: 1, name: '测试球队' }, { id: 2, name: '肝帝集团队' }]);
  54. // 分页
  55. const pageNum = ref(1);
  56. const pageSize = ref(10);
  57. const total = ref(0);
  58. // 数据是否触底
  59. const scrollTop = ref(0);
  60. const is_bottom = ref(false);
  61. const props = defineProps({
  62. config: { type: Object, default: () => { } },
  63. });
  64. const { config } = toRefs(props);
  65. onShow(async () => {
  66. await searchUser();
  67. await search();
  68. })
  69. // 用户信息
  70. const searchUser = async () => {
  71. user.value = uni.getStorageSync('user');
  72. };
  73. // 查询列表
  74. const search = async () => {
  75. const info = {
  76. pageNum: pageNum.value,
  77. pageSize: pageSize.value,
  78. userId: user.value.id
  79. }
  80. const res = await $api('team/list', 'GET', {
  81. ...info,
  82. ...searchInfo.value
  83. });
  84. if (res.code === 200) {
  85. list.value = res.rows
  86. total.value = res.total
  87. } else {
  88. uni.showToast({
  89. title: res.msg || '',
  90. icon: 'error',
  91. });
  92. }
  93. };
  94. //查询
  95. const toInput = (e : any) => {
  96. if (searchInfo.value.name) searchInfo.value.name = e.detail.value
  97. else searchInfo.value = {}
  98. clearPage();
  99. search();
  100. };
  101. // 球队详情
  102. const toInfo = (item : any) => {
  103. uni.navigateTo({
  104. url: `/pagesHome/team/info?id=${item._id || item.id}`,
  105. })
  106. };
  107. // 分页
  108. const toPage = () => {
  109. if (total.value > list.value.length) {
  110. uni.showLoading({
  111. title: '加载中',
  112. mask: true
  113. })
  114. pageNum.value = pageNum.value + 1
  115. pageSize.value = pageNum.value * 10;
  116. search();
  117. uni.hideLoading();
  118. } else is_bottom.value = true
  119. };
  120. const toScroll = (e : any) => {
  121. let up = scrollTop.value;
  122. scrollTop.value = e.detail.scrollTop
  123. let num = Math.sign(up - e.detail.scrollTop);
  124. if (num == 1) is_bottom.value = false
  125. };
  126. // 清空数据
  127. const clearPage = () => {
  128. list.value = []
  129. pageNum.value = 1
  130. pageSize.value = 10
  131. page.value = 0
  132. };
  133. </script>
  134. <style lang="scss" scoped>
  135. .main {
  136. display: flex;
  137. flex-direction: column;
  138. width: 100vw;
  139. height: 66vh;
  140. .first {
  141. display: flex;
  142. justify-content: center;
  143. align-items: center;
  144. padding: 2vw;
  145. border-bottom: 1px solid var(--f5Color);
  146. input {
  147. width: 100%;
  148. padding: 2vw;
  149. background-color: var(--f1Color);
  150. font-size: var(--font14Size);
  151. border-radius: 5px;
  152. }
  153. }
  154. .second {
  155. position: relative;
  156. flex-grow: 1;
  157. .list {
  158. border-bottom: 1px solid var(--f5Color);
  159. padding: 3vw;
  160. .list_1 {
  161. display: flex;
  162. align-items: center;
  163. .left {
  164. width: 15vw;
  165. .image {
  166. width: 15vw;
  167. height: 15vw;
  168. border-radius: 20vw;
  169. }
  170. }
  171. .right {
  172. width: 75vw;
  173. margin: 0 0 0 2vw;
  174. .name {
  175. font-size: var(--font16Size);
  176. .label {
  177. padding: 3px 6px;
  178. font-size: 10px;
  179. color: var(--mainColor);
  180. border-radius: 2px;
  181. }
  182. .label_1 {
  183. background-color: var(--fFFColor);
  184. }
  185. .label_2 {
  186. background-color: var(--fF0Color);
  187. }
  188. }
  189. .other {
  190. margin: 1vw 0 0 0;
  191. font-size: var(--font14Size);
  192. color: var(--f85Color);
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. .scroll-view {
  200. position: absolute;
  201. top: 0;
  202. left: 0;
  203. right: 0;
  204. bottom: 0;
  205. .list-scroll-view {
  206. display: flex;
  207. flex-direction: column;
  208. }
  209. }
  210. .is_bottom {
  211. width: 100%;
  212. text-align: center;
  213. text {
  214. padding: 2vw 0;
  215. display: inline-block;
  216. color: var(--f85Color);
  217. font-size: var(--font14Size);
  218. }
  219. }
  220. </style>