zhaoxiaohai vor 2 Jahren
Ursprung
Commit
b53e25d930

+ 8 - 3
pages/tabbar/mine/index.js

@@ -5,6 +5,7 @@ Page({
      * 页面的初始数据
      */
     data: {
+        userMsg: {},
         pathList: [{
             name: "团队管理",
             icon: "icon-a-wodetuanduiguanli",
@@ -45,7 +46,6 @@ Page({
             })
         })
     },
-
     /**
      * 生命周期函数--监听页面初次渲染完成
      */
@@ -108,9 +108,14 @@ Page({
         })
     },
     /* 去修改用户信息 */
-    toChangeUserMsg() {
+    changeUserMsg() {
+        let {
+            name,
+            phonenumber,
+            attinfos
+        } = this.data.userMsg;
         wx.navigateTo({
-            url: './userMsg/index'
+            url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}`
         })
     },
     listClick(e) {

+ 2 - 3
pages/tabbar/mine/index.wxml

@@ -1,6 +1,6 @@
 <view class="user-box">
-    <My_card custom-class='user-con' hover bindtap="toChangeUserMsg">
-        <van-image image-class="v-img" round width="128rpx" height="128rpx" src="https://img.yzcdn.cn/vant/cat.jpeg" />
+    <My_card custom-class='user-con' hover bindtap="changeUserMsg">
+        <van-image image-class="v-img" round width="128rpx" height="128rpx" src="{{userMsg.attinfos[0].url||'/static/image/user.png'}}" />
         <view class="user-msg">
             <view class="user-name">
                 {{userMsg.name}}<text>店长</text>
@@ -35,7 +35,6 @@
                 </view>
                 <van-icon size='30rpx' name="arrow" />
             </view>
-
         </view>
     </navigator>
 </My_card>

+ 142 - 71
pages/tabbar/mine/userMsg/index.js

@@ -1,10 +1,13 @@
-// pages/tabbar/mine/userMsg/index.js
+let time = null;
+const _Http = getApp().globalData.http;
+const MD5 = require('../../../../utils/md5');
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
+        attinfos: [],
         fromList1: [{
             label: "姓名",
             error: false,
@@ -12,102 +15,170 @@ Page({
             type: "text",
             value: "",
             placeholder: "请填写",
-            valueName: "username", //绑定的字段名称
+            valueName: "name", //绑定的字段名称
             required: true, //必填
         }, {
-            label: "性别",
+            label: "手机号",
             error: false,
             errMsg: "",
             type: "text",
             value: "",
             placeholder: "请填写",
-            valueName: "gender", //绑定的字段名称
+            valueName: "phonenumber", //绑定的字段名称
             required: true, //必填
-        }, {
-            label: "生日",
-            error: false,
-            errMsg: "",
-            type: "date",
-            value: "",
-            placeholder: "请填写",
-            valueName: "birthday", //绑定的字段名称
-            required: true, //必填
-        }]
+            callback: null,
+        }],
+        disabled: false, //禁用按钮
+        show: false, //显示验证码输入框
+        password: "", //验证码
+        countDown: 0, //倒计时
+        loading: false
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
-    onLoad(options) {},
+    onLoad(options) {
+        const that = this;
+        this.setData({
+            attinfos: JSON.parse(options.attinfos),
+            "fromList1[0].value": options.name,
+            "fromList1[1].value": options.phonenumber,
+            "fromList1[1].callback": function ({
+                value
+            }) {
+                that.setData({
+                    show: (value != that.data.copyPhonenumber) ? true : false,
+                    newPhone: value
+                })
+            },
+            "copyPhonenumber": options.phonenumber
+        })
+    },
     /* from1监听 */
     form1CompletedOrNot({
         detail
     }) {
         this.setData({
-            form1Complete: detail
+            disabled: !detail
+        })
+        if (this.data.show) this.setData({
+            disabled: this.data.password.length == 6
         })
     },
-    /* from2监听 */
-    form2CompletedOrNot({
-        detail
-    }) {
-        this.setData({
-            form1Complete: detail
+    /* 开始倒计时 */
+    startCountDown() {
+        let countDown = this.data.countDown;
+        if (countDown != 0) return wx.showToast({
+            title: '已发送验证码,请勿重新发送',
+            icon: "none"
+        });
+        if (this.data.newPhone.trim().length != 11) return wx.showToast({
+            title: '请输入正常手机号码',
+            icon: "none"
+        })
+        _Http.basic({
+            "classname": "common.usercenter.usercenter",
+            "method": "updateUserMsg_getPassWord",
+            "content": {
+                "phonenumber": this.data.newPhone.trim()
+            }
+        }).then(res => {
+            console.log(res)
+            wx.showToast({
+                title: res.msg,
+                icon: "none"
+            })
+            if (res.code != 1) return;
+            this.setData({
+                countDown: 30
+            })
+            time = setInterval(() => {
+                if (this.data.countDown == '0') return clearInterval(time);
+                this.setData({
+                    countDown: this.data.countDown - 1
+                })
+            }, 1000);
         })
     },
     /* 提交 */
     submit() {
-        let a1 = this.selectComponent("#form1").getData();
-        console.log({
-            ...a1.returnData
+        if (this.data.disabled || this.data.loading) return;
+        let data = this.selectComponent("#form1").getData().returnData;
+        if (data.phonenumber.length != 11) return wx.showToast({
+            title: '请输入正常手机号码',
+            icon: "none"
+        });
+        if (this.data.show && this.data.password.length == 0) return wx.showToast({
+            title: '请输入短信验证码',
+            icon: "none"
+        });
+        this.setData({
+            loading: true
+        })
+        _Http.basic({
+            "classname": "common.usercenter.usercenter",
+            "method": "updateUserMsg",
+            "content": {
+                "name": data.name,
+                "phonenumber": data.phonenumber,
+                "password": MD5.hexMD5(this.data.password.trim())
+            }
+        }).then(res => {
+            this.setData({
+                loading: false
+            })
+            if (res.code != 1) return wx.showToast({
+                title: res.msg,
+                icon: "none"
+            });
+            wx.showToast({
+                title: '修改成功'
+            });
+            this.changeUserMsg();
+            setTimeout(() => {
+                wx.navigateBack({
+                    delta: 0,
+                })
+            }, 300);
         })
     },
-    /**
-     * 生命周期函数--监听页面初次渲染完成
-     */
-    onReady() {
-
-    },
-
-    /**
-     * 生命周期函数--监听页面显示
-     */
-    onShow() {
-
-    },
-
-    /**
-     * 生命周期函数--监听页面隐藏
-     */
-    onHide() {
-
-    },
-
-    /**
-     * 生命周期函数--监听页面卸载
-     */
-    onUnload() {
-
+    changeUserMsg() {
+        let pages = getCurrentPages();
+        let prevPage = pages[pages.length - 2];
+        prevPage.queryUserMsg();
     },
-
-    /**
-     * 页面相关事件处理函数--监听用户下拉动作
-     */
-    onPullDownRefresh() {
-
-    },
-
-    /**
-     * 页面上拉触底事件的处理函数
-     */
-    onReachBottom() {
-
+    changeUserImage({
+        detail
+    }) {
+        _Http.basic({
+            "classname": "system.attachment.Attachment",
+            "method": "createFileLink",
+            "content": {
+                "ownertable": "sys_users",
+                "ownerid": wx.getStorageSync('userMsg').userid,
+                "usetype": "headportrait",
+                "attachmentids": detail
+            }
+        }).then(res => {
+            console.log(res)
+            if (res.msg != '成功') return wx.showToast({
+                title: res.data,
+                icon: "none"
+            })
+            let attinfos = this.data.attinfos;
+            if (attinfos[0]) _Http.basic({
+                "classname": "system.attachment.Attachment",
+                "method": "deleteFileLink",
+                "content": {
+                    "linksids": [attinfos[0].linksid]
+                }
+            });
+            attinfos = res.data;
+            this.setData({
+                attinfos
+            })
+            this.changeUserMsg();
+        })
     },
-
-    /**
-     * 用户点击右上角分享
-     */
-    onShareAppMessage() {
-
-    }
 })

+ 4 - 1
pages/tabbar/mine/userMsg/index.json

@@ -1,6 +1,9 @@
 {
     "navigationBarTitleText": "个人信息",
     "usingComponents": {
-        "My_form": "/components/My_form/index"
+        "My_form": "/components/My_form/index",
+        "van-cell-group": "@vant/weapp/cell-group/index",
+        "van-field": "@vant/weapp/field/index",
+        "My_upload": "/components/My_upload/index"
     }
 }

+ 19 - 19
pages/tabbar/mine/userMsg/index.wxml

@@ -1,24 +1,24 @@
 <!-- 头像 -->
-<navigator url="#" class="picture">
-    <view class="label">头像</view>
-    <view class="picture_right">
-        <image class="user-img" src="https://img01.yzcdn.cn/vant/cat.jpeg"></image>
-        <van-icon size='30rpx' name="arrow" />
-    </view>
-</navigator>
-<view style="height: 20rpx;" />
-<My_form id='form1' fromList='{{fromList1}}' bindCompletedOrNot='form1CompletedOrNot' />
-<!-- 职务 -->
-<view class="duty-box">
-    <view class="con">
-        <view class="duty-name">职务</view>
-        <view class="job">总监</view>
-    </view>
-</view>
-<view style="height: 20rpx;" />
-<My_form id='form1' fromList='{{fromList1}}' bindCompletedOrNot='form1CompletedOrNot' />
+<My_upload maxCount='1' accept='image' bind:uploadCallback='changeUserImage'>
+    <navigator url="#" class="picture">
+        <view class="label">头像</view>
+        <view class="picture_right">
+            <image class="user-img" src="{{attinfos[0].url||'/static/image/user.png'}}"></image>
+            <van-icon size='30rpx' name="arrow" />
+        </view>
+    </navigator>
+</My_upload>
 
+<view style="height: 20rpx;" />
 
+<My_form id='form1' fromList='{{fromList1}}' bindCompletedOrNot='form1CompletedOrNot' />
+<van-cell-group wx:if="{{show}}">
+    <van-field model:value="{{ password }}" required center clearable label="短信验证码" placeholder="请输入短信验证码" border="{{ false }}" use-button-slot>
+        <van-button slot="button" size="small" color='var(--assist)' bindtap="startCountDown">
+            {{countDown==0?'发送验证码':countDown+'s'}}
+        </van-button>
+    </van-field>
+</van-cell-group>
 <view style="width: 100%;text-align: center;">
-    <van-button custom-class='save-but' color="var(--warning)">保存</van-button>
+    <van-button custom-class='save-but' disabled='{{disabled}}' loading="{{loading}}" loading-text="保存中..." color="var(--warning)" bindtap="submit">保存</van-button>
 </view>

BIN
static/image/user.png