Browse Source

比赛场地信息

YY 2 years ago
parent
commit
bedd2c2c3e

+ 40 - 2
pages/match/address.js

@@ -1,4 +1,6 @@
 const app = getApp()
+import { is_use_project } from '../../utils/dict';
+
 Page({
 
     /**
@@ -7,15 +9,47 @@ Page({
     data: {
         frameStyle: { useTop: true, name: '比赛场地管理', leftArrow: true, useBar: false },
         searchInfo: {},
+        list: [],
     },
     // 跳转菜单
     back(e) {
         wx.navigateBack({ delta: 1 });
     },
+    search: function (e) {
+        const that = this;
+        that.setData({ 'searchInfo.name': e.detail.value });
+        that.watchLogin()
+    },
     // 添加
     toAdd() {
         wx.navigateTo({ url: '/pages/match/addressAdd' })
     },
+    // 修改
+    toEdit: function (e) {
+        const that = this;
+        let { id } = e.currentTarget.dataset;
+        wx.navigateTo({ url: `/pages/match/addressAdd?id=${id}` })
+    },
+    // 删除
+    toDel: async function (e) {
+        const that = this;
+        const { id } = e.currentTarget.dataset;
+        wx.showModal({
+            title: '提示',
+            content: '是否确认删除该条数据?',
+            async success(res) {
+                if (res.confirm) {
+                    const arr = await app.$delete(`/newCourt/api/ground/${id}`);
+                    if (arr.errcode == '0') {
+                        wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
+                        that.watchLogin()
+                    } else {
+                        wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
+                    }
+                }
+            }
+        })
+    },
     // 查询
     search: function (e) {
         const that = this;
@@ -28,7 +62,7 @@ Page({
     onLoad: function (options) {
         const that = this;
         // 监听用户是否登录
-        that.watchLogin();
+        // that.watchLogin();
     },
     watchLogin: function () {
         const that = this;
@@ -40,6 +74,10 @@ Page({
                 if (searchInfo && searchInfo.name) info.name = searchInfo.name;
                 const arr = await app.$get(`/newCourt/api/ground`, { ...info });
                 if (arr.errcode == '0') {
+                    for (const val of arr.data) {
+                        const aee = await app.$get(`/newCourt/api/user/${val.referee_id}`);
+                        if(aee.errcode=='0')val.referee_name=aee.data.name
+                    }
                     that.setData({ list: arr.data })
                 } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
             },
@@ -59,7 +97,7 @@ Page({
      * 生命周期函数--监听页面显示
      */
     onShow: function () {
-
+        this.watchLogin();
     },
 
     /**

+ 55 - 1
pages/match/address.less

@@ -4,7 +4,7 @@
     .zero {
         width: 96vw;
         margin: 0 0 2vw 0;
-        background-color: #ff0000;
+        // background-color: #fff;
     }
 
     .zero:last-child {
@@ -53,6 +53,60 @@
             .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;
+
+                    .info {
+                        display: flex;
+                        flex-direction: row;
+                        margin: 0 0 2vw 0;
+
+                        .list_2 {
+                            padding: 0 0 0 2vw;
+
+                            .name {
+                                font-size: 18px;
+                                font-weight: bold;
+                                margin: 0 0 1vw 0;
+                                overflow: hidden;
+                                text-overflow: ellipsis;
+                                -webkit-line-clamp: 2;
+                                word-break: break-all;
+                                display: -webkit-box;
+                                -webkit-box-orient: vertical;
+                            }
+
+                            .other {
+                                .other_1 {
+                                    margin: 0 0 1vw 0;
+                                    color: #000000a6;
+                                    font-size: 15px;
+                                    overflow: hidden;
+                                    text-overflow: ellipsis;
+                                    -webkit-line-clamp: 4;
+                                    word-break: break-all;
+                                    display: -webkit-box;
+                                    -webkit-box-orient: vertical;
+                                }
+                            }
+                        }
+                    }
+
+                    .btn {
+                        text-align: center;
+
+                        button {
+                            margin: 0 2vw;
+                            font-size: 14px;
+                        }
+                    }
+
+                }
             }
         }
     }

+ 28 - 1
pages/match/address.wxml

@@ -11,7 +11,34 @@
         <view class="zero two">
             <scroll-view scroll-y="true" class="scroll-view">
                 <view class="list-scroll-view">
-                    1111
+                    <view class="list" wx:for="{{list}}" wx:key="item">
+                        <view class="info">
+                            <view class="list_2">
+                                <view class="other">
+                                    <view class="other_1">
+                                        <text>比赛场地名称:</text>
+                                        <text>{{item.name||'暂无'}}</text>
+                                    </view>
+                                    <view class="other_1">
+                                        <text>裁判:</text>
+                                        <text>{{item.referee_name||'暂无'}}</text>
+                                    </view>
+                                    <view class="other_1">
+                                        <text>备注:</text>
+                                        <text>{{item.remark||'暂无'}}</text>
+                                    </view>
+                                    <view class="other_1">
+                                        <text>是否使用:</text>
+                                        <text>{{item.is_use=='0'?'启用':'禁用'}}</text>
+                                    </view>
+                                </view>
+                            </view>
+                        </view>
+                        <view class="btn">
+                            <button type="primary" bindtap="toEdit" data-id="{{item._id}}" size="mini">信息维护</button>
+                            <button size="mini" type="warn" bindtap="toDel" data-id="{{item._id}}">信息删除</button>
+                        </view>
+                    </view>
                 </view>
             </scroll-view>
         </view>

+ 44 - 1
pages/match/address.wxss

@@ -4,7 +4,6 @@
 .main .zero {
   width: 96vw;
   margin: 0 0 2vw 0;
-  background-color: #ff0000;
 }
 .main .zero:last-child {
   margin: 0;
@@ -47,3 +46,47 @@
   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 .info {
+  display: flex;
+  flex-direction: row;
+  margin: 0 0 2vw 0;
+}
+.main .two .scroll-view .list-scroll-view .list .info .list_2 {
+  padding: 0 0 0 2vw;
+}
+.main .two .scroll-view .list-scroll-view .list .info .list_2 .name {
+  font-size: 18px;
+  font-weight: bold;
+  margin: 0 0 1vw 0;
+  overflow: hidden;
+  text-overflow: ellipsis;
+  -webkit-line-clamp: 2;
+  word-break: break-all;
+  display: -webkit-box;
+  -webkit-box-orient: vertical;
+}
+.main .two .scroll-view .list-scroll-view .list .info .list_2 .other .other_1 {
+  margin: 0 0 1vw 0;
+  color: #000000a6;
+  font-size: 15px;
+  overflow: hidden;
+  text-overflow: ellipsis;
+  -webkit-line-clamp: 4;
+  word-break: break-all;
+  display: -webkit-box;
+  -webkit-box-orient: vertical;
+}
+.main .two .scroll-view .list-scroll-view .list .btn {
+  text-align: center;
+}
+.main .two .scroll-view .list-scroll-view .list .btn button {
+  margin: 0 2vw;
+  font-size: 14px;
+}

+ 80 - 3
pages/match/addressAdd.js

@@ -1,4 +1,7 @@
 const app = getApp()
+import WxValidate from '../../utils/wxValidate'
+import { is_use_project } from '../../utils/dict';
+
 Page({
 
     /**
@@ -6,17 +9,91 @@ Page({
      */
     data: {
         frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
+        id: '',
+        // 裁判列表
+        referee_idList: [],
+        // 是否使用
+        is_useList: is_use_project,
+        form: {}
+
+    },
+    initValidate() {
+        const rules = { name: { required: false }, referee_id: { required: false }, remark: { required: false }, is_use: { required: false } }
+        // 验证字段的提示信息,若不传则调用默认的信息
+        const messages = { name: { required: '请输入比赛场地名称', }, referee_id: { required: '请选择裁判', }, remark: { required: '请输入备注', }, is_use: { required: '请选择是否使用' } };
+        this.WxValidate = new WxValidate(rules, messages)
+    },
+    // 返回
+    back: function () {
+        wx.navigateBack({ delta: 1 })
     },
-    // 跳转菜单
-    back(e) {
-        wx.navigateBack({ delta: 1 });
+    // 选择裁判
+    referee_idChange: function (e) {
+        const that = this;
+        let index = e.detail.value;
+        let value = that.data.referee_idList[index];
+        that.setData({ 'form.referee_id': value.openid });
+        that.setData({ 'form.referee_name': value.name });
+    },
+    // 是否使用
+    is_useChange: function (e) {
+        const that = this;
+        let index = e.detail.value;
+        let value = that.data.is_useList[index];
+        that.setData({ 'form.is_use': value.label });
+    },
+    // 提交登录
+    onSubmit: async function (e) {
+        const that = this;
+        const params = e.detail.value;
+        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/ground/${data._id}`, params);
+            else arr = await app.$post(`/newCourt/api/ground`, 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: function (options) {
         const that = this;
+        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/user`, { type: 1 });
+                if (arr.errcode == '0') { that.setData({ referee_idList: arr.data }); }
+                if (that.data.id) {
+                    const arr = await app.$get(`/newCourt/api/ground/${that.data.id}`);
+                    if (arr.errcode == '0') {
+                        let user = that.data.referee_idList.find((i) => i.openid == arr.data.referee_id);
+                        if (user) arr.data.referee_name = user.name;
+                        that.setData({ form: arr.data });
+                    }
+                }
+
 
+            },
+            fail: res => {
+                wx.redirectTo({ url: '/pages/index/index', })
+            }
+        })
     },
     /**
      * 生命周期函数--监听页面初次渲染完成

+ 34 - 1
pages/match/addressAdd.less

@@ -3,7 +3,40 @@
 
     .one {
         width: 96vw;
-        background-color: #ff0000;
+
+        .content {
+            display: flex;
+            flex-direction: row;
+            justify-content: space-between;
+            align-items: center;
+            margin: 0 10px;
+            padding: 10px 5px;
+            border-bottom: 1px solid #cccccc;
+
+            .label {
+                font-size: 15px;
+            }
+
+            .value {
+                color: #666;
+                font-size: 16px;
+                text-align: right;
+
+                textarea {
+                    max-width: 220px;
+                }
+            }
+        }
+
+        .btn {
+            width: 96vw;
+            margin: 2vw 0 0 0;
+            text-align: center;
+
+            button {
+                font-size: 14px;
+            }
+        }
     }
 
 }

+ 30 - 2
pages/match/addressAdd.wxml

@@ -1,7 +1,35 @@
 <mobile-main frameStyle="{{frameStyle}}" bind:back="back" bind:tabPath="tabPath">
     <view slot="info" class="container main">
-        <view class="zero one">
-            信息添加
+        <view class="one">
+            <form catchsubmit="onSubmit">
+                <view class="content">
+                    <view class="label">场地名称</view>
+                    <view class="value">
+                        <view class="value"><input name="name" value="{{form.name}}" placeholder="请输入比赛场地名称" /></view>
+                    </view>
+                </view>
+                <view class="content">
+                    <view class="label">裁判:</view>
+                    <picker name="referee_id" bindchange="referee_idChange" value="{{form.referee_id}}" range-key='name' range="{{referee_idList}}">
+                        <view class="input">{{form.referee_name||'请选择裁判'}}</view>
+                    </picker>
+                </view>
+                <view class="content">
+                    <view class="label">备注:</view>
+                    <view class="value">
+                        <view class="value"><input name="remark" value="{{form.remark}}" placeholder="请输入备注" /></view>
+                    </view>
+                </view>
+                <view class="content">
+                    <view class="label">是否使用:</view>
+                    <picker name="is_use" bindchange="is_useChange" value="{{form.is_use}}" range-key='value' range="{{is_useList}}">
+                        <view class="input">{{form.is_use=='0'?'启用':form.is_use=='1'?'禁用':'选择是否使用'}}</view>
+                    </picker>
+                </view>
+                <view class="btn">
+                    <button type="primary" size="mini" formType="submit">提交保存</button>
+                </view>
+            </form>
         </view>
     </view>
 </mobile-main>

+ 28 - 1
pages/match/addressAdd.wxss

@@ -3,5 +3,32 @@
 }
 .main .one {
   width: 96vw;
-  background-color: #ff0000;
+}
+.main .one .content {
+  display: flex;
+  flex-direction: row;
+  justify-content: space-between;
+  align-items: center;
+  margin: 0 10px;
+  padding: 10px 5px;
+  border-bottom: 1px solid #cccccc;
+}
+.main .one .content .label {
+  font-size: 15px;
+}
+.main .one .content .value {
+  color: #666;
+  font-size: 16px;
+  text-align: right;
+}
+.main .one .content .value textarea {
+  max-width: 220px;
+}
+.main .one .btn {
+  width: 96vw;
+  margin: 2vw 0 0 0;
+  text-align: center;
+}
+.main .one .btn button {
+  font-size: 14px;
 }

+ 4 - 0
utils/dict.js

@@ -121,6 +121,10 @@ export const match_project = [
     { label: '单打', value: '单打' },
     { label: '双打', value: '双打' },
 ]
+export const is_use_project = [
+    { label: '0', value: '使用' },
+    { label: '1', value: '禁用' },
+]
 export const examine_status = [
     { label: '待审核', value: '0' },
     { label: '审核通过', value: '1' },