guhongwei 2 years ago
parent
commit
6f0966d417

+ 3 - 2
app.json

@@ -4,10 +4,10 @@
         "pages/register/index",
         "pages/register/index",
         "pages/school/index",
         "pages/school/index",
         "pages/smy/index",
         "pages/smy/index",
+        "pages/suser/list",
         "pages/sadmin/list",
         "pages/sadmin/list",
         "pages/scoach/list",
         "pages/scoach/list",
         "pages/sstudent/list",
         "pages/sstudent/list",
-        "pages/suser/list",
         "pages/club/index",
         "pages/club/index",
         "pages/match/index",
         "pages/match/index",
         "pages/other/agree",
         "pages/other/agree",
@@ -16,7 +16,8 @@
         "pages/logs/logs",
         "pages/logs/logs",
         "pages/user/basic",
         "pages/user/basic",
         "pages/setting/basic",
         "pages/setting/basic",
-        "pages/setting/contact"
+        "pages/setting/contact",
+        "pages/suser/add"
     ],
     ],
     "usingComponents": {
     "usingComponents": {
         "van-sidebar": "@vant/weapp/sidebar/index",
         "van-sidebar": "@vant/weapp/sidebar/index",

+ 1 - 1
pages/setting/basic.js

@@ -73,7 +73,7 @@ Page({
         wx.getStorage({
         wx.getStorage({
             key: 'user',
             key: 'user',
             success: async res => {
             success: async res => {
-                const arr = await app.$get(`/newCourt/api/user/${res.data.openid}`);
+                const arr = await app.$get(`/newCourt/api/user/${res.data.id}`);
                 if (arr.errcode == '0') { that.setData({ form: arr.data }) }
                 if (arr.errcode == '0') { that.setData({ form: arr.data }) }
             },
             },
             fail: res => {
             fail: res => {

+ 1 - 1
pages/smy/index.js

@@ -42,7 +42,7 @@ Page({
         wx.getStorage({
         wx.getStorage({
             key: 'user',
             key: 'user',
             success: async res => {
             success: async res => {
-                const arr = await app.$get(`/newCourt/api/user/${res.data.openid}`);
+                const arr = await app.$get(`/newCourt/api/user/${res.data._id}`);
                 if (arr.errcode == '0') {
                 if (arr.errcode == '0') {
                     that.setData({ user: arr.data })
                     that.setData({ user: arr.data })
                     let btnData = school_menu.find((i) => i.type == arr.data.type);
                     let btnData = school_menu.find((i) => i.type == arr.data.type);

+ 162 - 0
pages/suser/add.js

@@ -0,0 +1,162 @@
+const app = getApp()
+import WxValidate from '../../utils/wxValidate'
+const { gender } = require('../../utils/dict')
+Page({
+
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
+        id: '',
+        form: { icon: [] },
+        typeList: [
+            { label: '超级管理员', value: '-1' },
+            { label: '普通用户', value: '0' },
+            { label: '管理员', value: '1' },
+            { label: '教练', value: '2' },
+        ],
+        genderList: gender
+    },
+    initValidate() {
+        const rules = { type: { required: true }, icon: { required: true }, name: { required: true }, card: { required: true }, gender: { required: true }, phone: { required: true, tel: true } }
+        // 验证字段的提示信息,若不传则调用默认的信息
+        const messages = { type: { required: '请选择用户类型', }, icon: { required: '请选择头像', }, name: { required: '请输入用户姓名', }, card: { required: '请输入身份证号', }, gender: { required: '请选择性别', }, phone: { required: '请输入手机号', } };
+        this.WxValidate = new WxValidate(rules, messages)
+    },
+    // 返回
+    back: function () {
+        wx.navigateBack({ delta: 1 })
+    },
+    imgUpl: function (e) {
+        const that = this;
+        let data = that.data.form.icon;
+        data.push(e.detail)
+        that.setData({ 'form.icon': data })
+    },
+    // 删除图片
+    imgDel: function (e) {
+        const that = this;
+        let list = that.data.form.icon;
+        let arr = list.filter((i, index) => index != e.detail.index)
+        that.setData({ 'form.icon': arr })
+    },
+    // 选择用户类型
+    typeChange: function (e) {
+        const that = this;
+        let data = that.data.typeList[e.detail.value];
+        if (data) {
+            that.setData({ 'form.type': data.value });
+            that.setData({ 'form.type_name': data.label });
+        }
+
+    },
+    // 选择性别
+    genderChange: function (e) {
+        const that = this;
+        let data = that.data.genderList[e.detail.value];
+        if (data) {
+            that.setData({ 'form.gender': data.value });
+            that.setData({ 'form.gender_name': data.label });
+        }
+    },
+    // 提交登录
+    onSubmit: async function (e) {
+        const that = this;
+        const params = e.detail.value;
+        const form = that.data.form;
+        params.icon = form.icon;
+        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 (that.data.id) arr = await app.$post(`/newCourt/api/user/${form._id}`, params);
+            else arr = await app.$post(`/newCourt/api/user`, params);
+            if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
+            else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
+        }
+    },
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: function (options) {
+        const that = this;
+        that.setData({ id: options.id || null })
+        //验证规则函数
+        that.initValidate();
+        // 监听用户是否登录
+        that.watchLogin();
+
+    },
+    // 监听用户是否登录
+    watchLogin: async function () {
+        const that = this;
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                let arr;
+                if (that.data.id) {
+                    arr = await app.$get(`/newCourt/api/user/${that.data.id}`);
+                    if (arr.errcode == '0') {
+                        let type = that.data.typeList.find(i => i.value == arr.data.type);
+                        if (type) arr.data.type_name = type.label;
+                        let gender = that.data.genderList.find(i => i.value == arr.data.gender);
+                        if (gender) arr.data.gender_name = gender.label;
+                        that.setData({ form: arr.data })
+                    } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
+                }
+            },
+            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/suser/add.json

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

+ 30 - 0
pages/suser/add.less

@@ -0,0 +1,30 @@
+.main {
+    background-color: var(--mainColor);
+
+    .one {
+        .content {
+            display: flex;
+            flex-direction: row;
+            border-bottom: 1px dashed var(--f1Color);
+            padding: 2vw 0;
+            margin: 0 2vw 2vw 2vw;
+
+            .value {
+                flex-grow: 1;
+                color: var(--blackColor);
+
+            }
+        }
+
+        .btn {
+            text-align: center;
+            margin: 5vw 0 0 0;
+
+            button {
+                width: 40vw;
+                margin: 0 2vw;
+                padding: 1vw 0;
+            }
+        }
+    }
+}

+ 51 - 0
pages/suser/add.wxml

@@ -0,0 +1,51 @@
+<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 mode="selector" bindchange="typeChange" name="type" value="{{form.type}}" range="{{typeList}}" range-key="label">
+                            <view class="picker">{{form.type_name||'请选择用户类型'}}</view>
+                        </picker>
+                    </view>
+                </view>
+                <view class="content">
+                    <view class="label">头像:</view>
+                    <view class="value">
+                        <upload list="{{form.icon}}" count="{{1}}" previewSize="{{30}}" bind:imgUpload="imgUpl" bind:imgDel="imgDel"></upload>
+                    </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">
+                        <picker mode="selector" bindchange="genderChange" name="gender" value="{{form.gender}}" range="{{genderList}}" range-key="label">
+                            <view class="picker">{{form.gender_name||'请选择性别'}}</view>
+                        </picker>
+                    </view>
+                </view>
+                <view class="content">
+                    <view class="label">身份证号:</view>
+                    <view class="value">
+                        <input name="card" value="{{form.card}}" placeholder="请输入身份证号" />
+                    </view>
+                </view>
+                <view class="content">
+                    <view class="label">手机号:</view>
+                    <view class="value">
+                        <input name="phone" value="{{form.phone}}" placeholder="请输入手机号" />
+                    </view>
+                </view>
+                <view class="btn">
+                    <button type="primary" size="mini" formType="submit">提交保存</button>
+                </view>
+            </form>
+        </view>
+    </view>
+</mobile-main>

+ 23 - 0
pages/suser/add.wxss

@@ -0,0 +1,23 @@
+.main {
+  background-color: var(--mainColor);
+}
+.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 .value {
+  flex-grow: 1;
+  color: var(--blackColor);
+}
+.main .one .btn {
+  text-align: center;
+  margin: 5vw 0 0 0;
+}
+.main .one .btn button {
+  width: 40vw;
+  margin: 0 2vw;
+  padding: 1vw 0;
+}

+ 67 - 2
pages/suser/list.js

@@ -6,17 +6,80 @@ Page({
      */
      */
     data: {
     data: {
         frameStyle: { useTop: true, name: '用户管理', leftArrow: true, useBar: false },
         frameStyle: { useTop: true, name: '用户管理', leftArrow: true, useBar: false },
+        list: [],
+        typeList: [
+            { label: '超级管理员', value: '-1' },
+            { label: '普通用户', value: '0' },
+            { label: '管理员', value: '1' },
+            { label: '教练', value: '2' },
+        ]
     },
     },
     // 返回
     // 返回
     back: function () {
     back: function () {
         wx.navigateBack({ delta: 1 })
         wx.navigateBack({ delta: 1 })
     },
     },
+    // 信息添加
+    toAdd: function () {
+        wx.navigateTo({ url: `/pages/suser/add` })
+    },
+    // 信息维护
+    toEdit: function (e) {
+        const that = this;
+        const { item } = e.currentTarget.dataset;
+        wx.navigateTo({ url: `/pages/suser/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/user/${item._id}`);
+                    if (arr.errcode == '0') {
+                        wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
+                        that.setData({ skip: 0, page: 0, list: [] })
+                        that.watchLogin()
+                    } else {
+                        wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
+                    }
+                }
+            }
+        })
+    },
     /**
     /**
      * 生命周期函数--监听页面加载
      * 生命周期函数--监听页面加载
      */
      */
     onLoad: function (options) {
     onLoad: function (options) {
-        const that = this;
 
 
+    },
+    // 监听用户是否登录
+    watchLogin: async function () {
+        const that = this;
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                const arr = await app.$get(`/newCourt/api/user`);
+                console.log(arr);
+                // if (arr.errcode == '0') {
+                //     for (const val of arr.data) { val.zHtype = this.searchType(val.type) }
+                //     that.setData({ list: arr.data });
+                // }
+                // else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
+            },
+            fail: async res => {
+                wx.redirectTo({ url: '/pages/index/index' })
+            }
+        })
+    },
+    // 用户类型
+    searchType: function (e) {
+        const that = this;
+        let data = that.data.typeList.find(i => i.value == e);
+        if (data) return data.label;
+        else return '暂无';
     },
     },
     /**
     /**
      * 生命周期函数--监听页面初次渲染完成
      * 生命周期函数--监听页面初次渲染完成
@@ -29,7 +92,9 @@ Page({
      * 生命周期函数--监听页面显示
      * 生命周期函数--监听页面显示
      */
      */
     onShow: function () {
     onShow: function () {
-
+        const that = this;
+        // 监听用户是否登录
+        that.watchLogin();
     },
     },
 
 
     /**
     /**

+ 53 - 1
pages/suser/list.less

@@ -30,6 +30,58 @@
     }
     }
 
 
     .two {
     .two {
-        background-color: #ffffff;
+        position: relative;
+        flex-grow: 1;
+        background-color: var(--whiteColor);
+        padding: 0 2vw;
+
+        .list {
+            background-color: var(--f9Color);
+            margin: 0 0 2vw 0;
+            padding: 2vw;
+            margin: 0 2vw 2vw 2vw;
+            border-radius: 5px;
+
+            .name {
+                font-size: var(--font18Szie);
+                font-weight: bold;
+                margin: 0 0 1vw 0;
+            }
+
+            .other {
+                margin: 0 0 1vw 0;
+
+                .other_1 {
+                    margin: 0 0 1vw 0;
+                    font-size: var(--font16Size);
+
+                    text:first-child {
+                        color: var(--f85Color);
+                    }
+                }
+            }
+
+            .btn {
+                text-align: center;
+
+                button {
+                    margin: 0 2vw;
+                    font-size: var(--font14Size);
+                }
+            }
+        }
+    }
+}
+
+.scroll-view {
+    position: absolute;
+    top: 0;
+    left: 0;
+    right: 0;
+    bottom: 0;
+
+    .list-scroll-view {
+        display: flex;
+        flex-direction: column;
     }
     }
 }
 }

+ 23 - 1
pages/suser/list.wxml

@@ -9,7 +9,29 @@
             </view>
             </view>
         </view>
         </view>
         <view class="two">
         <view class="two">
-            列表
+            <scroll-view scroll-y="true" class="scroll-view">
+                <view class="list-scroll-view">
+                    <view class="list" wx:for="{{list}}" wx:key="index">
+                        <view class="name">{{item.name}}</view>
+                        <view class="other">
+                            <view class="other_1">
+                                <text>用户类型:</text>
+                                <text>{{item.zHtype}}</text>
+                            </view>
+                            <view class="other_1">
+                                <text>联系电话:</text>
+                                <text>{{item.phone}}</text>
+                            </view>
+                        </view>
+                        <view class="btn">
+                            <view class="btn_1">
+                                <button type="primary" size="mini" bindtap="toEdit" data-item="{{item}}">信息维护</button>
+                                <button type="warn" size="mini" bindtap="toDel" data-item="{{item}}">信息删除</button>
+                            </view>
+                        </view>
+                    </view>
+                </view>
+            </scroll-view>
         </view>
         </view>
     </view>
     </view>
 </mobile-main>
 </mobile-main>

+ 44 - 1
pages/suser/list.wxss

@@ -25,5 +25,48 @@
   font-size: var(--font14Size);
   font-size: var(--font14Size);
 }
 }
 .main .two {
 .main .two {
-  background-color: #ffffff;
+  position: relative;
+  flex-grow: 1;
+  background-color: var(--whiteColor);
+  padding: 0 2vw;
+}
+.main .two .list {
+  background-color: var(--f9Color);
+  margin: 0 0 2vw 0;
+  padding: 2vw;
+  margin: 0 2vw 2vw 2vw;
+  border-radius: 5px;
+}
+.main .two .list .name {
+  font-size: var(--font18Szie);
+  font-weight: bold;
+  margin: 0 0 1vw 0;
+}
+.main .two .list .other {
+  margin: 0 0 1vw 0;
+}
+.main .two .list .other .other_1 {
+  margin: 0 0 1vw 0;
+  font-size: var(--font16Size);
+}
+.main .two .list .other .other_1 text:first-child {
+  color: var(--f85Color);
+}
+.main .two .list .btn {
+  text-align: center;
+}
+.main .two .list .btn button {
+  margin: 0 2vw;
+  font-size: var(--font14Size);
+}
+.scroll-view {
+  position: absolute;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+}
+.scroll-view .list-scroll-view {
+  display: flex;
+  flex-direction: column;
 }
 }