Browse Source

比赛场地管理与比赛项目管理

zs 2 years ago
parent
commit
6737e9df09

+ 17 - 19
pages/address/add.js

@@ -64,25 +64,23 @@ Page({
     // 监听用户是否登录
     watchLogin: async function () {
         const that = this;
-        // 监听用户是否登录,
-        // wx.getStorage({
-        //     key: 'user',
-        //     success: async res => {
-        //         // if (res.data) wx.redirectTo({ url: '/pages/home/index' })
-        //     },
-        //     fail: async res => {
-        //         // wx.redirectTo({ url: '/pages/index/index' })
-        //     }
-        // })
-        // 查询裁判信息
-        let arr;
-        arr = await app.$get(`/newCourt/api/user`, { type: '-1' });
-        if (arr.errcode == '0') { that.setData({ refereeList: arr.data }) }
-        else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
-        if (that.data.id) {
-            arr = await app.$get(`/newCourt/api/ground/${that.data.id}`);
-            if (arr.errcode == '0') { that.setData({ form: arr.data }) }
-        }
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                // 查询裁判信息
+                let arr;
+                arr = await app.$get(`/newCourt/api/user`, { type: '-1' });
+                if (arr.errcode == '0') { that.setData({ refereeList: arr.data }) }
+                else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
+                if (that.data.id) {
+                    arr = await app.$get(`/newCourt/api/ground/${that.data.id}`);
+                    if (arr.errcode == '0') { that.setData({ form: arr.data }) }
+                }
+            },
+            fail: async res => {
+                wx.redirectTo({ url: '/pages/index/index' })
+            }
+        })
     },
     /**
      * 生命周期函数--监听页面初次渲染完成

+ 1 - 1
pages/address/add.less

@@ -1,5 +1,5 @@
 .main {
-    height: 91vh;
+    height: var(--twoHeight);
     background-color: var(--bgColor);
 
     .one {

+ 1 - 1
pages/address/add.wxss

@@ -1,5 +1,5 @@
 .main {
-  height: 91vh;
+  height: var(--twoHeight);
   background-color: var(--bgColor);
 }
 .main .one .content {

+ 33 - 18
pages/address/list.js

@@ -1,7 +1,7 @@
 const app = getApp()
 Page({
     data: {
-        frameStyle: { useTop: true, name: '比赛场地', leftArrow: false, useBar: false },
+        frameStyle: { useTop: true, name: '比赛场地', leftArrow: true, useBar: false },
         oldList: [],
         list: [],
         total: 0,
@@ -9,12 +9,24 @@ Page({
         page: 0,
         skip: 0
     },
+    // 返回
+    back: function () {
+        wx.navigateBack({ delta: 1 })
+    },
     toCommon: function (e) {
+        const that = this;
+        that.setData({ list: [] })
+        that.setData({ skip: 0 })
+        that.setData({ page: 0 })
         const { route } = e.currentTarget.dataset;
         if (route) wx.navigateTo({ url: `/pages/${route}` });
     },
     // 修改
     toEdit: function (e) {
+        const that = this;
+        that.setData({ list: [] })
+        that.setData({ skip: 0 })
+        that.setData({ page: 0 })
         let { item } = e.currentTarget.dataset;
         wx.navigateTo({ url: `/pages/address/add?id=${item._id}` })
     },
@@ -30,6 +42,9 @@ Page({
                     const arr = await app.$delete(`/newCourt/api/ground/${item._id}`);
                     if (arr.errcode == '0') {
                         wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
+                        that.setData({ list: [] })
+                        that.setData({ skip: 0 })
+                        that.setData({ page: 0 })
                         that.watchLogin()
                     } else {
                         wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
@@ -55,23 +70,23 @@ Page({
     // 监听用户是否登录
     watchLogin: async function () {
         const that = this;
-        // 监听用户是否登录,
-        // wx.getStorage({
-        //     key: 'user',
-        //     success: async res => { },
-        //     fail: async res => {
-        //         wx.redirectTo({ url: '/pages/index/index' })
-        //     }
-        // })
-        let info = { skip: that.data.skip, limit: that.data.limit };
-        let arr;
-        arr = await app.$get(`/newCourt/api/ground`, { ...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({ total: arr.total })
-        }
-        else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                let info = { skip: that.data.skip, limit: that.data.limit };
+                let arr;
+                arr = await app.$get(`/newCourt/api/ground`, { ...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({ total: arr.total })
+                }
+                else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
+            },
+            fail: async res => {
+                wx.redirectTo({ url: '/pages/index/index' })
+            }
+        })
     },
     /**
      * 生命周期函数--监听页面初次渲染完成

+ 1 - 1
pages/address/list.wxml

@@ -1,4 +1,4 @@
-<mobile-main frameStyle="{{frameStyle}}">
+<mobile-main frameStyle="{{frameStyle}}" bind:back="back">
     <view slot="info" class="container main">
         <view class="one">
             <view class="one_1">

+ 79 - 13
pages/project/add.js

@@ -1,66 +1,132 @@
-// pages/project/add.js
+const app = getApp()
+import WxValidate from '../../utils/wxValidate'
+import { match_project } from '../../utils/dict';
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
-
+        frameStyle: { useTop: true, name: '添加项目', leftArrow: true, useBar: false },
+        form: {},
+        //比赛类型
+        typeList: match_project,
+        // 用户id
+        id: ''
+    },
+    initValidate() {
+        const rules = { name: { required: true }, type: { required: true }, explain: { required: true }, num: { required: true, digits: true } }
+        // 验证字段的提示信息,若不传则调用默认的信息
+        const messages = { name: { required: '请输入比赛项目名称', }, type: { required: '请选择类型', }, explain: { required: '请输入比赛项目说明', }, num: { required: '请输入比赛人数' } };
+        this.WxValidate = new WxValidate(rules, messages)
+    },
+    // 返回
+    back: function () {
+        wx.navigateBack({ delta: 1 })
+    },
+    // 选择类型
+    typeChange: function (e) {
+        const that = this;
+        let index = e.detail.value;
+        let value = that.data.typeList[index];
+        that.setData({ 'form.type': value.value });
+    },
+    // 提交登录
+    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];
+            wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+            return false
+        } else {
+            let arr;
+            if (data._id) {
+                arr = await app.$post(`/newCourt/api/matchProject/${data._id}`, params);
+                if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
+                else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+            } else {
+                arr = await app.$post(`/newCourt/api/matchProject`, params);
+                if (arr.errcode == '0') { wx.showToast({ title: `添加信息完成`, icon: 'success', duration: 2000 }); that.back(); }
+                else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+            }
+        }
     },
-
     /**
      * 生命周期函数--监听页面加载
      */
-    onLoad(options) {
-
+    onLoad: function (options) {
+        const that = this;
+        if (options && options.id) that.setData({ id: options.id })
+        //验证规则函数
+        that.initValidate();
+        // 监听用户是否登录
+        that.watchLogin();
+    },
+    // 监听用户是否登录
+    watchLogin: async function () {
+        const that = this;
+        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 });
+                }
+            },
+            fail: res => {
+                wx.redirectTo({ url: '/pages/index/index', })
+            }
+        })
     },
-
     /**
      * 生命周期函数--监听页面初次渲染完成
      */
-    onReady() {
+    onReady: function () {
 
     },
 
     /**
      * 生命周期函数--监听页面显示
      */
-    onShow() {
+    onShow: function () {
 
     },
 
     /**
      * 生命周期函数--监听页面隐藏
      */
-    onHide() {
+    onHide: function () {
 
     },
 
     /**
      * 生命周期函数--监听页面卸载
      */
-    onUnload() {
+    onUnload: function () {
 
     },
 
     /**
      * 页面相关事件处理函数--监听用户下拉动作
      */
-    onPullDownRefresh() {
+    onPullDownRefresh: function () {
 
     },
 
     /**
      * 页面上拉触底事件的处理函数
      */
-    onReachBottom() {
+    onReachBottom: function () {
 
     },
 
     /**
      * 用户点击右上角分享
      */
-    onShareAppMessage() {
+    onShareAppMessage: function () {
 
     }
 })

+ 5 - 2
pages/project/add.json

@@ -1,3 +1,6 @@
 {
-    "usingComponents": {}
-}
+    "component": true,
+    "usingComponents": {
+      "mobile-main": "/commpents/mobile-frame/index"
+    }
+  }

+ 37 - 0
pages/project/add.less

@@ -0,0 +1,37 @@
+.main {
+    height: var(--twoHeight);
+    background-color: var(--bgColor);
+
+    .one {
+        .content {
+            display: flex;
+            flex-direction: row;
+            border-bottom: 1px dashed var(--f1Color);
+            padding: 2vw 0;
+            margin: 0 2vw 2vw 2vw;
+
+            .label {
+                color: var(--labelColor);
+            }
+
+            .value {
+                flex-grow: 1;
+                color: var(--txtColor);
+                textarea {
+                    max-width: 220px;
+                }
+            }
+        }
+
+        .btn {
+            text-align: center;
+            margin: 5vw 0 0 0;
+
+            button {
+                width: 40vw;
+                margin: 0 2vw;
+                padding: 1vw 0;
+            }
+        }
+    }
+}

+ 31 - 2
pages/project/add.wxml

@@ -1,2 +1,31 @@
-<!--pages/project/add.wxml-->
-<text>pages/project/add.wxml</text>
+<mobile-main frameStyle="{{frameStyle}}" bind:back="back">
+    <view slot="info" class="container main">
+        <view class="one">
+            <form catchsubmit="onSubmit">
+                <view class="content">
+                    <view class="label">比赛类型:</view>
+                    <view class="value">
+                        <picker name="type" bindchange="typeChange" value="{{form.type}}" range-key='value' range="{{typeList}}">
+                            <view class="input">{{form.type||'选择比赛类型'}}</view>
+                        </picker>
+                    </view>
+                </view>
+                <view class="content">
+                    <view class="label">比赛项目名称:</view>
+                    <view class="value"><input name="name" value="{{form.name}}" placeholder="请输入比赛项目名称" /></view>
+                </view>
+                <view class="content">
+                    <view class="label">比赛项目说明:</view>
+                    <view class="value"><textarea name="explain" value="{{form.explain}}" auto-height placeholder="请输入比赛项目说明"></textarea></view>
+                </view>
+                <view class="content">
+                    <view class="label">比赛人数:</view>
+                    <view class="value"><input type="digit" name="num" value="{{form.num}}" placeholder="请输入比赛人数" /></view>
+                </view>
+                <view class="btn">
+                    <button type="primary" size="mini" formType="submit">提交保存</button>
+                </view>
+            </form>
+        </view>
+    </view>
+</mobile-main>

+ 30 - 1
pages/project/add.wxss

@@ -1 +1,30 @@
-/* pages/project/add.wxss */
+.main {
+  height: var(--twoHeight);
+  background-color: var(--bgColor);
+}
+.main .one .content {
+  display: flex;
+  flex-direction: row;
+  border-bottom: 1px dashed var(--f1Color);
+  padding: 2vw 0;
+  margin: 0 2vw 2vw 2vw;
+}
+.main .one .content .label {
+  color: var(--labelColor);
+}
+.main .one .content .value {
+  flex-grow: 1;
+  color: var(--txtColor);
+}
+.main .one .content .value textarea {
+  max-width: 220px;
+}
+.main .one .btn {
+  text-align: center;
+  margin: 5vw 0 0 0;
+}
+.main .one .btn button {
+  width: 40vw;
+  margin: 0 2vw;
+  padding: 1vw 0;
+}

+ 92 - 17
pages/project/list.js

@@ -1,66 +1,141 @@
-// pages/project/list.js
+const app = getApp()
 Page({
-
-    /**
-     * 页面的初始数据
-     */
     data: {
-
+        frameStyle: { useTop: true, name: '比赛项目', leftArrow: true, useBar: false },
+        oldList: [],
+        list: [],
+        total: 0,
+        limit: 5,
+        page: 0,
+        skip: 0
+    },
+    // 返回
+    back: function () {
+        wx.navigateBack({ delta: 1 })
+    },
+    toCommon: function (e) {
+        const that = this;
+        that.setData({ list: [] })
+        that.setData({ skip: 0 })
+        that.setData({ page: 0 })
+        const { route } = e.currentTarget.dataset;
+        if (route) wx.navigateTo({ url: `/pages/${route}` });
+    },
+    // 修改
+    toEdit: function (e) {
+        const that = this;
+        that.setData({ list: [] })
+        that.setData({ skip: 0 })
+        that.setData({ page: 0 })
+        let { item } = e.currentTarget.dataset;
+        wx.navigateTo({ url: `/pages/project/add?id=${item._id}` })
+    },
+    // 删除
+    toDel: async function (e) {
+        const that = this;
+        const { item } = e.currentTarget.dataset;
+        wx.showModal({
+            title: '提示',
+            content: '是否确认删除该条数据?',
+            async success(res) {
+                if (res.confirm) {
+                    const arr = await app.$delete(`/newCourt/api/matchProject/${item._id}`);
+                    if (arr.errcode == '0') {
+                        wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
+                        that.setData({ list: [] })
+                        that.setData({ skip: 0 })
+                        that.setData({ page: 0 })
+                        that.watchLogin()
+                    } else {
+                        wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
+                    }
+                }
+            }
+        })
+    },
+    upcroll: function () {
+        const that = this;
+        let page = that.data.page + 1;
+        that.setData({ page })
+        const skip = page * that.data.limit;
+        that.setData({ skip });
+        that.watchLogin()
     },
-
     /**
      * 生命周期函数--监听页面加载
      */
-    onLoad(options) {
+    onLoad: function (options) {
 
     },
-
+    // 监听用户是否登录
+    watchLogin: async function () {
+        const that = this;
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                let info = { skip: that.data.skip, limit: that.data.limit };
+                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({ total: arr.total })
+                }
+                else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
+            },
+            fail: async res => {
+                wx.redirectTo({ url: '/pages/index/index' })
+            }
+        })
+    },
     /**
      * 生命周期函数--监听页面初次渲染完成
      */
-    onReady() {
+    onReady: function () {
 
     },
 
     /**
      * 生命周期函数--监听页面显示
      */
-    onShow() {
-
+    onShow: function () {
+        const that = this;
+        // 监听用户是否登录
+        that.watchLogin();
     },
 
     /**
      * 生命周期函数--监听页面隐藏
      */
-    onHide() {
+    onHide: function () {
 
     },
 
     /**
      * 生命周期函数--监听页面卸载
      */
-    onUnload() {
+    onUnload: function () {
 
     },
 
     /**
      * 页面相关事件处理函数--监听用户下拉动作
      */
-    onPullDownRefresh() {
+    onPullDownRefresh: function () {
 
     },
 
     /**
      * 页面上拉触底事件的处理函数
      */
-    onReachBottom() {
+    onReachBottom: function () {
 
     },
 
     /**
      * 用户点击右上角分享
      */
-    onShareAppMessage() {
+    onShareAppMessage: function () {
 
     }
 })

+ 5 - 2
pages/project/list.json

@@ -1,3 +1,6 @@
 {
-    "usingComponents": {}
-}
+    "component": true,
+    "usingComponents": {
+      "mobile-main": "/commpents/mobile-frame/index"
+    }
+  }

+ 99 - 0
pages/project/list.less

@@ -0,0 +1,99 @@
+.main {
+    height: var(--twoHeight);
+    background-color: var(--bgColor);
+
+    .one {
+        display: flex;
+        flex-direction: row;
+        width: 96vw;
+        padding: 2vw;
+
+        .one_1 {
+            flex-grow: 1;
+
+            input {
+                padding: 1vw 2vw 2vw 2vw;
+                border-radius: 2px;
+                font-size: var(--txtSize);
+                background-color: var(--f1Color);
+            }
+        }
+
+        .one_2 {
+            width: 15vw;
+
+            button {
+                width: 100%;
+                font-size: var(--btnSize);
+                padding: 2vw;
+            }
+        }
+    }
+
+    .two {
+        flex-grow: 1;
+        position: relative;
+        width: 100vw;
+
+        .list {
+            background-color: var(--f9Color);
+            padding: 2vw;
+            margin: 0 2vw 2vw 2vw;
+
+            .name {
+                font-size: var(--titleSize);
+                font-weight: bold;
+                margin: 0 0 1vw 0;
+            }
+
+            .other {
+                margin: 0 0 1vw 0;
+
+                .other_1 {
+                    font-size: var(--txtSize);
+                    margin: 0 0 1vw 0;
+
+                    text {
+                        color: var(--labelColor);
+                    }
+
+                    text:last-child {
+                        color: var(--txtColor);
+                    }
+                }
+            }
+
+            .btn {
+                display: flex;
+                flex-direction: row;
+                justify-content: center;
+                text-align: center;
+                flex-wrap: wrap;
+
+                .btn_1 {
+                    width: 20vw;
+                    margin: 0 1vw 1vw 1vw;
+
+                    button {
+                        width: 100%;
+                        font-size: var(--btnSize);
+                        padding: 2vw;
+                    }
+                }
+            }
+        }
+    }
+}
+
+.scroll-view {
+    position: absolute;
+    top: 0;
+    left: 0;
+    right: 0;
+    bottom: 0;
+
+    .list-scroll-view {
+        display: flex;
+        flex-direction: column;
+    }
+}

+ 35 - 2
pages/project/list.wxml

@@ -1,2 +1,35 @@
-<!--pages/project/list.wxml-->
-<text>pages/project/list.wxml</text>
+<mobile-main frameStyle="{{frameStyle}}" bind:back="back">
+    <view slot="info" class="container main">
+        <view class="one">
+            <view class="one_1">
+                <input type="text" placeholder="请输入关键词" />
+            </view>
+            <view class="one_2">
+                <button type="primary" bindtap="toCommon" data-route="project/add">添加</button>
+            </view>
+        </view>
+        <view class="two">
+            <scroll-view scroll-y="true" class="scroll-view" bindscrolltolower="upcroll">
+                <view class="list-scroll-view">
+                    <view class="list" wx:for="{{list}}" wx:key="item">
+                        <view class="name">{{item.name||'暂无'}}</view>
+                        <view class="other">
+                            <view class="other_1 textOver">
+                                <text>比赛项目说明:</text>
+                                <text>{{item.explain||'暂无'}}</text>
+                            </view>
+                            <view class="other_1">
+                                <text>比赛人数:</text>
+                                <text>{{item.num||'0'}}人</text>
+                            </view>
+                        </view>
+                        <view class="btn">
+                            <view class="btn_1"><button type="primary" bindtap="toEdit" data-item="{{item}}">信息维护</button></view>
+                            <view class="btn_1"><button type="warn" bindtap="toDel" data-item="{{item}}">信息删除</button></view>
+                        </view>
+                    </view>
+                </view>
+            </scroll-view>
+        </view>
+    </view>
+</mobile-main>

+ 82 - 1
pages/project/list.wxss

@@ -1 +1,82 @@
-/* pages/project/list.wxss */
+.main {
+  height: var(--twoHeight);
+  background-color: var(--bgColor);
+}
+.main .one {
+  display: flex;
+  flex-direction: row;
+  width: 96vw;
+  padding: 2vw;
+}
+.main .one .one_1 {
+  flex-grow: 1;
+}
+.main .one .one_1 input {
+  padding: 1vw 2vw 2vw 2vw;
+  border-radius: 2px;
+  font-size: var(--txtSize);
+  background-color: var(--f1Color);
+}
+.main .one .one_2 {
+  width: 15vw;
+}
+.main .one .one_2 button {
+  width: 100%;
+  font-size: var(--btnSize);
+  padding: 2vw;
+}
+.main .two {
+  flex-grow: 1;
+  position: relative;
+  width: 100vw;
+}
+.main .two .list {
+  background-color: var(--f9Color);
+  padding: 2vw;
+  margin: 0 2vw 2vw 2vw;
+}
+.main .two .list .name {
+  font-size: var(--titleSize);
+  font-weight: bold;
+  margin: 0 0 1vw 0;
+}
+.main .two .list .other {
+  margin: 0 0 1vw 0;
+}
+.main .two .list .other .other_1 {
+  font-size: var(--txtSize);
+  margin: 0 0 1vw 0;
+}
+.main .two .list .other .other_1 text {
+  color: var(--labelColor);
+}
+.main .two .list .other .other_1 text:last-child {
+  color: var(--txtColor);
+}
+.main .two .list .btn {
+  display: flex;
+  flex-direction: row;
+  justify-content: center;
+  text-align: center;
+  flex-wrap: wrap;
+}
+.main .two .list .btn .btn_1 {
+  width: 20vw;
+  margin: 0 1vw 1vw 1vw;
+}
+.main .two .list .btn .btn_1 button {
+  width: 100%;
+  font-size: var(--btnSize);
+  padding: 2vw;
+}
+.scroll-view {
+  position: absolute;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+}
+.scroll-view .list-scroll-view {
+  display: flex;
+  flex-direction: column;
+}

+ 4 - 0
utils/dict.js

@@ -112,4 +112,8 @@ export const type = [
     // { label: '管理员', value: '-1' },
     { label: '普通用户', value: '0' },
     { label: '裁判用户', value: '1' },
+]
+export const match_project = [
+    { label: '单打', value: '单打' },
+    { label: '双打', value: '双打' },
 ]