index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 month = start.getMonth();
  161. const start_hours = start.getHours();
  162. const start_minutes = start.getMinutes();
  163. const end_hours = end.getHours();
  164. const end_minutes = end.getMinutes();
  165. 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')} `;
  166. }
  167. },
  168. // 处理字典表
  169. getDict(item, model) {
  170. const that = this;
  171. let res
  172. if (model == 'status') res = that.statusList.find(i => i.value == item)
  173. else if (model == 'type') res = that.typeList.find(i => i.value == item)
  174. if (res) return res.label
  175. else return '暂无'
  176. },
  177. // 图片处理
  178. getUrl(e) {
  179. const that = this;
  180. if (e && e.length > 0) return that.$config.serverFile + e[0].url
  181. else return '/static/match.png'
  182. },
  183. // 回到顶部
  184. goTop(e) {
  185. const that = this;
  186. that.scrollTop = that.oldScrollTop
  187. that.$nextTick(function() {
  188. that.scrollTop = 0
  189. });
  190. },
  191. // 详情
  192. toView(item) {
  193. uni.navigateTo({
  194. url: `/pagesHome/match/index?id=${item.id||item._id}`
  195. })
  196. },
  197. // 分页
  198. toPage(e) {
  199. const that = this;
  200. let list = that.list;
  201. let limit = that.limit;
  202. if (that.total > list.length) {
  203. uni.showLoading({
  204. title: '加载中',
  205. mask: true
  206. })
  207. let page = that.page + 1;
  208. that.$set(that, `page`, page)
  209. let skip = page * limit;
  210. that.$set(that, `skip`, skip)
  211. that.search();
  212. uni.hideLoading();
  213. } else that.$set(that, `is_bottom`, true)
  214. },
  215. toScroll(e) {
  216. const that = this;
  217. let up = that.scrollTop;
  218. that.$set(that, `oldScrollTop`, e.detail.scrollTop);
  219. let num = Math.sign(up - e.detail.scrollTop);
  220. if (num == 1) that.$set(that, `is_bottom`, false);
  221. // 检查滚动位置是否达到div显示的条件
  222. if (e.detail.scrollTop >= 300 && !that.showDiv) {
  223. that.showDiv = true;
  224. } else if (e.detail.scrollTop < 300 && that.showDiv) {
  225. that.showDiv = false;
  226. }
  227. },
  228. // 清空列表
  229. clearPage() {
  230. const that = this;
  231. that.$set(that, `list`, [])
  232. that.$set(that, `skip`, 0)
  233. that.$set(that, `limit`, 5)
  234. that.$set(that, `page`, 0)
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="scss" scoped>
  240. .main {
  241. .one {
  242. display: flex;
  243. justify-content: center;
  244. align-items: center;
  245. padding: 2vw;
  246. background-color: var(--mainColor);
  247. .one_1 {
  248. padding: 0 2vw;
  249. width: 75vw;
  250. input {
  251. padding: 2vw;
  252. background-color: var(--f1Color);
  253. font-size: var(--font14Size);
  254. border-radius: 5px;
  255. }
  256. }
  257. .one_2 {
  258. .button {
  259. background-color: var(--f3CColor);
  260. color: var(--mainColor);
  261. }
  262. }
  263. }
  264. .two {
  265. position: relative;
  266. flex-grow: 1;
  267. .list {
  268. padding: 2vw 1vw;
  269. margin: 2vw 2vw 0 2vw;
  270. border-radius: 10px;
  271. .list_1 {
  272. .image {
  273. height: 50vw;
  274. width: 100%;
  275. border-radius: 5px;
  276. }
  277. }
  278. .list_2 {
  279. margin: 1vw 0;
  280. font-weight: bold;
  281. font-size: var(--font16Size);
  282. }
  283. .list_3 {
  284. display: flex;
  285. align-items: center;
  286. justify-content: space-between;
  287. font-size: var(--font14Size);
  288. .list_left {
  289. display: flex;
  290. align-items: center;
  291. color: var(--f69Color);
  292. span {
  293. margin: 0 0 0 0.5vw;
  294. }
  295. .t-icon {
  296. width: var(--font14Size) !important;
  297. height: var(--font14Size) !important;
  298. }
  299. }
  300. .list_right {
  301. border-radius: 3px;
  302. padding: 0 1vw;
  303. color: var(--mainColor);
  304. }
  305. .active_1 {
  306. background: linear-gradient(to right, #4caf50, #a8f3b2);
  307. }
  308. .active_2 {
  309. background: linear-gradient(to right, #2196f3, #a2ccec);
  310. }
  311. .active_3 {
  312. background: linear-gradient(to right, #FF5722, #FF9800);
  313. }
  314. .active_4 {
  315. background: linear-gradient(to right, #949698, #c6c9cc);
  316. }
  317. }
  318. }
  319. }
  320. .fixd {
  321. position: fixed;
  322. right: 2vw;
  323. bottom: 5vw;
  324. .t-icon {
  325. width: 40px !important;
  326. height: 40px !important;
  327. }
  328. }
  329. }
  330. .scroll-view {
  331. position: absolute;
  332. top: 0;
  333. left: 0;
  334. right: 0;
  335. bottom: 0;
  336. .list-scroll-view {
  337. display: flex;
  338. flex-direction: column;
  339. }
  340. }
  341. .is_bottom {
  342. width: 100%;
  343. text-align: center;
  344. text {
  345. padding: 2vw 0;
  346. display: inline-block;
  347. color: var(--f85Color);
  348. font-size: var(--font14Size);
  349. }
  350. }
  351. </style>