Przeglądaj źródła

我的页面账号设置

zs 2 lat temu
rodzic
commit
92a74f6fcc

+ 1 - 0
app.json

@@ -11,6 +11,7 @@
         "pages/usermymatch/index",
         "pages/setting/index",
         "pages/setting/basic",
+        "pages/setting/contact",
         "pages/test/index"
     ],
     "usingComponents": {

+ 1 - 1
pages/my/index.js

@@ -59,7 +59,7 @@ Page({
      * 生命周期函数--监听页面显示
      */
     onShow: function () {
-
+        this.watchLogin();
     },
 
     /**

+ 34 - 5
pages/setting/basic.js

@@ -1,6 +1,6 @@
 const app = getApp()
 import WxValidate from '../../utils/wxValidate'
-import { genders } from '../../utils/dict';
+import { gender } from '../../utils/dict';
 Page({
 
     /**
@@ -13,12 +13,12 @@ Page({
         // 头像
         icon: [],
         // 性别
-        genderList: genders,
+        genderList: gender,
     },
     initValidate() {
         const rules = { name: { required: true }, phone: { required: true, tel: true }, gender: { required: false }, email: { required: true } }
         // 验证字段的提示信息,若不传则调用默认的信息
-        const messages = { name: { required: '请输入用户名', }, phone: { required: '请输入手机号', }, gender: { required: '请选择性别', }, status: { required: '请选择状态' } };
+        const messages = { name: { required: '请输入用户名', }, phone: { required: '请输入手机号', }, gender: { required: '请选择性别', }, email: { required: '请输入邮箱' } };
         this.WxValidate = new WxValidate(rules, messages)
     },
     // 返回
@@ -44,14 +44,43 @@ Page({
         const that = this;
         let index = e.detail.value;
         let value = that.data.genderList[index];
-        that.setData({ 'form.gender': value });
+        that.setData({ 'form.gender': value.value });
+    },
+    // 提交登录
+    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) {
+                if (!params.icon) params.icon = that.data.icon;
+                arr = await app.$post(`/newCourt/api/user/${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.$get(`/newCourt/api/user`, { phone: params.phone });
+                if (arr.errcode == '0' && arr.total > 0) wx.showToast({ title: `该账号已有用户使用`, icon: 'error', duration: 2000 })
+                else {
+                    params.icon = that.data.icon;
+                    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: `${error.msg}`, icon: 'error', duration: 2000 })
+                }
+            }
+        }
     },
-
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
         const that = this;
+        //验证规则函数
+        that.initValidate();
         // 监听用户是否登录
         that.watchLogin();
     },

+ 13 - 1
pages/setting/basic.wxml

@@ -2,6 +2,18 @@
     <view slot="info" class="container main">
         <view class="one">
             <form catchsubmit="onSubmit">
+                <view class="content" style="display: none;">
+                    <view class="label">用户id:</view>
+                    <view class="value"><input name="id" value="{{form.id}}" placeholder="请输入用户id" /></view>
+                </view>
+                <view class="content" style="display: none;">
+                    <view class="label">openid:</view>
+                    <view class="value"><input name="openid" value="{{form.openid}}" placeholder="请输入openid" /></view>
+                </view>
+                <view class="content" style="display: none;">
+                    <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="name" value="{{form.name}}" placeholder="请输入用户名" /></view>
@@ -15,7 +27,7 @@
                 <view class="content">
                     <view class="label">性别</view>
                     <view class="value">
-                        <picker name="gender" bindchange="genderChange" value="{{form.gender}}" range="{{genderList}}">
+                        <picker name="gender" bindchange="genderChange" value="{{form.gender}}" range-key='value' range="{{genderList}}">
                             <view class="input">{{form.gender||'选择性别'}}</view>
                         </picker>
                     </view>

+ 69 - 0
pages/setting/contact.js

@@ -0,0 +1,69 @@
+const app = getApp()
+Page({
+
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        frameStyle: { useTop: true, name: '联系我们', leftArrow: true, useBar: false },
+    },
+    // 返回
+    back: function () {
+        wx.navigateBack({ delta: 1 })
+    },
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: function (options) {
+        const that = this;
+
+    },
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload: function () {
+
+    },
+
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
+
+    },
+
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom: function () {
+
+    },
+
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage: function () {
+
+    }
+})

+ 6 - 0
pages/setting/contact.json

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

+ 5 - 0
pages/setting/contact.less

@@ -0,0 +1,5 @@
+.main {
+    height: 88vh;
+    background-color: #ff0000;
+  }
+  

+ 5 - 0
pages/setting/contact.wxml

@@ -0,0 +1,5 @@
+<mobile-main frameStyle="{{frameStyle}}" bind:back="back">
+    <view slot="info" class="container main">
+        联系我们
+    </view>
+</mobile-main>

+ 4 - 0
pages/setting/contact.wxss

@@ -0,0 +1,4 @@
+.main {
+  height: 88vh;
+  background-color: #ff0000;
+}

+ 0 - 2
utils/dict.js

@@ -28,5 +28,3 @@ export const gender = [
     { label: '未知', value: '未知' },
 
 ]
-// 性别
-export const genders = ['男', '女', '未知'];