index.vue 9.1 KB

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