index.vue 8.7 KB

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