guhongwei 2 tahun lalu
induk
melakukan
1fb1974df4

+ 1 - 1
app.json

@@ -1,6 +1,5 @@
 {
     "pages": [
- 
         "pages/index/index",
         "pages/register/index",
         "pages/home/index",
@@ -18,6 +17,7 @@
         "pages/match/matchadd",
         "pages/match/project",
         "pages/match/projectadd",
+        "pages/match/matchgroup",
         "pages/test/index"
     ],
     "usingComponents": {

+ 159 - 0
pages/match/matchgroup.js

@@ -0,0 +1,159 @@
+const app = getApp()
+import WxValidate from '../../utils/wxValidate';
+Page({
+
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        frameStyle: { useTop: true, name: '话题', leftArrow: true, useBar: false },
+        id: '',
+        info: {},
+        projectList: [],
+        dialog: { title: '赛事组别', show: false, type: '1' },
+        form: { project: [] }
+    },
+    initValidate() {
+        const rules = { name: { required: true }, age: { required: true }, gender: { required: true } }
+        // 验证字段的提示信息,若不传则调用默认的信息
+        const messages = { name: { required: '请输入名称' }, age: { required: '请输入年龄限制' }, gender: { required: '请输入性别限制' } };
+        this.WxValidate = new WxValidate(rules, messages)
+    },
+    // 跳转菜单
+    back(e) {
+        wx.navigateBack({ delta: 1 })
+    },
+    // 添加
+    toAdd: function () {
+        const that = this;
+        that.setData({ dialog: { title: '赛事组别', show: true, type: '1' } });
+    },
+    // 信息删除
+    toDel: async function (e) {
+        const that = this;
+        const info = that.data.info;
+        const { item } = e.currentTarget.dataset;
+        wx.showModal({
+            title: '提示',
+            content: '您确定要删除该条数据吗?',
+            async success(res) {
+                if (res.confirm) {
+                    let grouping = info.grouping.filter((i) => i._id != item._id);
+                    const arr = await app.$post(`/newCourt/api/match/${info.id}`, { grouping: grouping })
+                    if (arr.errcode == '0') {
+                        wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 });
+                        that.watchLogin()
+                    } else {
+                        wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 });
+                    }
+                }
+            }
+        })
+    },
+    checkboxChange: function (e) {
+        const that = this;
+        that.setData({ 'form.project': e.detail.value });
+    },
+    // 提交
+    onSubmit: async function (e) {
+        const that = this;
+        const params = e.detail.value;
+        const info = that.data.info;
+        if (!this.WxValidate.checkForm(params)) {
+            const error = this.WxValidate.errorList[0];
+            wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+            return false
+        } else {
+            let grouping = [...info.grouping, params];
+            const arr = await app.$post(`/newCourt/api/match/${that.data.id}`, { grouping: grouping })
+            if (arr.errcode == '0') {
+                that.watchLogin();
+                that.toClose();
+            } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
+
+        }
+    },
+    // 关闭弹框
+    toClose: function () {
+        const that = this;
+        that.setData({ dialog: { title: '赛事组别', show: false, type: '1' } })
+    },
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: function (options) {
+        const that = this;
+        that.setData({ id: options.id || '62e23cd3bb22e03d0b49d73b' });
+        //验证规则函数
+        that.initValidate();
+        that.watchLogin()
+    },
+    watchLogin: function () {
+        const that = this;
+        wx.getStorage({
+            key: 'user',
+            success: async (res) => {
+                if (that.data.id) {
+                    let arr;
+                    arr = await app.$get(`/newCourt/api/match/${that.data.id}`);
+                    if (arr.errcode == '0') {
+                        that.setData({ info: arr.data })
+                    } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
+                    arr = await app.$get(`/newCourt/api/matchProject`);
+                    if (arr.errcode == '0') that.setData({ projectList: arr.data })
+                }
+            },
+            fail: async (res) => {
+                wx.redirectTo({ url: '/pages/index/index' });
+            },
+        });
+    },
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload: function () {
+
+    },
+
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
+
+    },
+
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom: function () {
+
+    },
+
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage: function () {
+
+    }
+})

+ 7 - 0
pages/match/matchgroup.json

@@ -0,0 +1,7 @@
+{
+    "component": true,
+    "usingComponents": {
+        "mobile-main": "/commpents/mobile-frame/index",
+        "e-dialog": "/commpents/dialog/index"
+    }
+}

+ 117 - 0
pages/match/matchgroup.less

@@ -0,0 +1,117 @@
+.main {
+    height: 88.8vh;
+
+    .zero {
+        width: 96vw;
+        margin: 0 0 2vw 0;
+    }
+
+    .zero:nth-child(2) {
+        margin: 0 0 0 0;
+    }
+
+    .one {
+        width: 92vw;
+        padding: 2vw;
+        background-color: #fff;
+        text-align: center;
+
+        button {
+            font-size: 14px;
+        }
+    }
+
+    .two {
+        flex-grow: 1;
+        width: 100%;
+        position: relative;
+
+        .scroll-view {
+            position: absolute;
+            top: 0;
+            left: 0;
+            right: 0;
+            bottom: 0;
+
+            .list-scroll-view {
+                display: flex;
+                flex-direction: column;
+
+                .list {
+                    background-color: #ffffff;
+                    border-bottom: 1px solid #cccccc;
+                    padding: 2vw 0;
+                    display: flex;
+                    flex-direction: column;
+
+                    .name {
+                        font-size: 15px;
+                        font-weight: bold;
+                        margin: 0 0 1vw 0;
+                    }
+
+                    .other {
+                        margin: 0 0 1vw 0;
+
+                        .other_1 {
+                            margin: 0 0 1vw 0;
+                            color: #000000a6;
+                            font-size: 12px;
+                        }
+                    }
+
+                    .btn {
+                        text-align: center;
+
+                        button {
+                            font-size: 14px;
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
+.dialog_1 {
+    width: 80vw;
+
+    .content {
+        background-color: #ffffff;
+        border-bottom: 1px solid #cccccc;
+        display: flex;
+        flex-direction: row;
+        justify-content: space-between;
+        padding: 2vw;
+        width: 76vw;
+
+        .label {
+            width: 25vw;
+            text-align: left;
+            font-size: 14px;
+        }
+
+        .value {
+            width: 65vw;
+            text-align: right;
+            font-size: 14px;
+
+            textarea {
+                width: 65vw;
+            }
+        }
+
+        .checkbox {
+            .list {
+                .name {
+                    margin: 0 2vw 0 0;
+                }
+            }
+        }
+    }
+
+    .btn {
+        margin: 2vw 0 0 0;
+        text-align: center;
+    }
+}

+ 69 - 0
pages/match/matchgroup.wxml

@@ -0,0 +1,69 @@
+<mobile-main frameStyle="{{frameStyle}}" bind:back="back">
+    <view slot="info" class="container main">
+        <view class="zero one">
+            <button type="primary" size="mini" bindtap="toAdd">添加组别</button>
+        </view>
+        <view class="zero two">
+            <scroll-view scroll-y="true" class="scroll-view">
+                <view class="list-scroll-view">
+                    <view class="list" wx:for="{{info.grouping}}" wx:key="item">
+                        <view class="name">
+                            {{item.name}}
+                        </view>
+                        <view class="other">
+                            <view class="other_1">
+                                <text>年龄限制:</text><text>{{item.age}}</text>
+                            </view>
+                            <view class="other_1">
+                                <text>性别限制:</text><text>{{item.gender}}</text>
+                            </view>
+                        </view>
+                        <view class="btn">
+                            <button type="warn" size="mini" bindtap="toDel" data-item="{{item}}">信息删除</button>
+                        </view>
+                    </view>
+                </view>
+            </scroll-view>
+        </view>
+    </view>
+</mobile-main>
+<e-dialog dialog="{{dialog}}" bind:toClose="toClose">
+    <view slot="info">
+        <view class="dialog_1" wx:if="{{dialog.type=='1'}}">
+            <form catchsubmit="onSubmit">
+                <view class="content">
+                    <view class="label">名称</view>
+                    <view class="value">
+                        <input type="text" name="name" value="{{form.name}}" placeholder="请输入名称" />
+                    </view>
+                </view>
+                <view class="content">
+                    <view class="label">年龄限制</view>
+                    <view class="value">
+                        <input type="text" name="age" value="{{form.age}}" placeholder="请输入年龄限制" />
+                    </view>
+                </view>
+                <view class="content">
+                    <view class="label">性别限制</view>
+                    <view class="value">
+                        <input type="text" name="gender" value="{{form.gender}}" placeholder="请输入性别限制" />
+                    </view>
+                </view>
+                <view class="content">
+                    <view class="label">比赛项目</view>
+                    <view class="value checkbox">
+                        <checkbox-group name="project" bindchange="checkboxChange">
+                            <label class="list" wx:for="{{projectList}}" wx:key="item">
+                                <text class="name">{{item.name}}</text>
+                                <checkbox value="{{item._id}}" checked="{{item.checked}}" />
+                            </label>
+                        </checkbox-group>
+                    </view>
+                </view>
+                <view class="btn">
+                    <button type="primary" size="mini" form-type="submit">提交保存</button>
+                </view>
+            </form>
+        </view>
+    </view>
+</e-dialog>

+ 93 - 0
pages/match/matchgroup.wxss

@@ -0,0 +1,93 @@
+.main {
+  height: 88.8vh;
+}
+.main .zero {
+  width: 96vw;
+  margin: 0 0 2vw 0;
+}
+.main .zero:nth-child(2) {
+  margin: 0 0 0 0;
+}
+.main .one {
+  width: 92vw;
+  padding: 2vw;
+  background-color: #fff;
+  text-align: center;
+}
+.main .one button {
+  font-size: 14px;
+}
+.main .two {
+  flex-grow: 1;
+  width: 100%;
+  position: relative;
+}
+.main .two .scroll-view {
+  position: absolute;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+}
+.main .two .scroll-view .list-scroll-view {
+  display: flex;
+  flex-direction: column;
+}
+.main .two .scroll-view .list-scroll-view .list {
+  background-color: #ffffff;
+  border-bottom: 1px solid #cccccc;
+  padding: 2vw 0;
+  display: flex;
+  flex-direction: column;
+}
+.main .two .scroll-view .list-scroll-view .list .name {
+  font-size: 15px;
+  font-weight: bold;
+  margin: 0 0 1vw 0;
+}
+.main .two .scroll-view .list-scroll-view .list .other {
+  margin: 0 0 1vw 0;
+}
+.main .two .scroll-view .list-scroll-view .list .other .other_1 {
+  margin: 0 0 1vw 0;
+  color: #000000a6;
+  font-size: 12px;
+}
+.main .two .scroll-view .list-scroll-view .list .btn {
+  text-align: center;
+}
+.main .two .scroll-view .list-scroll-view .list .btn button {
+  font-size: 14px;
+}
+.dialog_1 {
+  width: 80vw;
+}
+.dialog_1 .content {
+  background-color: #ffffff;
+  border-bottom: 1px solid #cccccc;
+  display: flex;
+  flex-direction: row;
+  justify-content: space-between;
+  padding: 2vw;
+  width: 76vw;
+}
+.dialog_1 .content .label {
+  width: 25vw;
+  text-align: left;
+  font-size: 14px;
+}
+.dialog_1 .content .value {
+  width: 65vw;
+  text-align: right;
+  font-size: 14px;
+}
+.dialog_1 .content .value textarea {
+  width: 65vw;
+}
+.dialog_1 .content .checkbox .list .name {
+  margin: 0 2vw 0 0;
+}
+.dialog_1 .btn {
+  margin: 2vw 0 0 0;
+  text-align: center;
+}

+ 0 - 1
pages/match/mess.js

@@ -59,7 +59,6 @@ Page({
     },
     // 赛事组别
     toGroup: function (e) {
-        const that = this;
         const { item } = e.currentTarget.dataset;
         wx.navigateTo({ url: `/pages/match/matchgroup?id=${item._id}` })
     },