index.vue 9.8 KB

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