activity.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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="other">
  10. <view class="other_1">
  11. <view class="drop" v-for="(item, index) in list" :key="index">
  12. .
  13. <view class="line"></view>
  14. </view>
  15. </view>
  16. <view class="other_2">
  17. <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
  18. <view class="list_1">
  19. <view class="date">{{item.date||'暂无日期'}}</view>
  20. <view class="status"
  21. :class="[item.status=='0'?'status0':item.status=='1'?'status1':'status2']">
  22. {{item.status_name||'暂无状态'}}
  23. </view>
  24. </view>
  25. <view class="list_2">
  26. <view class="name">{{item.name||'暂无活动名称'}}</view>
  27. <view class="score">
  28. <view class="red">
  29. <view class="red_name">{{item.red_name||'暂无红方名称'}}</view>
  30. <view class="red_image">
  31. <image class="image" mode="aspectFill"
  32. :src="item.red_logo||config.logoUrl"></image>
  33. </view>
  34. <view class="red_score">{{item.red_score||0}}</view>
  35. </view>
  36. <view class="center">:</view>
  37. <view class="blue">
  38. <view class="blue_score">{{item.blue_score||0}}</view>
  39. <view class="blue_image">
  40. <image class="image" mode="aspectFill"
  41. :src="item.blue_logo||config.logoUrl"></image>
  42. </view>
  43. <view class="blue_name">{{item.blue_name||'暂无蓝方名称'}}</view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="is_bottom" v-if="is_bottom">
  51. <text>{{config.bottomTitle||'到底了!'}}</text>
  52. </view>
  53. </view>
  54. </scroll-view>
  55. </view>
  56. </view>
  57. </template>
  58. <script setup lang="ts">
  59. import { ref, toRefs, getCurrentInstance } from 'vue';
  60. //该依赖已内置不需要单独安装
  61. import { onShow } from "@dcloudio/uni-app";
  62. // 请求接口
  63. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  64. interface PropsItem {
  65. id ?: number,
  66. name ?: string,
  67. date ?: string,
  68. red_name ?: string,
  69. red_score ?: number,
  70. red_logo ?: string,
  71. blue_name ?: string,
  72. blue_score ?: number,
  73. blue_logo ?: string,
  74. status ?: string,
  75. status_name ?: string,
  76. };
  77. // 用户信息
  78. const user = ref({});
  79. // 查询
  80. const searchInfo = ref({ });
  81. // 列表
  82. const list = ref<PropsItem[]>([{ id: 1, name: '测试球队' }, { id: 1, name: '肝帝集团队' }]);
  83. // 分页
  84. const pageNum = ref(1);
  85. const pageSize = ref(10);
  86. const total = ref(0);
  87. // 数据是否触底
  88. const scrollTop = ref(0);
  89. const is_bottom = ref(false);
  90. const props = defineProps({
  91. config: { type: Object, default: () => { } },
  92. });
  93. const { config } = toRefs(props);
  94. onShow(async () => {
  95. await searchUser();
  96. await search();
  97. })
  98. // 用户信息
  99. const searchUser = async () => {
  100. user.value = uni.getStorageSync('user');
  101. };
  102. // 查询列表
  103. const search = async () => {
  104. const info = {
  105. pageNum: pageNum.value,
  106. pageSize: pageSize.value,
  107. userId: user.value.id
  108. }
  109. const res = await $api('activity/list', 'GET', {
  110. ...info,
  111. ...searchInfo.value
  112. });
  113. if (res.code === 200) {
  114. list.value = res.rows
  115. total.value = res.total
  116. } else {
  117. uni.showToast({
  118. title: res.msg || '',
  119. icon: 'error',
  120. });
  121. }
  122. };
  123. //查询
  124. const toInput = (e : any) => {
  125. if (searchInfo.value.name) searchInfo.value.name = e.detail.value
  126. searchInfo.value = { }
  127. clearPage();
  128. search();
  129. };
  130. // 活动详情
  131. const toInfo = (item : any) => {
  132. uni.navigateTo({
  133. url: `/pagesHome/activity/info?id=${item._id || item.id}&name=${item.name}`,
  134. })
  135. };
  136. // 分页
  137. const toPage = () => {
  138. if (total.value > list.value.length) {
  139. uni.showLoading({
  140. title: '加载中',
  141. mask: true
  142. })
  143. pageNum.value = pageNum.value + 1
  144. pageSize.value = pageNum.value * 10;
  145. search();
  146. uni.hideLoading();
  147. } else is_bottom.value = true
  148. };
  149. const toScroll = (e : any) => {
  150. let up = scrollTop.value;
  151. scrollTop.value = e.detail.scrollTop
  152. let num = Math.sign(up - e.detail.scrollTop);
  153. if (num == 1) is_bottom.value = false
  154. };
  155. // 清空数据
  156. const clearPage = () => {
  157. list.value = []
  158. pageNum.value = 1
  159. pageSize.value = 10
  160. page.value = 0
  161. };
  162. </script>
  163. <style lang="scss" scoped>
  164. .main {
  165. display: flex;
  166. flex-direction: column;
  167. width: 100vw;
  168. height: 66vh;
  169. .first {
  170. display: flex;
  171. justify-content: center;
  172. align-items: center;
  173. padding: 2vw;
  174. border-bottom: 1px solid var(--f5Color);
  175. input {
  176. width: 100%;
  177. padding: 2vw;
  178. background-color: var(--f1Color);
  179. font-size: var(--font14Size);
  180. border-radius: 5px;
  181. }
  182. }
  183. .second {
  184. position: relative;
  185. flex-grow: 1;
  186. .other {
  187. display: flex;
  188. .other_1 {
  189. padding: 2vw 2vw 2vw 5vw;
  190. font-size: 20px;
  191. font-weight: bold;
  192. .line {
  193. height: 18vh;
  194. margin: 0 0 0 2px;
  195. border-left: 1px dashed var(--f99Color);
  196. }
  197. }
  198. .other_2 {
  199. width: 90%;
  200. .list {
  201. .list_1 {
  202. display: flex;
  203. align-items: center;
  204. padding: 4vw 2vw 2vw 2vw;
  205. .date {
  206. font-size: var(--font16Size);
  207. font-weight: bold;
  208. }
  209. .status {
  210. font-size: var(--font12Size);
  211. margin: 0 1vw;
  212. padding: 1px 5px;
  213. }
  214. .status0 {
  215. color: var(--mainColor);
  216. background-color: var(--fF0Color);
  217. }
  218. .status1 {
  219. color: var(--mainColor);
  220. background-color: var(--fFFColor);
  221. }
  222. .status2 {
  223. color: var(--f99Color);
  224. background-color: var(--f9Color);
  225. }
  226. }
  227. .list_2 {
  228. border: 1px solid var(--f5Color);
  229. padding: 2vw;
  230. border-radius: 2px;
  231. .name {
  232. font-size: var(--font16Size);
  233. font-weight: bold;
  234. margin: 2vw;
  235. }
  236. .score {
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. font-size: var(--font14Size);
  241. background-color: var(--f9Color);
  242. border-radius: 5vw;
  243. padding: 1vw 0;
  244. .red {
  245. display: flex;
  246. align-items: center;
  247. margin: 0 1vw 0 0;
  248. .red_image {
  249. margin: 0 1vw;
  250. .image {
  251. width: 8vw;
  252. height: 8vw;
  253. border-radius: 8vw;
  254. }
  255. }
  256. .red_score {
  257. font-size: var(--font16Size);
  258. color: var(--fF0Color);
  259. }
  260. }
  261. .center {
  262. font-size: var(--font16Size);
  263. color: var(--fF0Color);
  264. }
  265. .blue {
  266. display: flex;
  267. align-items: center;
  268. margin: 0 0 0 1vw;
  269. .blue_image {
  270. margin: 0 1vw;
  271. .image {
  272. width: 8vw;
  273. height: 8vw;
  274. border-radius: 8vw;
  275. }
  276. }
  277. .blue_score {
  278. font-size: var(--font16Size);
  279. color: var(--fF0Color);
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. }
  289. .scroll-view {
  290. position: absolute;
  291. top: 0;
  292. left: 0;
  293. right: 0;
  294. bottom: 0;
  295. .list-scroll-view {
  296. display: flex;
  297. flex-direction: column;
  298. }
  299. }
  300. .is_bottom {
  301. width: 100%;
  302. text-align: center;
  303. text {
  304. padding: 2vw 0;
  305. display: inline-block;
  306. color: var(--f85Color);
  307. font-size: var(--font14Size);
  308. }
  309. }
  310. </style>