team.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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.userId==user.id?'label_1':'label_2']">{{item.userId==user.id?'队长':'队员'}}</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. isUse: 'Y'
  80. }
  81. const res = await $api('team/list', 'GET', {
  82. ...info,
  83. ...searchInfo.value
  84. });
  85. if (res.code === 200) {
  86. list.value = res.rows
  87. total.value = res.total
  88. } else {
  89. uni.showToast({
  90. title: res.msg || '',
  91. icon: 'error',
  92. });
  93. }
  94. };
  95. //查询
  96. const toInput = (e : any) => {
  97. if (searchInfo.value.name) searchInfo.value.name = e.detail.value
  98. else searchInfo.value = {}
  99. clearPage();
  100. search();
  101. };
  102. // 球队详情
  103. const toInfo = (item : any) => {
  104. uni.navigateTo({
  105. url: `/pagesHome/team/info?id=${item._id || item.id}`,
  106. })
  107. };
  108. // 分页
  109. const toPage = () => {
  110. if (total.value > list.value.length) {
  111. uni.showLoading({
  112. title: '加载中',
  113. mask: true
  114. })
  115. pageNum.value = pageNum.value + 1
  116. pageSize.value = pageNum.value * 10;
  117. search();
  118. uni.hideLoading();
  119. } else is_bottom.value = true
  120. };
  121. const toScroll = (e : any) => {
  122. let up = scrollTop.value;
  123. scrollTop.value = e.detail.scrollTop
  124. let num = Math.sign(up - e.detail.scrollTop);
  125. if (num == 1) is_bottom.value = false
  126. };
  127. // 清空数据
  128. const clearPage = () => {
  129. list.value = []
  130. pageNum.value = 1
  131. pageSize.value = 10
  132. page.value = 0
  133. };
  134. </script>
  135. <style lang="scss" scoped>
  136. .main {
  137. display: flex;
  138. flex-direction: column;
  139. width: 100vw;
  140. height: 66vh;
  141. .first {
  142. display: flex;
  143. justify-content: center;
  144. align-items: center;
  145. padding: 2vw;
  146. border-bottom: 1px solid var(--f5Color);
  147. input {
  148. width: 100%;
  149. padding: 2vw;
  150. background-color: var(--f1Color);
  151. font-size: var(--font14Size);
  152. border-radius: 5px;
  153. }
  154. }
  155. .second {
  156. position: relative;
  157. flex-grow: 1;
  158. .list {
  159. border-bottom: 1px solid var(--f5Color);
  160. padding: 3vw;
  161. .list_1 {
  162. display: flex;
  163. align-items: center;
  164. .left {
  165. width: 15vw;
  166. .image {
  167. width: 15vw;
  168. height: 15vw;
  169. border-radius: 20vw;
  170. }
  171. }
  172. .right {
  173. width: 75vw;
  174. margin: 0 0 0 2vw;
  175. .name {
  176. font-size: var(--font16Size);
  177. .label {
  178. padding: 3px 6px;
  179. font-size: 10px;
  180. color: var(--mainColor);
  181. border-radius: 2px;
  182. }
  183. .label_1 {
  184. background-color: var(--fF0Color);
  185. }
  186. .label_2 {
  187. background-color: var(--fFFColor);
  188. }
  189. }
  190. .other {
  191. margin: 1vw 0 0 0;
  192. font-size: var(--font14Size);
  193. color: var(--f85Color);
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. .scroll-view {
  201. position: absolute;
  202. top: 0;
  203. left: 0;
  204. right: 0;
  205. bottom: 0;
  206. .list-scroll-view {
  207. display: flex;
  208. flex-direction: column;
  209. }
  210. }
  211. .is_bottom {
  212. width: 100%;
  213. text-align: center;
  214. text {
  215. padding: 2vw 0;
  216. display: inline-block;
  217. color: var(--f85Color);
  218. font-size: var(--font14Size);
  219. }
  220. }
  221. </style>