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