index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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">
  15. <view class="list-scroll-view">
  16. <view class="list" v-for="(item, index) in list" :key="index">
  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-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':item.match_status=='2'?'active_3':'active_4']">
  32. {{getDict(item.match_status,'status')}}
  33. </view>
  34. </view>
  35. <view class="list_4">
  36. <button class="warning" size="mini" type="warn" @tap.stop="toView(item)">查看详情</button>
  37. </view>
  38. </view>
  39. <view class="is_bottom" v-if="is_bottom">
  40. <text>{{config.bottom_title||'到底了!'}}</text>
  41. </view>
  42. </view>
  43. </scroll-view>
  44. </view>
  45. </tabs>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import tabs from '../../components/tabs/index.vue';
  51. export default {
  52. components: {
  53. tabs
  54. },
  55. data() {
  56. return {
  57. searchInfo: {},
  58. config: {},
  59. user: {},
  60. tabs: {
  61. active: '0',
  62. bgColor: '#ffffff',
  63. menu: []
  64. },
  65. list: [],
  66. total: 0,
  67. skip: 0,
  68. limit: 6,
  69. page: 0,
  70. // 数据是否触底
  71. is_bottom: false,
  72. scrollTop: 0,
  73. statusList: []
  74. }
  75. },
  76. onLoad: async function(e) {
  77. const that = this;
  78. that.searchToken();
  79. that.searchConfig();
  80. await that.searchOther();
  81. },
  82. onShow: async function() {
  83. const that = this;
  84. that.clearPage();
  85. await that.search();
  86. },
  87. onPullDownRefresh: async function() {
  88. const that = this;
  89. that.clearPage();
  90. await that.search();
  91. uni.stopPullDownRefresh();
  92. },
  93. methods: {
  94. searchToken() {
  95. const that = this;
  96. try {
  97. const res = uni.getStorageSync('token');
  98. if (res) {
  99. const user = that.$jwt(res);
  100. that.$set(that, `user`, user);
  101. } else {
  102. that.$set(that, `user`, {});
  103. }
  104. } catch (e) {}
  105. },
  106. searchConfig() {
  107. const that = this;
  108. try {
  109. const res = uni.getStorageSync('config');
  110. if (res) that.$set(that, `config`, res);
  111. } catch (e) {
  112. uni.showToast({
  113. title: err.errmsg,
  114. icon: 'error',
  115. duration: 2000
  116. });
  117. }
  118. },
  119. async search() {
  120. const that = this;
  121. let info = {
  122. skip: that.skip,
  123. limit: that.limit,
  124. status: that.tabs.active,
  125. user: that.user.id,
  126. }
  127. const res = await that.$api(`/sign/sign`, 'GET', {
  128. ...info,
  129. ...that.searchInfo
  130. })
  131. if (res.errcode == '0') {
  132. let list = [...that.list, ...res.data];
  133. const matchList = []
  134. for (let val of list) {
  135. matchList.push({
  136. ...val.matchInfo,
  137. signId: val.id
  138. })
  139. }
  140. that.$set(that, `list`, matchList)
  141. that.$set(that, `total`, res.total)
  142. } else {
  143. uni.showToast({
  144. title: res.errmsg,
  145. });
  146. }
  147. },
  148. // 选择选项卡
  149. tabsChange(e) {
  150. const that = this;
  151. that.$set(that.tabs, `active`, e.active)
  152. that.clearPage();
  153. that.search()
  154. },
  155. // 查看详情
  156. toView(item) {
  157. uni.navigateTo({
  158. url: `/pagesMy/activity/detail?id=${item.signId}`
  159. })
  160. },
  161. // 输入框
  162. toInput() {
  163. const that = this;
  164. if (!that.searchInfo?.name) that.$set(that, `searchInfo`, {})
  165. that.clearPage();
  166. that.search();
  167. },
  168. // 处理时间
  169. getTime(start_time, end_time) {
  170. if (start_time && end_time) {
  171. const start = new Date(start_time);
  172. const end = new Date(end_time);
  173. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  174. const day = start.getDate();
  175. const weekday = weekdays[start.getDay()];
  176. const month = start.getMonth();
  177. const start_hours = start.getHours();
  178. const start_minutes = start.getMinutes();
  179. const end_hours = end.getHours();
  180. const end_minutes = end.getMinutes();
  181. 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')} `;
  182. }
  183. },
  184. // 处理字典表
  185. getDict(item, model) {
  186. const that = this;
  187. let res
  188. if (model == 'status') res = that.statusList.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. // 图片处理
  219. getUrl(e) {
  220. const that = this;
  221. if (e && e.length > 0) return that.$config.serverFile + e[0].url
  222. else return '/static/match.png'
  223. },
  224. // 分页
  225. toPage(e) {
  226. const that = this;
  227. let list = that.list;
  228. let limit = that.limit;
  229. if (that.total > list.length) {
  230. uni.showLoading({
  231. title: '加载中',
  232. mask: true
  233. })
  234. let page = that.page + 1;
  235. that.$set(that, `page`, page)
  236. let skip = page * limit;
  237. that.$set(that, `skip`, skip)
  238. that.search();
  239. uni.hideLoading();
  240. } else that.$set(that, `is_bottom`, true)
  241. },
  242. toScroll(e) {
  243. const that = this;
  244. let up = that.scrollTop;
  245. that.$set(that, `scrollTop`, e.detail.scrollTop);
  246. let num = Math.sign(up - e.detail.scrollTop);
  247. if (num == 1) that.$set(that, `is_bottom`, false);
  248. },
  249. // 清空列表
  250. clearPage() {
  251. const that = this;
  252. that.$set(that, `list`, [])
  253. that.$set(that, `skip`, 0)
  254. that.$set(that, `limit`, 6)
  255. that.$set(that, `page`, 0)
  256. }
  257. }
  258. }
  259. </script>
  260. <style lang="scss" scoped>
  261. .main {
  262. display: flex;
  263. flex-direction: column;
  264. width: 100vw;
  265. height: 100vh;
  266. .one {
  267. display: flex;
  268. justify-content: center;
  269. align-items: center;
  270. padding: 2vw;
  271. background-color: var(--mainColor);
  272. .one_1 {
  273. padding: 0 2vw;
  274. width: 75vw;
  275. input {
  276. padding: 2vw;
  277. background-color: var(--f1Color);
  278. font-size: var(--font14Size);
  279. border-radius: 5px;
  280. }
  281. }
  282. .one_2 {
  283. .button {
  284. background-color: var(--f3CColor);
  285. color: var(--mainColor);
  286. }
  287. }
  288. }
  289. .two {
  290. background-color: var(--f9Color);
  291. margin: 2vw 0 0 0;
  292. .tabsList {
  293. position: relative;
  294. width: 100vw;
  295. height: 82vh;
  296. .list {
  297. background-color: var(--mainColor);
  298. padding: 2vw;
  299. margin: 2vw 2vw 0 2vw;
  300. border-radius: 10px;
  301. .list_1 {
  302. .image {
  303. height: 50vw;
  304. width: 100%;
  305. border-radius: 5px;
  306. }
  307. }
  308. .list_2 {
  309. margin: 1vw 0;
  310. font-weight: bold;
  311. font-size: var(--font16Size);
  312. }
  313. .list_3 {
  314. display: flex;
  315. align-items: center;
  316. justify-content: space-between;
  317. font-size: var(--font14Size);
  318. .list_left {
  319. display: flex;
  320. align-items: center;
  321. color: var(--f69Color);
  322. span {
  323. margin: 0 0 0 0.5vw;
  324. }
  325. .t-icon {
  326. width: var(--font14Size) !important;
  327. height: var(--font14Size) !important;
  328. }
  329. }
  330. .list_right {
  331. border-radius: 3px;
  332. padding: 0 1vw;
  333. color: var(--mainColor);
  334. }
  335. .active_1 {
  336. background: linear-gradient(to right, #4caf50, #a8f3b2);
  337. }
  338. .active_2 {
  339. background: linear-gradient(to right, #2196f3, #a2ccec);
  340. }
  341. .active_3 {
  342. background: linear-gradient(to right, #FF5722, #FF9800);
  343. }
  344. .active_4 {
  345. background: linear-gradient(to right, #949698, #c6c9cc);
  346. }
  347. }
  348. .list_4 {
  349. margin: 2vw 0 0 0;
  350. text-align: center;
  351. .warning {
  352. background: var(--f3CColor);
  353. }
  354. .danger {
  355. background: var(--fF0Color);
  356. }
  357. button {
  358. margin: 0 1vw 0 0;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }
  365. .scroll-view {
  366. position: absolute;
  367. top: 0;
  368. left: 0;
  369. right: 0;
  370. bottom: 0;
  371. .list-scroll-view {
  372. display: flex;
  373. flex-direction: column;
  374. }
  375. }
  376. .is_bottom {
  377. width: 100%;
  378. text-align: center;
  379. text {
  380. padding: 2vw 0;
  381. display: inline-block;
  382. color: var(--f85Color);
  383. font-size: var(--font14Size);
  384. }
  385. }
  386. </style>