123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- <template>
- <view class="container main">
- <view class="one">
- <view class="one_1">
- <input type="text" v-model="searchInfo.name" placeholder="请输入活动名称">
- </view>
- <view class="one_2">
- <button size="mini" class="button" type="primary" @click="toInput">搜索</button>
- </view>
- </view>
- <view class="two" v-if="total>0">
- <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-view" @scrolltolower="toPage"
- @scroll="toScroll">
- <view class="list-scroll-view">
- <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
- <view class="list_1">
- <image class="image" :src="getUrl(item.file)"></image>
- </view>
- <view class="list_2 textOne">{{item.name||'暂无比赛名称'}}</view>
- <view class="list_3">
- <view class="list_left">
- <text class="t-icon t-icon-shizhong"></text>
- <span>{{getTime(item.start_time,item.end_time)||'暂无'}}</span>
- </view>
- <view class="list_left">
- <text class="t-icon t-icon-gonglve"></text>
- <span>{{getDict(item.match_type,'type')||'自办'}}</span>
- </view>
- <view class="list_right"
- :class="[item.match_status=='0'?'active_1':item.match_status=='1'?'active_2':item.match_status=='2'?'active_3':'active_4']">
- {{getDict(item.match_status,'status')}}
- </view>
- </view>
- </view>
- <view class="is_bottom" v-if="is_bottom">
- <text>{{config.bottom_title||'到底了!'}}</text>
- </view>
- </view>
- </scroll-view>
- </view>
- <o-empty v-else />
- <view class="fixd" @tap="goTop" v-if="showDiv">
- <text class="t-icon t-icon-fanhuidingbu"></text>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- user: {},
- config: {},
- searchInfo: {},
- list: [],
- total: 0,
- skip: 0,
- limit: 5,
- page: 0,
- // 数据是否触底
- is_bottom: false,
- scrollTop: 0,
- oldScrollTop: 0,
- showDiv: false,
- // 字典表
- statusList: [],
- typeList: []
- }
- },
- onLoad: async function(e) {
- const that = this;
- await that.searchToken();
- await that.searchConfig();
- await that.searchOther();
- },
- onShow: async function() {
- const that = this;
- that.clearPage();
- await that.search();
- },
- onPullDownRefresh: async function() {
- const that = this;
- that.clearPage();
- await that.search();
- uni.stopPullDownRefresh();
- },
- methods: {
- // 用户信息
- searchToken() {
- const that = this;
- try {
- const res = uni.getStorageSync('token');
- if (res) {
- const user = that.$jwt(res);
- that.$set(that, `user`, user);
- }
- } catch (e) {}
- },
- searchConfig() {
- const that = this;
- try {
- const res = uni.getStorageSync('config');
- if (res) that.$set(that, `config`, res);
- } catch (e) {}
- },
- async searchOther() {
- const that = this;
- let res;
- // 查询状态
- res = await that.$api(`/dictData`, 'GET', {
- code: 'matchStatus',
- is_use: '0',
- })
- if (res.errcode == '0') that.$set(that, `statusList`, res.data)
- // 赛事类型
- res = await that.$api(`/dictData`, 'GET', {
- code: 'activeType',
- is_use: '0',
- })
- if (res.errcode == '0') that.$set(that, `typeList`, res.data)
- },
- // 查询
- async search() {
- const that = this;
- let info = {
- skip: that.skip,
- limit: that.limit,
- is_use: '0',
- status: '1'
- }
- const res = await that.$api(`/match`, 'GET', {
- ...info,
- ...that.searchInfo
- })
- if (res.errcode == '0') {
- let list = [...that.list, ...res.data];
- that.$set(that, `list`, list)
- that.$set(that, `total`, res.total)
- } else {
- uni.showToast({
- title: res.errmsg,
- icon: 'none'
- });
- }
- },
- // 输入框
- toInput() {
- const that = this;
- if (!that.searchInfo.name) that.$set(that, `searchInfo`, {})
- that.clearPage();
- that.search();
- },
- // 处理时间
- getTime(start_time, end_time) {
- if (start_time && end_time) {
- const start = new Date(start_time);
- const end = new Date(end_time);
- const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
- const day = start.getDate();
- const weekday = weekdays[start.getDay()];
- const month = start.getMonth();
- const start_hours = start.getHours();
- const start_minutes = start.getMinutes();
- const end_hours = end.getHours();
- const end_minutes = end.getMinutes();
- 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')} `;
- }
- },
- // 处理字典表
- getDict(item, model) {
- const that = this;
- let res
- if (model == 'status') res = that.statusList.find(i => i.value == item)
- else if (model == 'type') res = that.typeList.find(i => i.value == item)
- if (res) return res.label
- else return '暂无'
- },
- // 图片处理
- getUrl(e) {
- const that = this;
- if (e && e.length > 0) return that.$config.serverFile + e[0].url
- else return '/static/match.png'
- },
- // 回到顶部
- goTop(e) {
- const that = this;
- that.scrollTop = that.oldScrollTop
- that.$nextTick(function() {
- that.scrollTop = 0
- });
- },
- // 详情
- toView(item) {
- uni.navigateTo({
- url: `/pagesHome/match/index?id=${item.id||item._id}`
- })
- },
- // 分页
- toPage(e) {
- const that = this;
- let list = that.list;
- let limit = that.limit;
- if (that.total > list.length) {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- let page = that.page + 1;
- that.$set(that, `page`, page)
- let skip = page * limit;
- that.$set(that, `skip`, skip)
- that.search();
- uni.hideLoading();
- } else that.$set(that, `is_bottom`, true)
- },
- toScroll(e) {
- const that = this;
- let up = that.scrollTop;
- that.$set(that, `oldScrollTop`, e.detail.scrollTop);
- let num = Math.sign(up - e.detail.scrollTop);
- if (num == 1) that.$set(that, `is_bottom`, false);
- // 检查滚动位置是否达到div显示的条件
- if (e.detail.scrollTop >= 300 && !that.showDiv) {
- that.showDiv = true;
- } else if (e.detail.scrollTop < 300 && that.showDiv) {
- that.showDiv = false;
- }
- },
- // 清空列表
- clearPage() {
- const that = this;
- that.$set(that, `list`, [])
- that.$set(that, `skip`, 0)
- that.$set(that, `limit`, 5)
- that.$set(that, `page`, 0)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .main {
- .one {
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 2vw;
- background-color: var(--mainColor);
- .one_1 {
- padding: 0 2vw;
- width: 75vw;
- input {
- padding: 2vw;
- background-color: var(--f1Color);
- font-size: var(--font14Size);
- border-radius: 5px;
- }
- }
- .one_2 {
- .button {
- background-color: var(--f3CColor);
- color: var(--mainColor);
- }
- }
- }
- .two {
- position: relative;
- flex-grow: 1;
- .list {
- padding: 2vw 1vw;
- margin: 2vw 2vw 0 2vw;
- border-radius: 10px;
- .list_1 {
- .image {
- height: 50vw;
- width: 100%;
- border-radius: 5px;
- }
- }
- .list_2 {
- margin: 1vw 0;
- font-weight: bold;
- font-size: var(--font16Size);
- }
- .list_3 {
- display: flex;
- align-items: center;
- justify-content: space-between;
- font-size: var(--font14Size);
- .list_left {
- display: flex;
- align-items: center;
- color: var(--f69Color);
- span {
- margin: 0 0 0 0.5vw;
- }
- .t-icon {
- width: var(--font14Size) !important;
- height: var(--font14Size) !important;
- }
- }
- .list_right {
- border-radius: 3px;
- padding: 0 1vw;
- color: var(--mainColor);
- }
- .active_1 {
- background: linear-gradient(to right, #4caf50, #a8f3b2);
- }
- .active_2 {
- background: linear-gradient(to right, #2196f3, #a2ccec);
- }
- .active_3 {
- background: linear-gradient(to right, #FF5722, #FF9800);
- }
- .active_4 {
- background: linear-gradient(to right, #949698, #c6c9cc);
- }
- }
- }
- }
- .fixd {
- position: fixed;
- right: 2vw;
- bottom: 5vw;
- .t-icon {
- width: 40px !important;
- height: 40px !important;
- }
- }
- }
- .scroll-view {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .list-scroll-view {
- display: flex;
- flex-direction: column;
- }
- }
- .is_bottom {
- width: 100%;
- text-align: center;
- text {
- padding: 2vw 0;
- display: inline-block;
- color: var(--f85Color);
- font-size: var(--font14Size);
- }
- }
- </style>
|