index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <view class="one_1">
  5. <input type="text" v-model="searchInfo.name" placeholder="请输入赛事名称">
  6. </view>
  7. <view class="one_2">
  8. <button size="mini" class="button" type="primary" @click="toInput">搜索</button>
  9. </view>
  10. </view>
  11. <view class="two">
  12. <tabs :tabs="tabs" @tabsChange="tabsChange">
  13. <view class="tabsList">
  14. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll"
  15. v-if="total>0">
  16. <view class="list-scroll-view">
  17. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  18. <view class="list_1">
  19. <image class="image" :src="getUrl(item.file)"></image>
  20. </view>
  21. <view class="list_2 textOne">{{item.name||'暂无比赛名称'}}</view>
  22. <view class="list_3">
  23. <view class="list_left">
  24. <text class="t-icon t-icon-shizhong"></text>
  25. <span>{{getTime(item.start_time,item.end_time)||'暂无'}}</span>
  26. </view>
  27. <view class="list_left">
  28. <text class="t-icon t-icon-gonglve"></text>
  29. <span>{{getDict(item.match_type,'type')||'自办'}}</span>
  30. </view>
  31. <view class="list_right"
  32. :class="[item.match_status=='0'?'active_1':item.match_status=='1'?'active_2':item.match_status=='2'?'active_3':'active_4']">
  33. {{getDict(item.match_status,'status')}}
  34. </view>
  35. </view>
  36. <view class="list_4">
  37. <button class="warning" size="default" type="warn"
  38. @tap.stop="toSign(item)">报名信息</button>
  39. <button class="warning" size="default" type="warn" @tap.stop="toScore(item)"
  40. v-if="item.match_status=='2'">分数列表</button>
  41. </view>
  42. </view>
  43. <view class="is_bottom" v-if="is_bottom">
  44. <text>{{config.bottom_title||'到底了!'}}</text>
  45. </view>
  46. </view>
  47. </scroll-view>
  48. <o-empty v-else />
  49. </view>
  50. </tabs>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import tabs from '../../components/tabs/index.vue';
  56. export default {
  57. components: {
  58. tabs
  59. },
  60. data() {
  61. return {
  62. searchInfo: {},
  63. config: {},
  64. user: {},
  65. tabs: {
  66. active: '0',
  67. bgColor: '#ffffff',
  68. menu: []
  69. },
  70. list: [],
  71. total: 0,
  72. skip: 0,
  73. limit: 6,
  74. page: 0,
  75. // 数据是否触底
  76. is_bottom: false,
  77. scrollTop: 0,
  78. statusList: [],
  79. typeList: []
  80. }
  81. },
  82. onLoad: async function(e) {
  83. const that = this;
  84. that.searchToken();
  85. that.searchConfig();
  86. await that.searchOther();
  87. },
  88. onShow: async function() {
  89. const that = this;
  90. that.clearPage();
  91. await that.search();
  92. },
  93. onPullDownRefresh: async function() {
  94. const that = this;
  95. that.clearPage();
  96. await that.search();
  97. uni.stopPullDownRefresh();
  98. },
  99. methods: {
  100. searchToken() {
  101. const that = this;
  102. try {
  103. const res = uni.getStorageSync('token');
  104. if (res) {
  105. const user = that.$jwt(res);
  106. that.$set(that, `user`, user);
  107. } else {
  108. that.$set(that, `user`, {});
  109. }
  110. } catch (e) {}
  111. },
  112. searchConfig() {
  113. const that = this;
  114. try {
  115. const res = uni.getStorageSync('config');
  116. if (res) that.$set(that, `config`, res);
  117. } catch (e) {
  118. uni.showToast({
  119. title: err.errmsg,
  120. icon: 'error',
  121. duration: 2000
  122. });
  123. }
  124. },
  125. async search() {
  126. const that = this;
  127. let info = {
  128. skip: that.skip,
  129. limit: that.limit,
  130. status: that.tabs.active,
  131. user: that.user.id,
  132. }
  133. const res = await that.$api(`/match`, 'GET', {
  134. ...info,
  135. ...that.searchInfo
  136. })
  137. if (res.errcode == '0') {
  138. let list = [...that.list, ...res.data];
  139. that.$set(that, `list`, list)
  140. that.$set(that, `total`, res.total)
  141. } else {
  142. uni.showToast({
  143. title: res.errmsg,
  144. });
  145. }
  146. },
  147. // 选择选项卡
  148. tabsChange(e) {
  149. const that = this;
  150. that.$set(that.tabs, `active`, e.active)
  151. that.clearPage();
  152. that.search()
  153. },
  154. // 查看详情
  155. toView(item) {
  156. uni.navigateTo({
  157. url: `/pagesHome/match/index?id=${item.id||item._id}`
  158. })
  159. },
  160. // 报名信息
  161. toSign(item) {
  162. const that = this;
  163. if (item.form == '3') {
  164. uni.navigateTo({
  165. url: `/pagesMy/match/active?id=${item.id||item._id}`
  166. })
  167. } else {
  168. uni.navigateTo({
  169. url: `/pagesMy/match/sign?id=${item.id||item._id}`
  170. })
  171. }
  172. },
  173. // 分数列表
  174. toScore(item) {
  175. uni.navigateTo({
  176. url: `/pagesMy/match/score?id=${item.id||item._id}`
  177. })
  178. },
  179. // 输入框
  180. toInput() {
  181. const that = this;
  182. if (!that.searchInfo?.name) that.$set(that, `searchInfo`, {})
  183. that.clearPage();
  184. that.search();
  185. },
  186. // 处理时间
  187. getTime(start_time, end_time) {
  188. if (start_time && end_time) {
  189. const start = new Date(start_time);
  190. const end = new Date(end_time);
  191. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  192. const day = start.getDate();
  193. const weekday = weekdays[start.getDay()];
  194. const month = start.getMonth();
  195. const start_hours = start.getHours();
  196. const start_minutes = start.getMinutes();
  197. const end_hours = end.getHours();
  198. const end_minutes = end.getMinutes();
  199. return `${month}/${day < 10 ? '0' + day : day} ${weekday} ${start_hours.toString().padStart(2, '0')}:${start_minutes.toString().padStart(2, '0')} - ${end_hours.toString().padStart(2, '0')}:${end_minutes.toString().padStart(2, '0')} `;
  200. }
  201. },
  202. // 处理字典表
  203. getDict(item, model) {
  204. const that = this;
  205. let res
  206. if (model == 'status') res = that.statusList.find(i => i.value == item)
  207. else if (model == 'type') res = that.typeList.find(i => i.value == item)
  208. if (res) return res.label
  209. else return '暂无'
  210. },
  211. async searchOther() {
  212. const that = this;
  213. let res;
  214. //状态
  215. res = await that.$api('/dictData', 'GET', {
  216. code: 'examStatus',
  217. is_use: '0'
  218. })
  219. if (res.errcode == '0') {
  220. const menu = res.data.map((item) => {
  221. if (item.value != '-2') {
  222. return {
  223. title: item.label,
  224. active: item.value
  225. }
  226. }
  227. })
  228. that.$set(that.tabs, `menu`, menu)
  229. }
  230. // 查询状态
  231. res = await that.$api(`/dictData`, 'GET', {
  232. code: 'matchStatus',
  233. is_use: '0',
  234. })
  235. if (res.errcode == '0') that.$set(that, `statusList`, res.data)
  236. // 赛事类型
  237. res = await that.$api(`/dictData`, 'GET', {
  238. code: 'activeType',
  239. is_use: '0',
  240. })
  241. if (res.errcode == '0') that.$set(that, `typeList`, res.data)
  242. },
  243. // 图片处理
  244. getUrl(e) {
  245. const that = this;
  246. if (e && e.length > 0) return that.$config.serverFile + e[0].url
  247. else return '/static/match.png'
  248. },
  249. // 分页
  250. toPage(e) {
  251. const that = this;
  252. let list = that.list;
  253. let limit = that.limit;
  254. if (that.total > list.length) {
  255. uni.showLoading({
  256. title: '加载中',
  257. mask: true
  258. })
  259. let page = that.page + 1;
  260. that.$set(that, `page`, page)
  261. let skip = page * limit;
  262. that.$set(that, `skip`, skip)
  263. that.search();
  264. uni.hideLoading();
  265. } else that.$set(that, `is_bottom`, true)
  266. },
  267. toScroll(e) {
  268. const that = this;
  269. let up = that.scrollTop;
  270. that.$set(that, `scrollTop`, e.detail.scrollTop);
  271. let num = Math.sign(up - e.detail.scrollTop);
  272. if (num == 1) that.$set(that, `is_bottom`, false);
  273. },
  274. // 清空列表
  275. clearPage() {
  276. const that = this;
  277. that.$set(that, `list`, [])
  278. that.$set(that, `skip`, 0)
  279. that.$set(that, `limit`, 6)
  280. that.$set(that, `page`, 0)
  281. }
  282. }
  283. }
  284. </script>
  285. <style lang="scss" scoped>
  286. .main {
  287. display: flex;
  288. flex-direction: column;
  289. width: 100vw;
  290. height: 100vh;
  291. .one {
  292. display: flex;
  293. justify-content: center;
  294. align-items: center;
  295. padding: 2vw;
  296. background-color: var(--mainColor);
  297. .one_1 {
  298. padding: 0 2vw;
  299. width: 75vw;
  300. input {
  301. padding: 2vw;
  302. background-color: var(--f1Color);
  303. font-size: var(--font14Size);
  304. border-radius: 5px;
  305. }
  306. }
  307. .one_2 {
  308. .button {
  309. background-color: var(--f3CColor);
  310. color: var(--mainColor);
  311. }
  312. }
  313. }
  314. .two {
  315. background-color: var(--f9Color);
  316. margin: 2vw 0 0 0;
  317. .tabsList {
  318. position: relative;
  319. width: 100vw;
  320. height: 81vh;
  321. .list {
  322. background-color: var(--mainColor);
  323. padding: 2vw;
  324. margin: 2vw 2vw 0 2vw;
  325. border-radius: 10px;
  326. .list_1 {
  327. .image {
  328. height: 50vw;
  329. width: 100%;
  330. border-radius: 5px;
  331. }
  332. }
  333. .list_2 {
  334. margin: 1vw 0;
  335. font-weight: bold;
  336. font-size: var(--font16Size);
  337. }
  338. .list_3 {
  339. display: flex;
  340. align-items: center;
  341. justify-content: space-between;
  342. font-size: var(--font14Size);
  343. .list_left {
  344. display: flex;
  345. align-items: center;
  346. color: var(--f69Color);
  347. span {
  348. margin: 0 0 0 0.5vw;
  349. }
  350. .t-icon {
  351. width: var(--font14Size) !important;
  352. height: var(--font14Size) !important;
  353. }
  354. }
  355. .list_right {
  356. border-radius: 3px;
  357. padding: 0 1vw;
  358. color: var(--mainColor);
  359. }
  360. .active_1 {
  361. background: linear-gradient(to right, #4caf50, #a8f3b2);
  362. }
  363. .active_2 {
  364. background: linear-gradient(to right, #2196f3, #a2ccec);
  365. }
  366. .active_3 {
  367. background: linear-gradient(to right, #FF5722, #FF9800);
  368. }
  369. .active_4 {
  370. background: linear-gradient(to right, #949698, #c6c9cc);
  371. }
  372. }
  373. .list_4 {
  374. display: flex;
  375. justify-content: center;
  376. margin: 2vw 0 0 0;
  377. text-align: center;
  378. .warning {
  379. font-size: 16px;
  380. width: 140px;
  381. height: 35px;
  382. line-height: 35px;
  383. background: linear-gradient(to right, #39D5FF, #868bff);
  384. }
  385. .danger {
  386. background: var(--fF0Color);
  387. }
  388. button {
  389. margin: 0 2vw 0 0;
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. .scroll-view {
  397. position: absolute;
  398. top: 0;
  399. left: 0;
  400. right: 0;
  401. bottom: 0;
  402. .list-scroll-view {
  403. display: flex;
  404. flex-direction: column;
  405. }
  406. }
  407. .is_bottom {
  408. width: 100%;
  409. text-align: center;
  410. text {
  411. padding: 2vw 0;
  412. display: inline-block;
  413. color: var(--f85Color);
  414. font-size: var(--font14Size);
  415. }
  416. }
  417. </style>