index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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'&&item.form!='4'">分数列表</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 if (item.form == '4') {
  168. uni.navigateTo({
  169. url: `/pagesMy/match/preliminary?id=${item.id||item._id}`
  170. })
  171. } else {
  172. uni.navigateTo({
  173. url: `/pagesMy/match/sign?id=${item.id||item._id}`
  174. })
  175. }
  176. },
  177. // 分数列表
  178. toScore(item) {
  179. uni.navigateTo({
  180. url: `/pagesMy/match/score?id=${item.id||item._id}`
  181. })
  182. },
  183. // 输入框
  184. toInput() {
  185. const that = this;
  186. if (!that.searchInfo?.name) that.$set(that, `searchInfo`, {})
  187. that.clearPage();
  188. that.search();
  189. },
  190. // 处理时间
  191. getTime(start_time, end_time) {
  192. if (start_time && end_time) {
  193. const start = new Date(start_time);
  194. const end = new Date(end_time);
  195. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  196. const day = start.getDate();
  197. const weekday = weekdays[start.getDay()];
  198. const year = start.getFullYear();
  199. const month = start.getMonth();
  200. const start_hours = start.getHours();
  201. const start_minutes = start.getMinutes();
  202. const end_hours = end.getHours();
  203. const end_minutes = end.getMinutes();
  204. return `${year}/${month+1}/${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')} `;
  205. }
  206. },
  207. // 处理字典表
  208. getDict(item, model) {
  209. const that = this;
  210. let res
  211. if (model == 'status') res = that.statusList.find(i => i.value == item)
  212. else if (model == 'type') res = that.typeList.find(i => i.value == item)
  213. if (res) return res.label
  214. else return '暂无'
  215. },
  216. async searchOther() {
  217. const that = this;
  218. let res;
  219. //状态
  220. res = await that.$api('/dictData', 'GET', {
  221. code: 'examStatus',
  222. is_use: '0'
  223. })
  224. if (res.errcode == '0') {
  225. const menu = res.data.map((item) => {
  226. if (item.value != '-2') {
  227. return {
  228. title: item.label,
  229. active: item.value
  230. }
  231. }
  232. })
  233. that.$set(that.tabs, `menu`, menu)
  234. }
  235. // 查询状态
  236. res = await that.$api(`/dictData`, 'GET', {
  237. code: 'matchStatus',
  238. is_use: '0',
  239. })
  240. if (res.errcode == '0') that.$set(that, `statusList`, res.data)
  241. // 赛事类型
  242. res = await that.$api(`/dictData`, 'GET', {
  243. code: 'activeType',
  244. is_use: '0',
  245. })
  246. if (res.errcode == '0') that.$set(that, `typeList`, res.data)
  247. },
  248. // 图片处理
  249. getUrl(e) {
  250. const that = this;
  251. if (e && e.length > 0) return that.$config.serverFile + e[0].url
  252. else return '/static/match.png'
  253. },
  254. // 分页
  255. toPage(e) {
  256. const that = this;
  257. let list = that.list;
  258. let limit = that.limit;
  259. if (that.total > list.length) {
  260. uni.showLoading({
  261. title: '加载中',
  262. mask: true
  263. })
  264. let page = that.page + 1;
  265. that.$set(that, `page`, page)
  266. let skip = page * limit;
  267. that.$set(that, `skip`, skip)
  268. that.search();
  269. uni.hideLoading();
  270. } else that.$set(that, `is_bottom`, true)
  271. },
  272. toScroll(e) {
  273. const that = this;
  274. let up = that.scrollTop;
  275. that.$set(that, `scrollTop`, e.detail.scrollTop);
  276. let num = Math.sign(up - e.detail.scrollTop);
  277. if (num == 1) that.$set(that, `is_bottom`, false);
  278. },
  279. // 清空列表
  280. clearPage() {
  281. const that = this;
  282. that.$set(that, `list`, [])
  283. that.$set(that, `skip`, 0)
  284. that.$set(that, `limit`, 6)
  285. that.$set(that, `page`, 0)
  286. }
  287. }
  288. }
  289. </script>
  290. <style lang="scss" scoped>
  291. .main {
  292. display: flex;
  293. flex-direction: column;
  294. width: 100vw;
  295. height: 100vh;
  296. .one {
  297. display: flex;
  298. justify-content: center;
  299. align-items: center;
  300. padding: 2vw;
  301. background-color: var(--mainColor);
  302. .one_1 {
  303. padding: 0 2vw;
  304. width: 75vw;
  305. input {
  306. padding: 2vw;
  307. background-color: var(--f1Color);
  308. font-size: var(--font14Size);
  309. border-radius: 5px;
  310. }
  311. }
  312. .one_2 {
  313. .button {
  314. background-color: var(--f3CColor);
  315. color: var(--mainColor);
  316. }
  317. }
  318. }
  319. .two {
  320. background-color: var(--f9Color);
  321. margin: 2vw 0 0 0;
  322. .tabsList {
  323. position: relative;
  324. width: 100vw;
  325. height: 81vh;
  326. .list {
  327. background-color: var(--mainColor);
  328. padding: 2vw;
  329. margin: 2vw 2vw 0 2vw;
  330. border-radius: 10px;
  331. .list_1 {
  332. .image {
  333. height: 50vw;
  334. width: 100%;
  335. border-radius: 5px;
  336. }
  337. }
  338. .list_2 {
  339. margin: 1vw 0;
  340. font-weight: bold;
  341. font-size: var(--font16Size);
  342. }
  343. .list_3 {
  344. display: flex;
  345. align-items: center;
  346. justify-content: space-between;
  347. font-size: var(--font14Size);
  348. .list_left {
  349. display: flex;
  350. align-items: center;
  351. color: var(--f69Color);
  352. span {
  353. margin: 0 0 0 0.5vw;
  354. }
  355. .t-icon {
  356. width: var(--font14Size) !important;
  357. height: var(--font14Size) !important;
  358. }
  359. }
  360. .list_right {
  361. border-radius: 3px;
  362. padding: 0 1vw;
  363. color: var(--mainColor);
  364. }
  365. .active_1 {
  366. background: linear-gradient(to right, #4caf50, #a8f3b2);
  367. }
  368. .active_2 {
  369. background: linear-gradient(to right, #2196f3, #a2ccec);
  370. }
  371. .active_3 {
  372. background: linear-gradient(to right, #FF5722, #FF9800);
  373. }
  374. .active_4 {
  375. background: linear-gradient(to right, #949698, #c6c9cc);
  376. }
  377. }
  378. .list_4 {
  379. display: flex;
  380. justify-content: center;
  381. margin: 2vw 0 0 0;
  382. text-align: center;
  383. .warning {
  384. font-size: 16px;
  385. width: 140px;
  386. height: 35px;
  387. line-height: 35px;
  388. background: linear-gradient(to right, #39D5FF, #868bff);
  389. }
  390. .danger {
  391. background: var(--fF0Color);
  392. }
  393. button {
  394. margin: 0 2vw 0 0;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. .scroll-view {
  402. position: absolute;
  403. top: 0;
  404. left: 0;
  405. right: 0;
  406. bottom: 0;
  407. .list-scroll-view {
  408. display: flex;
  409. flex-direction: column;
  410. }
  411. }
  412. .is_bottom {
  413. width: 100%;
  414. text-align: center;
  415. text {
  416. padding: 2vw 0;
  417. display: inline-block;
  418. color: var(--f85Color);
  419. font-size: var(--font14Size);
  420. }
  421. }
  422. </style>