activity.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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, toRefs, 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 searchInfo = ref({});
  88. // 列表
  89. const list = ref<PropsItem[]>([{ id: 1, name: '测试球队' }, { id: 1, name: '肝帝集团队' }]);
  90. // 分页
  91. const pageNum = ref(1);
  92. const pageSize = ref(10);
  93. const total = ref(0);
  94. const statusList = ref([]);
  95. // 数据是否触底
  96. const scrollTop = ref(0);
  97. const is_bottom = ref(false);
  98. const props = defineProps({
  99. config: { type: Object, default: () => { } },
  100. });
  101. const { config } = toRefs(props);
  102. onShow(async () => {
  103. await searchUser();
  104. await search();
  105. })
  106. // 用户信息
  107. const searchUser = async () => {
  108. user.value = uni.getStorageSync('user');
  109. let res;
  110. // 比赛状态
  111. res = await $api(`dict/data/list`, 'GET', { dictType: 'sys_game_status', status: '0' });
  112. if (res.code === 200 && res.total > 0) statusList.value = res.rows
  113. };
  114. // 查询列表
  115. const search = async () => {
  116. const info = {
  117. pageNum: pageNum.value,
  118. pageSize: pageSize.value,
  119. userId: user.value.id
  120. }
  121. const res = await $api('game/list', 'GET', {
  122. ...info,
  123. ...searchInfo.value
  124. });
  125. if (res.code === 200) {
  126. list.value = res.rows
  127. total.value = res.total
  128. } else {
  129. uni.showToast({
  130. title: res.msg || '',
  131. icon: 'error',
  132. });
  133. }
  134. };
  135. //查询
  136. const toInput = (e : any) => {
  137. if (searchInfo.value.name) searchInfo.value.name = e.detail.value
  138. searchInfo.value = {}
  139. clearPage();
  140. search();
  141. };
  142. // 活动详情
  143. const toInfo = (item : any) => {
  144. uni.navigateTo({
  145. url: `/pagesHome/activity/info?id=${item._id || item.id}&name=${item.name || ''}`,
  146. })
  147. };
  148. // 日期换算星期几
  149. const getDayOfWeek = (dateString) => {
  150. if (dateString) {
  151. const date = new Date(dateString);
  152. const dayOfWeek = date.getDay();
  153. const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  154. return weekdays[dayOfWeek];
  155. } else return '暂无日期';
  156. };
  157. // 换算状态
  158. const getStatus = (value) => {
  159. if (value) {
  160. const data = statusList.value.find(i => i.dictValue == value)
  161. if (data) return data.dictLabel
  162. } else return '暂无状态';
  163. };
  164. // 分页
  165. const toPage = () => {
  166. if (total.value > list.value.length) {
  167. uni.showLoading({
  168. title: '加载中',
  169. mask: true
  170. })
  171. pageNum.value = pageNum.value + 1
  172. pageSize.value = pageNum.value * 10;
  173. search();
  174. uni.hideLoading();
  175. } else is_bottom.value = true
  176. };
  177. const toScroll = (e : any) => {
  178. let up = scrollTop.value;
  179. scrollTop.value = e.detail.scrollTop
  180. let num = Math.sign(up - e.detail.scrollTop);
  181. if (num == 1) is_bottom.value = false
  182. };
  183. // 清空数据
  184. const clearPage = () => {
  185. list.value = []
  186. pageNum.value = 1
  187. pageSize.value = 10
  188. };
  189. </script>
  190. <style lang="scss" scoped>
  191. .main {
  192. display: flex;
  193. flex-direction: column;
  194. width: 100vw;
  195. height: 66vh;
  196. .first {
  197. display: flex;
  198. justify-content: center;
  199. align-items: center;
  200. padding: 2vw;
  201. border-bottom: 1px solid var(--f5Color);
  202. input {
  203. width: 100%;
  204. padding: 2vw;
  205. background-color: var(--f1Color);
  206. font-size: var(--font14Size);
  207. border-radius: 5px;
  208. }
  209. }
  210. .second {
  211. position: relative;
  212. flex-grow: 1;
  213. .other {
  214. display: flex;
  215. .other_1 {
  216. padding: 2vw 2vw 2vw 5vw;
  217. font-size: 20px;
  218. font-weight: bold;
  219. .line {
  220. height: 18vh;
  221. margin: 0 0 0 2px;
  222. border-left: 1px dashed var(--f99Color);
  223. }
  224. }
  225. .other_2 {
  226. width: 90%;
  227. .list {
  228. .list_1 {
  229. display: flex;
  230. align-items: center;
  231. padding: 4vw 2vw 2vw 2vw;
  232. .date {
  233. font-size: var(--font16Size);
  234. font-weight: bold;
  235. }
  236. .status {
  237. font-size: 10px;
  238. margin: 0 1vw;
  239. padding: 1px 5px;
  240. }
  241. .status0 {
  242. color: var(--mainColor);
  243. background-color: var(--f35BColor);
  244. }
  245. .status1 {
  246. color: var(--mainColor);
  247. background-color: var(--fFFColor);
  248. }
  249. .status2 {
  250. color: var(--mainColor);
  251. background-color: var(--fF0Color);
  252. }
  253. .status3 {
  254. color: var(--f99Color);
  255. background-color: var(--f9Color);
  256. }
  257. }
  258. .list_2 {
  259. border: 1px solid var(--f5Color);
  260. padding: 2vw;
  261. border-radius: 2px;
  262. .name {
  263. font-size: var(--font16Size);
  264. font-weight: bold;
  265. margin: 2vw;
  266. }
  267. .score {
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. font-size: var(--font14Size);
  272. background-color: var(--f9Color);
  273. border-radius: 5vw;
  274. padding: 1vw 0;
  275. .red {
  276. display: flex;
  277. align-items: center;
  278. margin: 0 1vw 0 0;
  279. .red_image {
  280. margin: 0 1vw;
  281. .image {
  282. width: 8vw;
  283. height: 8vw;
  284. border-radius: 8vw;
  285. }
  286. }
  287. .red_score {
  288. font-size: var(--font16Size);
  289. color: var(--fF0Color);
  290. }
  291. }
  292. .center {
  293. font-size: var(--font16Size);
  294. color: var(--fF0Color);
  295. }
  296. .blue {
  297. display: flex;
  298. align-items: center;
  299. margin: 0 0 0 1vw;
  300. .blue_image {
  301. margin: 0 1vw;
  302. .image {
  303. width: 8vw;
  304. height: 8vw;
  305. border-radius: 8vw;
  306. }
  307. }
  308. .blue_score {
  309. font-size: var(--font16Size);
  310. color: var(--fF0Color);
  311. }
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. }
  320. .scroll-view {
  321. position: absolute;
  322. top: 0;
  323. left: 0;
  324. right: 0;
  325. bottom: 0;
  326. .list-scroll-view {
  327. display: flex;
  328. flex-direction: column;
  329. }
  330. }
  331. .is_bottom {
  332. width: 100%;
  333. text-align: center;
  334. text {
  335. padding: 2vw 0;
  336. display: inline-block;
  337. color: var(--f85Color);
  338. font-size: var(--font14Size);
  339. }
  340. }
  341. </style>