index.vue 8.4 KB

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