index.vue 9.1 KB

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