index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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" v-if="total>0">
  15. <view class="list-scroll-view">
  16. <view class="list" v-for="(item, index) in list" :key="index" @tap.stop="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-gonglve"></text>
  28. <span>{{getDict(item.match_type,'type')||'自办'}}</span>
  29. </view>
  30. <view class="list_right"
  31. :class="[item.match_status=='0'?'active_1':item.match_status=='1'?'active_2':item.match_status=='2'?'active_3':'active_4']">
  32. {{getDict(item.match_status,'status')}}
  33. </view>
  34. </view>
  35. </view>
  36. <view class="is_bottom" v-if="is_bottom">
  37. <text>{{config.bottom_title||'到底了!'}}</text>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. <o-empty v-else />
  42. </view>
  43. </tabs>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import tabs from '../../components/tabs/index.vue';
  49. export default {
  50. components: {
  51. tabs
  52. },
  53. data() {
  54. return {
  55. searchInfo: {},
  56. config: {},
  57. user: {},
  58. tabs: {
  59. active: '0',
  60. bgColor: '#ffffff',
  61. menu: []
  62. },
  63. list: [],
  64. total: 0,
  65. skip: 0,
  66. limit: 6,
  67. page: 0,
  68. // 数据是否触底
  69. is_bottom: false,
  70. scrollTop: 0,
  71. statusList: [],
  72. typeList: []
  73. }
  74. },
  75. onLoad: async function(e) {
  76. const that = this;
  77. that.searchToken();
  78. that.searchConfig();
  79. await that.searchOther();
  80. },
  81. onShow: async function() {
  82. const that = this;
  83. that.clearPage();
  84. await that.search();
  85. },
  86. onPullDownRefresh: async function() {
  87. const that = this;
  88. that.clearPage();
  89. await that.search();
  90. uni.stopPullDownRefresh();
  91. },
  92. methods: {
  93. searchToken() {
  94. const that = this;
  95. try {
  96. const res = uni.getStorageSync('token');
  97. if (res) {
  98. const user = that.$jwt(res);
  99. that.$set(that, `user`, user);
  100. } else {
  101. that.$set(that, `user`, {});
  102. }
  103. } catch (e) {}
  104. },
  105. searchConfig() {
  106. const that = this;
  107. try {
  108. const res = uni.getStorageSync('config');
  109. if (res) that.$set(that, `config`, res);
  110. } catch (e) {
  111. uni.showToast({
  112. title: err.errmsg,
  113. icon: 'error',
  114. duration: 2000
  115. });
  116. }
  117. },
  118. async search() {
  119. const that = this;
  120. let info = {
  121. skip: that.skip,
  122. limit: that.limit,
  123. status: that.tabs.active,
  124. user: that.user.id,
  125. }
  126. const res = await that.$api(`/sign/sign`, 'GET', {
  127. ...info,
  128. ...that.searchInfo
  129. })
  130. if (res.errcode == '0') {
  131. let list = [...that.list, ...res.data];
  132. const matchList = []
  133. for (let val of list) {
  134. matchList.push({
  135. ...val.matchInfo,
  136. signId: val.id
  137. })
  138. }
  139. that.$set(that, `list`, matchList)
  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: `/pagesMy/activity/detail?id=${item.signId}`
  158. })
  159. },
  160. // 输入框
  161. toInput() {
  162. const that = this;
  163. if (!that.searchInfo?.name) that.$set(that, `searchInfo`, {})
  164. that.clearPage();
  165. that.search();
  166. },
  167. // 处理时间
  168. getTime(start_time, end_time) {
  169. if (start_time && end_time) {
  170. const start = new Date(start_time);
  171. const end = new Date(end_time);
  172. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  173. const day = start.getDate();
  174. const weekday = weekdays[start.getDay()];
  175. const month = start.getMonth();
  176. const start_hours = start.getHours();
  177. const start_minutes = start.getMinutes();
  178. const end_hours = end.getHours();
  179. const end_minutes = end.getMinutes();
  180. 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')} `;
  181. }
  182. },
  183. // 处理字典表
  184. getDict(item, model) {
  185. const that = this;
  186. let res
  187. if (model == 'status') res = that.statusList.find(i => i.value == item)
  188. else if (model == 'type') res = that.typeList.find(i => i.value == item)
  189. if (res) return res.label
  190. else return '暂无'
  191. },
  192. async searchOther() {
  193. const that = this;
  194. let res;
  195. //状态
  196. res = await that.$api('/dictData', 'GET', {
  197. code: 'examStatus',
  198. is_use: '0'
  199. })
  200. if (res.errcode == '0') {
  201. const menu = res.data.map((item) => {
  202. if (item.value != '-2') {
  203. return {
  204. title: item.label,
  205. active: item.value
  206. }
  207. }
  208. })
  209. that.$set(that.tabs, `menu`, menu)
  210. }
  211. // 查询状态
  212. res = await that.$api(`/dictData`, 'GET', {
  213. code: 'matchStatus',
  214. is_use: '0',
  215. })
  216. if (res.errcode == '0') that.$set(that, `statusList`, res.data)
  217. // 赛事类型
  218. res = await that.$api(`/dictData`, 'GET', {
  219. code: 'activeType',
  220. is_use: '0',
  221. })
  222. if (res.errcode == '0') that.$set(that, `typeList`, 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: 90vh;
  302. .list {
  303. background-color: var(--mainColor);
  304. padding: 2vw;
  305. margin: 2vw 2vw 0 2vw;
  306. border-radius: 10px;
  307. .list_1 {
  308. .image {
  309. height: 50vw;
  310. width: 100%;
  311. border-radius: 5px;
  312. }
  313. }
  314. .list_2 {
  315. margin: 1vw 0;
  316. font-weight: bold;
  317. font-size: var(--font16Size);
  318. }
  319. .list_3 {
  320. display: flex;
  321. align-items: center;
  322. justify-content: space-between;
  323. font-size: var(--font14Size);
  324. .list_left {
  325. display: flex;
  326. align-items: center;
  327. color: var(--f69Color);
  328. span {
  329. margin: 0 0 0 0.5vw;
  330. }
  331. .t-icon {
  332. width: var(--font14Size) !important;
  333. height: var(--font14Size) !important;
  334. }
  335. }
  336. .list_right {
  337. border-radius: 3px;
  338. padding: 0 1vw;
  339. color: var(--mainColor);
  340. }
  341. .active_1 {
  342. background: linear-gradient(to right, #4caf50, #a8f3b2);
  343. }
  344. .active_2 {
  345. background: linear-gradient(to right, #2196f3, #a2ccec);
  346. }
  347. .active_3 {
  348. background: linear-gradient(to right, #FF5722, #FF9800);
  349. }
  350. .active_4 {
  351. background: linear-gradient(to right, #949698, #c6c9cc);
  352. }
  353. }
  354. .list_4 {
  355. margin: 2vw 0 0 0;
  356. text-align: center;
  357. .warning {
  358. background: var(--f3CColor);
  359. }
  360. .danger {
  361. background: var(--fF0Color);
  362. }
  363. button {
  364. margin: 0 1vw 0 0;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. }
  371. .scroll-view {
  372. position: absolute;
  373. top: 0;
  374. left: 0;
  375. right: 0;
  376. bottom: 0;
  377. .list-scroll-view {
  378. display: flex;
  379. flex-direction: column;
  380. }
  381. }
  382. .is_bottom {
  383. width: 100%;
  384. text-align: center;
  385. text {
  386. padding: 2vw 0;
  387. display: inline-block;
  388. color: var(--f85Color);
  389. font-size: var(--font14Size);
  390. }
  391. }
  392. </style>