guhongwei 2 years ago
parent
commit
72312fe5f4

+ 2 - 1
app.wxss

@@ -41,7 +41,8 @@ page {
     /* 输入框查询背景颜色 */
     --f1Color: #f1f1f1;
     --f9Color: #f9f9f9;
-
+    --redColor: #ff0000;
+    --whiteColor: #ffffff;
 }
 
 /* @import "/icon/icon.wxss"; */

+ 17 - 21
pages/home/index.js

@@ -19,6 +19,21 @@ Page({
         const { item } = e.currentTarget.dataset;
         wx.navigateTo({ url: `/pages/match/info?id=${item._id}` })
     },
+    // 分页
+    toPage: function () {
+        const that = this;
+        let list = that.data.list;
+        let limit = that.data.limit;
+        if (that.data.total > list.length) {
+            wx.showLoading({ title: '加载中', mask: true })
+            let page = that.data.page + 1;
+            that.setData({ page: page })
+            let skip = page * limit;
+            that.setData({ skip: skip })
+            that.watchLogin();
+            wx.hideLoading()
+        } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
+    },
     /**
      * 生命周期函数--监听页面加载
      */
@@ -44,14 +59,8 @@ Page({
                 let info = { skip: that.data.skip, limit: that.data.limit };
                 const arr = await app.$get(`/newCourt/api/match`, { ...info });
                 if (arr.errcode == '0') {
-                    let arr1 = that.data.list;
-                    let arr2 = arr.data;
-                    arr1 = arr1.concat(arr2);
-                    that.setData({ list: arr1 })
-                }
-                const aee = await app.$get(`/newCourt/api/match`);
-                if (aee.errcode == '0') {
-                    that.setData({ total: aee.data.length })
+                    that.setData({ list: [...that.data.list, ...arr.data] });
+                    that.setData({ total: arr.total })
                 }
                 else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
             },
@@ -63,19 +72,6 @@ Page({
     /**
      * 页面上拉触底事件的处理函数
      */
-    onReachBottom: function () {
-        const that = this;
-        if (that.data.total > that.data.list.length) {
-            wx.showLoading({ title: '加载中', mask: true })
-            let page = that.data.page + 1; //获取当前页数并+1
-            that.setData({ page: page })//更新当前页数
-            let limit = that.data.limit;
-            let skip = page * limit;
-            that.setData({ skip: skip })
-            that.watchLogin();
-            wx.hideLoading()
-        } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
-    },
     /**
      * 生命周期函数--监听页面隐藏
      */

+ 14 - 7
pages/home/index.less

@@ -46,19 +46,16 @@
             flex-direction: row;
 
             .list_1 {
-                width: 30vw;
-                padding: 8vw 0 0 0;
-                text-align: center;
-
+                width: 25vw;
                 .image {
                     width: 100%;
-                    height: 14vw;
-                    border-radius: 10px;
-                    border: 1px solid #cccccc;
+                    height: 12vh;
+                    border: 1px solid var(--f1Color);
                 }
             }
 
             .list_2 {
+                width: 65vw;
                 flex-grow: 1;
                 padding: 0 0 0 2vw;
 
@@ -73,6 +70,16 @@
                     word-break: break-all;
                     display: -webkit-box;
                     -webkit-box-orient: vertical;
+
+                    .status {
+                        display: inline-block;
+                        background-color: var(--redColor);
+                        color: var(--whiteColor);
+                        padding: 0.5vw 1vw;
+                        margin: 0 1vw 0 0;
+                        font-size: var(--btnSize);
+                        border-radius: 5px;
+                    }
                 }
 
                 .other {

+ 1 - 1
pages/home/index.wxml

@@ -9,7 +9,7 @@
             </view>
         </view>
         <view class="two">
-            <scroll-view scroll-y="true" class="scroll-view" bindscrolltolower="onReachBottom">
+            <scroll-view scroll-y="true" class="scroll-view" bindscrolltolower="toPage">
                 <view class="list-scroll-view">
                     <view class="list" wx:for="{{list}}" wx:key="item" bindtap="toView" data-item="{{item}}">
                         <view class="list_1">

+ 13 - 6
pages/home/index.wxss

@@ -41,17 +41,15 @@
   flex-direction: row;
 }
 .main .two .list .list_1 {
-  width: 30vw;
-  padding: 8vw 0 0 0;
-  text-align: center;
+  width: 25vw;
 }
 .main .two .list .list_1 .image {
   width: 100%;
-  height: 14vw;
-  border-radius: 10px;
-  border: 1px solid #cccccc;
+  height: 12vh;
+  border: 1px solid var(--f1Color);
 }
 .main .two .list .list_2 {
+  width: 65vw;
   flex-grow: 1;
   padding: 0 0 0 2vw;
 }
@@ -67,6 +65,15 @@
   display: -webkit-box;
   -webkit-box-orient: vertical;
 }
+.main .two .list .list_2 .name .status {
+  display: inline-block;
+  background-color: var(--redColor);
+  color: var(--whiteColor);
+  padding: 0.5vw 1vw;
+  margin: 0 1vw 0 0;
+  font-size: var(--btnSize);
+  border-radius: 5px;
+}
 .main .two .list .list_2 .other {
   margin: 0 0 1vw 0;
 }

+ 38 - 29
pages/news/index.js

@@ -10,33 +10,11 @@ Page({
                 { title: '羽毛球', name: '1' },
             ],
         },
-        list: [
-            {
-                _id:'1',
-                name: '1212',
-                home_url: [{ url: '/image/lingdang.png' }]
-            },
-            {
-                name: '1212',
-                home_url: [{ url: '/image/lingdang.png' }]
-            },
-            {
-                name: '1212',
-                home_url: [{ url: '/image/lingdang.png' }]
-            },
-            {
-                name: '1212',
-                home_url: [{ url: '/image/lingdang.png' }]
-            },
-            {
-                name: '1212',
-                home_url: [{ url: '/image/lingdang.png' }]
-            },
-            {
-                name: '1212',
-                home_url: [{ url: '/image/lingdang.png' }]
-            },
-        ],
+        list: [],
+        page: 0,
+        skip: 0,
+        limit: 5,
+        total: 0,
         typeList: news_type,
     },
     // 跳转菜单
@@ -48,26 +26,57 @@ Page({
     tabsChange: function (e) {
         const that = this;
         that.setData({ 'tabs.active': e.detail.name });
+        that.setData({ skip: 0 })
+        that.setData({ page: 0 })
+        that.setData({ list: [] })
+        that.watchLogin()
     },
     // 详情
     toView: function (e) {
+        const that = this;
+        that.setData({ skip: 0 })
+        that.setData({ page: 0 })
+        that.setData({ list: [] })
         const { item } = e.currentTarget.dataset;
         wx.navigateTo({ url: `/pages/news/info?id=${item._id}` })
     },
+    // 分页
+    toPage: function () {
+        const that = this;
+        let list = that.data.list;
+        let limit = that.data.limit;
+        if (that.data.total > list.length) {
+            wx.showLoading({ title: '加载中', mask: true })
+            let page = that.data.page + 1;
+            that.setData({ page: page })
+            let skip = page * limit;
+            that.setData({ skip: skip })
+            that.watchLogin();
+            wx.hideLoading()
+        } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
+    },
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) { },
     // 监听用户是否登录
     watchLogin: async function () {
+        const that = this;
+        let type = that.data.tabs.active;
         // 监听用户是否登录,
         wx.getStorage({
             key: 'user',
             success: async res => {
-                // if (res.data) wx.redirectTo({ url: '/pages/home/index' })
+                let info = { skip: that.data.skip, limit: that.data.limit, type: type };
+                const arr = await app.$get(`/newCourt/api/news`, { ...info });
+                if (arr.errcode == '0') {
+                    that.setData({ list: [...that.data.list, ...arr.data] });
+                    that.setData({ total: arr.total })
+                }
+                else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
             },
             fail: async res => {
-                // wx.redirectTo({ url: '/pages/index/index' })
+                wx.redirectTo({ url: '/pages/index/index' })
             }
         })
     },

+ 2 - 2
pages/news/index.wxml

@@ -9,7 +9,7 @@
                     <input type="text" placeholder="请输入关键词" />
                 </view>
                 <view class="a_2">
-                    <scroll-view scroll-y="true" class="scroll-view">
+                    <scroll-view scroll-y="true" class="scroll-view" bindscrolltolower="toPage">
                         <view class="list-scroll-view">
                             <view class="list" wx:for="{{list}}" wx:key="item" bindtap="toView" data-item="{{item._id}}">
                                 <view class="list_1">
@@ -33,7 +33,7 @@
                     <input type="text" placeholder="请输入关键词" />
                 </view>
                 <view class="a_2">
-                    <scroll-view scroll-y="true" class="scroll-view">
+                    <scroll-view scroll-y="true" class="scroll-view" bindscrolltolower="toPage">
                         <view class="list-scroll-view">
                             <view class="list" wx:for="{{list}}" wx:key="item" bindtap="toView" data-item="{{item._id}}">
                                 <view class="list_1">

+ 6 - 7
pages/project/add.js

@@ -8,11 +8,11 @@ Page({
      */
     data: {
         frameStyle: { useTop: true, name: '添加项目', leftArrow: true, useBar: false },
+        id: '',
         form: {},
         //比赛类型
         typeList: match_project,
-        // 用户id
-        id: ''
+
     },
     initValidate() {
         const rules = { name: { required: true }, type: { required: true }, explain: { required: true }, num: { required: true, digits: true } }
@@ -35,7 +35,6 @@ Page({
     onSubmit: async function (e) {
         const that = this;
         const params = e.detail.value;
-        params.num = parseFloat(params.num);
         const data = that.data.form;
         if (!this.WxValidate.checkForm(params)) {
             const error = this.WxValidate.errorList[0];
@@ -59,7 +58,7 @@ Page({
      */
     onLoad: function (options) {
         const that = this;
-        if (options && options.id) that.setData({ id: options.id })
+        that.setData({ id: options.id || '' })
         //验证规则函数
         that.initValidate();
         // 监听用户是否登录
@@ -71,9 +70,9 @@ Page({
         wx.getStorage({
             key: 'user',
             success: async res => {
-                const arr = await app.$get(`/newCourt/api/matchProject/${that.data.id}`);
-                if (arr.errcode == '0') {
-                    that.setData({ form: arr.data });
+                if (that.data.id) {
+                    const arr = await app.$get(`/newCourt/api/matchProject/${that.data.id}`);
+                    if (arr.errcode == '0') { that.setData({ form: arr.data }); }
                 }
             },
             fail: res => {

+ 1 - 1
pages/project/add.wxml

@@ -20,7 +20,7 @@
                 </view>
                 <view class="content">
                     <view class="label">比赛人数:</view>
-                    <view class="value"><input type="digit" name="num" value="{{form.num}}" placeholder="请输入比赛人数" /></view>
+                    <view class="value"><input type="number" name="num" value="{{form.num}}" placeholder="请输入比赛人数" /></view>
                 </view>
                 <view class="btn">
                     <button type="primary" size="mini" formType="submit">提交保存</button>

+ 13 - 9
pages/project/list.js

@@ -2,7 +2,6 @@ const app = getApp()
 Page({
     data: {
         frameStyle: { useTop: true, name: '比赛项目', leftArrow: true, useBar: false },
-        oldList: [],
         list: [],
         total: 0,
         limit: 5,
@@ -53,13 +52,19 @@ Page({
             }
         })
     },
-    upcroll: function () {
+    toPage: function () {
         const that = this;
-        let page = that.data.page + 1;
-        that.setData({ page })
-        const skip = page * that.data.limit;
-        that.setData({ skip });
-        that.watchLogin()
+        let list = that.data.list;
+        let limit = that.data.limit;
+        if (that.data.total > list.length) {
+            wx.showLoading({ title: '加载中', mask: true })
+            let page = that.data.page + 1;
+            that.setData({ page: page })
+            let skip = page * limit;
+            that.setData({ skip: skip })
+            that.watchLogin();
+            wx.hideLoading()
+        } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
     },
     /**
      * 生命周期函数--监听页面加载
@@ -77,8 +82,7 @@ Page({
                 let arr;
                 arr = await app.$get(`/newCourt/api/matchProject`, { ...info });
                 if (arr.errcode == '0') {
-                    if (arr.data && arr.data.length > 0) that.setData({ list: [...that.data.list, ...arr.data] })
-                    else wx.showToast({ title: `没有更多数据`, icon: 'success', duration: 2000 })
+                    that.setData({ list: [...that.data.list, ...arr.data] })
                     that.setData({ total: arr.total })
                 }
                 else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }

+ 1 - 1
pages/project/list.wxml

@@ -9,7 +9,7 @@
             </view>
         </view>
         <view class="two">
-            <scroll-view scroll-y="true" class="scroll-view" bindscrolltolower="upcroll">
+            <scroll-view scroll-y="true" class="scroll-view" bindscrolltolower="toPage">
                 <view class="list-scroll-view">
                     <view class="list" wx:for="{{list}}" wx:key="item">
                         <view class="name">{{item.name||'暂无'}}</view>

+ 16 - 16
pages/topic/index.js

@@ -2,36 +2,36 @@ const app = getApp()
 Page({
     data: {
         frameStyle: { useTop: true, name: '话题', leftArrow: false, useBar: true },
-        searchInfo: {},
         list: [],
         //分页
         skip: 0,
         page: 0,
         limit: 5,
+        total: 0
     },
     // 跳转菜单
     tabPath(e) {
         let { route } = e.detail.detail;
         if (route) wx.redirectTo({ url: `/${route}` })
     },
-    toJoin(e) {
-        let { id } = e.currentTarget.dataset;
-        wx.navigateTo({ url: `/pages/topic/info?id=${id}` })
-    },
-    // 查询
-    search: function (e) {
-        const that = this;
-        that.setData({ 'searchInfo.title': e.detail.value });
-        that.watchLogin()
+    toView: function (e) {
+        let { item } = e.currentTarget.dataset;
+        wx.navigateTo({ url: `/pages/topic/info?id=${item._id}` })
     },
     //分页
     toPage: function () {
         const that = this;
-        let page = that.data.page + 1;
-        that.setData({ page })
-        let skip = page * that.data.limit;
-        that.setData({ skip })
-        that.watchLogin();
+        let list = that.data.list;
+        let limit = that.data.limit;
+        if (that.data.total > list.length) {
+            wx.showLoading({ title: '加载中', mask: true })
+            let page = that.data.page + 1;
+            that.setData({ page: page })
+            let skip = page * limit;
+            that.setData({ skip: skip })
+            that.watchLogin();
+            wx.hideLoading()
+        } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
     },
     /**
      * 生命周期函数--监听页面加载
@@ -47,7 +47,7 @@ Page({
                 let info = { skip: that.data.skip, limit: that.data.limit };
                 if (searchInfo && searchInfo.title) info.title = searchInfo.title;
                 const arr = await app.$get(`/newCourt/api/topic`, { ...info });
-                if (arr.errcode == '0') { that.setData({ list: [...that.data.list, ...arr.data] }) }
+                if (arr.errcode == '0') { that.setData({ list: [...that.data.list, ...arr.data] }); that.setData({ total: arr.total }); }
                 else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
             },
             fail: async (res) => {

+ 3 - 3
pages/topic/index.wxml

@@ -1,12 +1,12 @@
 <mobile-main frameStyle="{{frameStyle}}" bind:tabPath="tabPath">
     <view slot="info" class="container main">
         <view class="one">
-            <input type="text" value="{{searchInfo.title}}" bindconfirm="search" placeholder="请输入话题名称" />
+            <input type="text" placeholder="请输入关键词" />
         </view>
         <view class="two">
             <scroll-view scroll-y="true" class="scroll-view" bindscrolltolower="toPage">
                 <view class="list-scroll-view">
-                    <view class="list" wx:for="{{list}}" wx:key="item" data-id="{{item._id}}">
+                    <view class="list" wx:for="{{list}}" wx:key="item">
                         <view class="list_1">
                             <view class="name textOver">{{item.title}}</view>
                             <view>{{item.create_time}}</view>
@@ -14,7 +14,7 @@
                         <view class="list_2">{{item.brief}}</view>
                         <view class="list_3">
                             <view>已发布{{item.stick.length||0}}个帖子</view>
-                            <view class="btn" bindtap="toJoin">加入话题>>></view>
+                            <view class="btn" bindtap="toJoin" data-item="{{item}}">加入话题>>></view>
                         </view>
                     </view>
                 </view>