index.vue 10 KB

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