Kaynağa Gözat

修改我的信息

zs 1 yıl önce
ebeveyn
işleme
8e67757c47

+ 1 - 0
app.json

@@ -5,6 +5,7 @@
     "pages/calorie/index",
     "pages/reserve/index",
     "pages/my/index",
+    "pages/basic/index",
     "pages/history/index",
     "pages/history/detail",
     "pages/news/index",

+ 80 - 0
pages/basic/index.js

@@ -0,0 +1,80 @@
+// pages/home/index.js
+const app = getApp();
+Page({
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    height: app.globalData.height * 2 + 25,
+    windowHeight: app.globalData.windowHeight,
+    navbarData: {
+      name: '我的信息',
+    },
+    form: {},
+  },
+  // 返回
+  back: function () {
+    wx.switchTab({
+      url: '/pages/my/index',
+    });
+  },
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: async function (options) {
+    if(options.id) {
+      const res = await app.$get(`/user/${options.id}`);
+      this.setData({ form: res.data });
+    } else {
+      wx.switchTab({
+        url: '/pages/login/index',
+      });
+    }
+  },
+  // 保存
+  async formSubmit(e) {
+    const data = e.detail.value
+    let url;
+    if (data._id) url = `/user/${data._id}`;
+    else{
+      data.openid = app.globalData.wxInfo.openid
+      url = `/user`;
+    }
+    const res = await app.$post(url, data);
+    if (res.errcode === 0) wx.showToast({ title: '维护成功', icon: 'success' });
+  },
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {},
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {},
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {},
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {},
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {},
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {},
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {},
+});

+ 5 - 0
pages/basic/index.json

@@ -0,0 +1,5 @@
+{
+  "usingComponents": {
+    "nav-bar": "/commpents/navbar/index"
+  }
+}

+ 40 - 0
pages/basic/index.wxml

@@ -0,0 +1,40 @@
+<nav-bar navbar-data='{{navbarData}}' bind:back="back"></nav-bar>
+<view class="main" style="padding-top:{{height}}px;height:{{windowHeight-height}}px">
+  <form catchsubmit="formSubmit">
+    <view class="form">
+      <view class="section" style="display: none;">
+        <view class="title">_id:</view>
+        <view class="cells">
+          <input class="input" model:value="{{form._id}}" name="_id" placeholder="请输入_id" />
+        </view>
+      </view>
+      <view class="section" style="display: none;">
+        <view class="title">openid:</view>
+        <view class="cells">
+          <input class="input" model:value="{{form.openid}}" name="openid" placeholder="请输入openid" />
+        </view>
+      </view>
+      <view class="section">
+        <view class="title">昵称:</view>
+        <view class="cells">
+          <input type="nickname" class="input" model:value="{{form.nick_name}}" name="nick_name" placeholder="请输入昵称" />
+        </view>
+      </view>
+      <view class="section">
+        <view class="title">电话:</view>
+        <view class="cells">
+          <input type="number" class="input" model:value="{{form.tel}}" name="tel" placeholder="请输入电话" />
+        </view>
+      </view>
+      <view class="section">
+        <view class="title">部门:</view>
+        <view class="cells">
+          <input class="input" model:value="{{form.dept}}" name="dept" placeholder="请输入部门" />
+        </view>
+      </view>
+      <view class="btn">
+        <button size="mini" type="primary" formType="submit">保存</button>
+      </view>
+    </view>
+  </form>
+</view>

+ 18 - 0
pages/basic/index.wxss

@@ -0,0 +1,18 @@
+.main .form {
+  padding: 5px;
+}
+
+.main .form .section {
+  padding: 5px;
+  margin: 0 0 10px 0;
+  border: 1px solid #333333;
+  border-radius: 5px;
+}
+
+.main .form .section .title {
+  padding: 5px 0;
+}
+
+.main .form .btn {
+  text-align: center;
+}

+ 2 - 2
pages/my/index.js

@@ -17,11 +17,11 @@ Page({
     let type = e.currentTarget.dataset.type;
     if (type == '1') {
       wx.redirectTo({
-        url: `/pages/history/index?openid=${app.globalData.wxInfo.openid}`
+        url: `/pages/basic/index?id=${app.globalData.wxInfo._id}`
       })
     } else if (type == '2') {
       wx.redirectTo({
-        url: '/pages/login/index'
+        url: `/pages/history/index?openid=${app.globalData.wxInfo.openid}`
       })
     }
   },

+ 2 - 2
pages/my/index.wxml

@@ -12,7 +12,7 @@
     </view>
   </view>
   <view class="two">
-    <van-cell title="历史记录" is-link bind:click="routeBtn" data-type="1" />
-    <!-- <van-cell title="退出登录" is-link bind:click="routeBtn" data-type="2" /> -->
+    <van-cell title="我的信息" is-link bind:click="routeBtn" data-type="1" />
+    <van-cell title="历史记录" is-link bind:click="routeBtn" data-type="2" />
   </view>
 </view>