person.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.name" @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="title">约过的战队</view>
  10. <view class="list" v-for="(item, index) in list" :key="index" @tap="toSelect(item)">
  11. <view class="list_1">
  12. <view class="left">
  13. <image class="image" mode="aspectFill" :src="item.logo||config.logoUrl"></image>
  14. </view>
  15. <view class="right">
  16. <view class="name">
  17. {{item.name||'暂无名称'}}
  18. </view>
  19. <view class="other">
  20. <view class="other_1">{{item.city||'未入驻'}}</view>
  21. <view class="other_2">胜{{item.win||0}},平{{item.flat||0}},负{{item.burden||0}}</view>
  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. logo ?: string,
  44. address ?: string,
  45. win ?: string,
  46. burden ?: string,
  47. flat ?: string,
  48. };
  49. // 用户信息
  50. const user = ref({});
  51. // 查询
  52. const searchInfo = ref({});
  53. // 列表
  54. const list = ref<PropsItem[]>([{ id: 1, name: '成都容城' }, { id: 1, name: 'YYDS|脏三疯' }]);
  55. // 分页
  56. const pageNum = ref(1);
  57. const pageSize = ref(10);
  58. const total = ref(0);
  59. // 基本信息
  60. const config = ref({});
  61. // 数据是否触底
  62. const scrollTop = ref(0);
  63. const is_bottom = ref(false);
  64. onShow(async () => {
  65. await searchConfig();
  66. await searchUser();
  67. await search();
  68. })
  69. // config信息
  70. const searchConfig = async () => {
  71. config.value = uni.getStorageSync('config');
  72. };
  73. // 用户信息
  74. const searchUser = async () => {
  75. user.value = uni.getStorageSync('user');
  76. };
  77. // 查询约过的战队列表
  78. const search = async () => {
  79. const info = {
  80. pageNum: pageNum.value,
  81. pageSize: pageSize.value,
  82. userId: user.value.id
  83. }
  84. const res = await $api('team/list', 'GET', {
  85. ...info
  86. });
  87. if (res.code === 200) {
  88. list.value = res.rows
  89. total.value = res.total
  90. } else {
  91. uni.showToast({
  92. title: res.msg || '',
  93. icon: 'error',
  94. });
  95. }
  96. };
  97. // 查询球队列表
  98. const searchTeam = async () => {
  99. const info = {
  100. pageNum: pageNum.value,
  101. pageSize: pageSize.value,
  102. }
  103. const res = await $api('team/list', 'GET', {
  104. ...info,
  105. ...searchInfo
  106. });
  107. if (res.code === 200) {
  108. list.value = res.rows
  109. total.value = res.total
  110. } else {
  111. uni.showToast({
  112. title: res.msg || '',
  113. icon: 'error',
  114. });
  115. }
  116. };
  117. //查询
  118. const toInput = (e : any) => {
  119. if (searchInfo.value.name) searchInfo.value.name = e.detail.value
  120. searchInfo.value = {}
  121. clearPage();
  122. searchTeam();
  123. };
  124. // 选择战队
  125. const toSelect = (item : any) => {
  126. uni.$emit('opponentInfo', item);
  127. // 返回上一个页面
  128. uni.navigateBack({
  129. delta: 1
  130. })
  131. };
  132. // 分页
  133. const toPage = () => {
  134. if (total.value > list.value.length) {
  135. uni.showLoading({
  136. title: '加载中',
  137. mask: true
  138. })
  139. pageNum.value = pageNum.value + 1
  140. pageSize.value = pageNum.value * 10;
  141. search();
  142. uni.hideLoading();
  143. } else is_bottom.value = true
  144. };
  145. const toScroll = (e : any) => {
  146. let up = scrollTop.value;
  147. scrollTop.value = e.detail.scrollTop
  148. let num = Math.sign(up - e.detail.scrollTop);
  149. if (num == 1) is_bottom.value = false
  150. };
  151. // 清空数据
  152. const clearPage = () => {
  153. list.value = []
  154. pageNum.value = 1
  155. pageSize.value = 10
  156. };
  157. </script>
  158. <style lang="scss" scoped>
  159. .content {
  160. display: flex;
  161. flex-direction: column;
  162. width: 100vw;
  163. height: 66vh;
  164. .one {
  165. display: flex;
  166. justify-content: center;
  167. align-items: center;
  168. padding: 2vw;
  169. border-bottom: 1px solid var(--f5Color);
  170. input {
  171. width: 100%;
  172. padding: 2vw;
  173. background-color: var(--f1Color);
  174. font-size: var(--font14Size);
  175. border-radius: 5px;
  176. }
  177. }
  178. .two {
  179. position: relative;
  180. flex-grow: 1;
  181. .title {
  182. padding: 1vw 0;
  183. text-align: center;
  184. background-color: var(--f9Color);
  185. }
  186. .list {
  187. border-bottom: 1px solid var(--f5Color);
  188. padding: 3vw;
  189. .list_1 {
  190. display: flex;
  191. align-items: center;
  192. .left {
  193. width: 15vw;
  194. .image {
  195. width: 15vw;
  196. height: 15vw;
  197. border-radius: 2vw;
  198. }
  199. }
  200. .right {
  201. width: 75vw;
  202. margin: 0 0 0 2vw;
  203. .name {
  204. font-size: var(--font16Size);
  205. }
  206. .other {
  207. display: flex;
  208. justify-content: space-between;
  209. margin: 1vw 0 0 0;
  210. font-size: var(--font14Size);
  211. color: var(--f85Color);
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. .scroll-view {
  219. position: absolute;
  220. top: 0;
  221. left: 0;
  222. right: 0;
  223. bottom: 0;
  224. .list-scroll-view {
  225. display: flex;
  226. flex-direction: column;
  227. }
  228. }
  229. .is_bottom {
  230. width: 100%;
  231. text-align: center;
  232. text {
  233. padding: 2vw 0;
  234. display: inline-block;
  235. color: var(--f85Color);
  236. font-size: var(--font14Size);
  237. }
  238. }
  239. </style>