Browse Source

个人信息修改与商户注册

zhaoxiaohai 3 years ago
parent
commit
64c2feb774

+ 10 - 4
README.md

@@ -6,12 +6,13 @@
 
 app.js 全局变量
 safeAreaBottom -- iPhone X 等机型底部安全距离适配
-userMsg -- 登录用户信息
+accountList -- 用户角色列表
 
 页面
 login -- 登录和用户注册
 tabbarPage -- tabbar页面
-userPerfectMsg -- 商户信息完善
+userPerfectMsg -- 商户注册信息完善
+userMessage -- 用户个人信息修改
 
 自定义组件:
 My_inform_box -- 通告
@@ -19,5 +20,10 @@ My_inform_item -- 通告项
 My_realTime_display -- 实时展示
 My_operation -- 3列宫格
 My_userRegister -- 个人注册
-My_perfectRegister -- 完善商户信息
-My_moreAccount -- 多账号登录
+My_moreAccount -- 多账号登录
+
+utils文件
+Http.js -- 封装请求
+api.js -- 接口分类
+md5.js -- 验证码加密
+verify.js -- 表单校验

+ 1 - 1
app.js

@@ -12,6 +12,6 @@ App({
   },
   globalData: {
     safeAreaBottom: 0,//底部安全距离
-    userMsg:{},//登录用户信息
+    accountList:{},//角色列表
   }
 })

+ 1 - 1
components/My_moreAccount/index.js

@@ -22,7 +22,7 @@ Component({
     methods: {
         loginAccount(e) {
             //全局储存
-            app.globalData.userMsg = this.data.userList[e.currentTarget.dataset.index];
+            wx.setStorageSync('token', this.data.userList[e.currentTarget.dataset.index].token)
             wx.reLaunch({
                 url: '/pages/tabbarPage/Home/index'
             })

+ 1 - 1
components/My_moreAccount/index.wxml

@@ -1,4 +1,4 @@
 <view class="row" wx:for="{{userList}}" data-index="{{index}}" bindtap="loginAccount">
     <view class="userName">{{item.fname}}</view>
-    <view class="position">{{item.fusertype}}</view>
+    <view class="position">{{item.frole}}</view>
 </view>

+ 55 - 8
components/My_userRegister/index.js

@@ -1,4 +1,7 @@
-// components/My_userRegister/index.js
+import {
+    ApiModel
+} from "../../utils/api"
+const _Http = new ApiModel()
 Component({
     /**
      * 组件的属性列表
@@ -14,26 +17,70 @@ Component({
      */
     data: {
         //用户名
-        userName: String,
+        userName: "",
         //身份职位
-        identity: String,
+        identity: "",
     },
 
     /**
      * 组件的方法列表
      */
     methods: {
+        /* 用户名 */
+        setUserName(e) {
+            this.setData({
+                userName: e.detail.value
+            })
+        },
+        /* 用户身份 */
+        setUsereFole(e) {
+            this.setData({
+                identity: e.detail.value
+            })
+        },
+        /* 设置默认信息并发送请求 */
+        setTacitlyApprove() {
+            let userName = this.data.userName,
+                identity = this.data.identity;
+            /* 设置用户名默认值 */
+            if (userName.length < 1) {
+                const str = this.data.userTelephone.toString();
+                userName = str.substring(str.length - 4, str.length) + "用户"
+            }
+            /* 设置身份/职位默认值 */
+            if (identity < 1) {
+                identity = "管理员";
+            }
+            /* 发送请求 */
+            return _Http.basic({
+                "accesstoken": wx.getStorageSync('token'),
+                "classname": "customer.usercenter.usermsg.usermsg",
+                "method": "update_usermsg",
+                "content": {
+                    "fname": userName,
+                    "fsex": "",
+                    "fbirthdate": "",
+                    "femail": "",
+                    "fwechatno": "",
+                    "faddress": "",
+                    "frole": identity
+                }
+            })
+        },
         /* 下一步,完善商户信息 */
         userPerfectMsg() {
-            // if(this.data.userName.length>2)
-            wx.reLaunch({
-                url: '/pages/userPerfectMsg/index'
+            this.setTacitlyApprove().then(s => {
+                console.log(s)
             })
         },
         /* 跳过,跳转首页 */
         toHomePage() {
-            wx.reLaunch({
-                url: '/pages/tabbarPage/Home/index'
+            this.setTacitlyApprove().then(s => {
+                console.log(s)
+                if (s.msg != "成功") return;
+                wx.reLaunch({
+                    url: '/pages/tabbarPage/Home/index'
+                })
             })
         }
     }

+ 4 - 4
components/My_userRegister/index.wxml

@@ -1,15 +1,15 @@
 <view class="login">
     <view class="login_row">
-        <view class="login_row_title">账户名</view>
-        <input class="login_row_input" type="number" placeholder="用户名" value="{{userName}}" bindblur="inputTelephone" />
+        <view class="login_row_title" bindtap="setTacitlyApprove">账户名</view>
+        <input class="login_row_input" type="number" placeholder="用户名" value="{{userName}}" bindinput="setUserName" />
     </view>
     <view class="login_row">
         <view class="login_row_title">手机号</view>
-        <input class="login_row_input" type="number" value="{{userTelephone}}" disabled bindblur="inputTelephone" />
+        <input class="login_row_input" type="number" value="{{userTelephone}}" disabled />
     </view>
     <view class="login_row">
         <view class="login_row_title" style="margin-left: -48rpx;">身份/职位</view>
-        <textarea class="login_row_input input_textarea" value="{{identity}}"></textarea>
+        <textarea class="login_row_input input_textarea" value="{{identity}}" bindinput="setUsereFole"></textarea>
     </view>
     <view class="login_but">
         <van-button type="info" size="large" bindtap="userPerfectMsg">下一步</van-button>

+ 9 - 8
pages/login/index.js

@@ -59,17 +59,17 @@ Page({
     login() {
         /* 验证号码 */
         if (!this.verifyTelephone(this.data.userTelephone)) return;
-        if (this.data.securityCode.length !== 6) return wx.showToast({
-            title: '请检查验证码',
-            icon: 'none',
-            duration: 2000 //持续的时间
-        })
         _Http.login({
             "phonenumber": this.data.userTelephone,
             "password": utilMd5.hexMD5(this.data.securityCode)
         }).then(s => {
             console.log(s)
-            if (s.msg != "成功") return
+            if (s.msg != "成功") return wx.showToast({
+                title: s.msg,
+                icon: 'none',
+                duration: 2000 //持续的时间
+            })
+            getApp().globalData.accountList = s.account_list;
             if (s.account_list.length >= 2) {
                 console.log("多账号")
                 this.setData({
@@ -77,13 +77,14 @@ Page({
                     userList: s.account_list
                 })
             } else if (s.account_list[0].isnewregister == 1) {
-                getApp().globalData.userMsg = s.account_list[0];
                 console.log("新账号")
+                wx.setStorageSync('token', s.account_list[0].token);
                 this.setData({
                     pageType: 1
                 })
             } else {
-                getApp().globalData.userMsg = s.account_list[0];
+                console.log("单账号")
+                wx.setStorageSync('token', s.account_list[0].token);
                 wx.reLaunch({
                     url: "/pages/tabbarPage/Home/index"
                 })

+ 3 - 3
pages/login/index.wxml

@@ -1,12 +1,12 @@
-<!-- 登录 -->
+<!-- 登录页面 --> <!-- pageType 0-登录,1-新用户注册,2多账号选择 -->
 <view class="login" wx:if="{{pageType==0}}">
     <view class="login_row">
         <view class="login_row_title">手机号</view>
-        <input class="login_row_input" type="number" placeholder="输入手机号" value="{{userTelephone}}" bindblur="inputTelephone" />
+        <input class="login_row_input" type="number" placeholder="输入手机号" value="{{userTelephone}}" bindinput="inputTelephone" />
     </view>
     <view class="login_row">
         <view class="login_row_title">验证码</view>
-        <input class="login_row_input" type="number" placeholder="输入验证码" value="{{securityCode}}" bindblur="inputVerify" />
+        <input class="login_row_input" type="number" placeholder="输入验证码" value="{{securityCode}}" bindinput="inputVerify" />
         <view class="input_but" bindtap="getSecurityCode">
             获取验证码
         </view>

+ 1 - 1
pages/tabbarPage/Home/index.js

@@ -52,7 +52,7 @@ Page({
      * 生命周期函数--监听页面加载
      */
     onLoad: function () {
-        console.log(app.globalData.userMsg.token);
+        console.log(getApp().globalData.accountList.token);
     },
 
     /**

+ 1 - 0
pages/tabbarPage/Home/index.wxml

@@ -1,3 +1,4 @@
+<!-- tabbar--Home -->
 <view style="padding-bottom:{{safeAreaBottom+140}}rpx;">
     <!-- 轮播图 -->
     <swiper class="home_banner" autoplay circular indicator-dots indicator-color="#CCCCCC" indicator-active-color="#FFFFFF">

+ 20 - 7
pages/tabbarPage/User/index.js

@@ -1,6 +1,8 @@
-const app = getApp()
+import {
+    ApiModel
+} from '../../../utils/api'
+const _Http = new ApiModel();
 Page({
-
     /**
      * 页面的初始数据
      */
@@ -12,14 +14,12 @@ Page({
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
-        this.setData({
-            userMsg: app.globalData.userMsg
-        })
     },
-    /* 跳转个人信息 */
+    /* 跳转修改信息 */
     toUserMsg() {
+        const data = JSON.stringify(this.data.userMsg)
         wx.navigateTo({
-            url: '/pages/userMessage/index',
+            url: '/pages/userMessage/index?data=' + data
         })
     },
     /**
@@ -34,6 +34,19 @@ Page({
      */
     onShow: function () {
         this.getTabBar().init();
+        
+        /* 获取个人信息 */
+        _Http.basic({
+            "accesstoken": wx.getStorageSync('token'),
+            "classname": "customer.usercenter.usermsg.usermsg",
+            "method": "query_usermsg",
+            "content": {}
+        }).then(s => {
+            if (s.msg != "成功") return;
+            this.setData({
+                userMsg: s.data[0]
+            })
+        })
     },
 
     /**

+ 4 - 0
pages/tabbarPage/User/index.wxml

@@ -1,13 +1,17 @@
+<!-- tabbar--个人 -->
 <view class="user_box">
+  <!-- 用户头像 -->
   <view class="user_img">
     <!-- <image></image> -->
   </view>
+  <!-- 用户文字信息 -->
   <view class="user_text" bindtap="toUserMsg">
     <view class="user_name">{{userMsg.fname}} <text class="gray">{{userMsg.fusertype}}</text></view>
     <view class="user_number gray">{{userMsg.fphonenumber}}</view>
     <van-icon class="user_icon" name="arrow" />
   </view>
 </view>
+<!-- 功能列表 -->
 <van-cell-group>
   <van-cell title="商品管理" is-link size="large" icon="shop-o" />
   <van-cell title="产品管理" is-link size="large" icon="points" />

+ 29 - 35
pages/userMessage/index.js

@@ -8,60 +8,54 @@ Page({
      * 页面的初始数据
      */
     data: {
-        fname: null, //用户名
-        frole: null, //角色
-        fphonenumber: null, //手机号
-        fsex: null, //性别
-        fbirthdate: null, //生日
-        femail: null, //邮箱
-        fwechatno: null, //微信
-        faddress: null, //地址
+        fname: "", //用户名
+        frole: "", //角色
+        fphonenumber: "", //手机号
+        fsex: "", //性别
+        fbirthdate: "", //生日
+        femail: "", //邮箱
+        fwechatno: "", //微信
+        faddress: "", //地址
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
-        _Http.basic({
-            "accesstoken": getApp().globalData.userMsg.token,
-            "classname": "customer.usercenter.usermsg.usermsg",
-            "method": "query_usermsg",
-            "content": {}
-        }).then(s => {
-            if (s.msg != "成功") return;
-            this.setData({
-                fname: s.data[0].fname,
-                frole: s.data[0].frole,
-                fsex: s.data[0].fsex,
-                fbirthdate: s.data[0].fbirthdate,
-                femail: s.data[0].femail,
-                fwechatno: s.data[0].fwechatno,
-                faddress: s.data[0].faddress,
-                frole: s.data[0].frole,
-                faddress: s.data[0].faddress,
-                fphonenumber: s.data[0].fphonenumber,
-            })
+        const data = JSON.parse(options.data)
+        this.setData({
+            fname: data.fname,
+            frole: data.frole,
+            fsex: data.fsex,
+            fbirthdate: data.fbirthdate,
+            femail: data.femail,
+            fwechatno: data.fwechatno,
+            faddress: data.faddress,
+            frole: data.frole,
+            faddress: data.faddress,
+            fphonenumber: data.fphonenumber,
         })
     },
     /* 表单提交 */
     formSubmit() {
         _Http.basic({
-            "accesstoken": getApp().globalData.userMsg.token,
+            "accesstoken": wx.getStorageSync('token'),
             "classname": "customer.usercenter.usermsg.usermsg",
             "method": "update_usermsg",
             "content": {
                 fname: this.data.fname,
-                frole: this.data.frole, 
-                fsex: this.data.fsex, 
-                fbirthdate: this.data.fbirthdate, 
-                femail: this.data.femail, 
-                fwechatno: this.data.fwechatno, 
-                faddress: this.data.faddress, 
+                frole: this.data.frole,
+                fsex: this.data.fsex,
+                fbirthdate: this.data.fbirthdate,
+                femail: this.data.femail,
+                fwechatno: this.data.fwechatno,
+                faddress: this.data.faddress,
             }
         }).then(s => {
+            console.log(s)
             if (s.msg != "成功") return;
             wx.showToast({
-              title: '保存成功',
+                title: '保存成功',
             })
             this.setData({
                 userMsg: s.data[0]

+ 2 - 1
pages/userMessage/index.wxml

@@ -1,8 +1,9 @@
+<!-- 用户修改信息页面 -->
 <view class="head">
   <view class="user_img"></view>
   <view class="change_img">修改头像</view>
 </view>
-<van-cell-group><!-- fname -->
+<van-cell-group>
   <van-field model:value="{{ fname }}" required clearable label="用户名" placeholder="点击填写" input-align="right" size="large" />
   <van-field model:value="{{ frole }}" required clearable label="身份/职位" placeholder="点击选择" input-align="right" size="large" />
   <van-field model:value="{{ fphonenumber }}" required clearable label="手机" disabled placeholder="点击填写" input-align="right" size="large" />

+ 76 - 27
pages/userPerfectMsg/index.js

@@ -1,11 +1,15 @@
-// pages/userPerfectMsg/index.js
+//引入文本校验
+import {
+    TestVerify
+} from "../../utils/verify"
+const _Verify = new TestVerify()
 Page({
-
     /**
      * 页面的初始数据
      */
     data: {
         brandName: "", //品牌名称
+        classify: "", //经营类目
         contact: "", //联系人
         telephone: "", //电话号
         companyName: "", //公司名称
@@ -13,6 +17,15 @@ Page({
         companyAddress: "", //公司地址
         userCode: "", //统一社会编码
         fileList: "", //logo
+        //必填项状态 是否红色字体
+        ErrRed: {
+            brandNameErrRed:false,//品牌名
+            logoErrRed: false, //logo
+            classifyErrRed: false,//经营类目
+            contactErrRed: false,//联系人
+            telephoneErrRed: false, //联系方式
+        },
+        telephoneErrTitle: "", //手机号错误提示
     },
 
     /**
@@ -20,35 +33,71 @@ Page({
      */
     onLoad: function (options) {
 
+    },
+    /* 必填项,获得焦点更新状态 */
+    isInputFocus(e) {
+        let data = this.data.ErrRed;
+        data[e.currentTarget.dataset.name] = false;
+        this.setData({
+            ErrRed: data
+        })
+    },
+    /* 必填项,失去焦点更新状态 */
+    isInputBlur(e) {
+        let data = this.data.ErrRed;
+        data[e.currentTarget.dataset.name] = true;
+        this.setData({
+            ErrRed: data
+        })
+    },
+    //联系方式失去焦点校验
+    inputTelephoneBlur(e) {
+        if (!_Verify.phoneNumber(this.data.telephone)) {
+            let data = this.data.ErrRed;
+            data[e.currentTarget.dataset.name] = true;
+            this.setData({
+                telephoneErrTitle: "手机号格式错误",
+                ErrRed: data
+            })
+            return
+        }
+        this.setData({
+            telephoneErrTitle: "",
+        })
     },
     afterRead(event) {
-        const {
-            file
-        } = event.detail;
+        console.log(event)
         // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
-/*         wx.uploadFile({
-            url: 'https://example.weixin.qq.com/upload', // 仅为示例,非真实的接口地址
-            filePath: file.url,
-            name: 'file',
-            formData: {
-                user: 'test'
-            },
-            success(res) {
-                // 上传完成需要更新 fileList
-                const {
-                    fileList = []
-                } = this.data;
-                fileList.push({
-                    ...file,
-                    url: res.data
-                });
-                this.setData({
-                    fileList
-                });
-            },
-        }); */
+        /*         wx.uploadFile({
+                    url: 'https://example.weixin.qq.com/upload', // 仅为示例,非真实的接口地址
+                    filePath: file.url,
+                    name: 'file',
+                    formData: {
+                        user: 'test'
+                    },
+                    success(res) {
+                        // 上传完成需要更新 fileList
+                        const {
+                            fileList = []
+                        } = this.data;
+                        fileList.push({
+                            ...file,
+                            url: res.data
+                        });
+                        this.setData({
+                            fileList
+                        });
+                    },
+                }); */
+    },
+    /* 完善设置商户信息 */
+    setUserMsg() {
+        // _Verify.userName(this.data.brandName)
+        // _Verify.phoneNumber(this.data.telephone)
+        // console.log(_Verify.phoneNumber(this.data.telephone))
+        _Verify.required(this.data.classify) //经营类目
+
     },
-    /* 跳过,跳转首页 */
     toHomePage() {
         wx.reLaunch({
             url: '/pages/tabbarPage/Home/index'

+ 8 - 6
pages/userPerfectMsg/index.wxml

@@ -1,27 +1,29 @@
+<!-- 新用户注册完善商户信息页面 -->
 <van-cell-group>
-  <van-field model:value="{{ brandName }}" required clearable label="品牌名" placeholder="点击填写" input-align="right" size="large" />
+  <van-field model:value="{{ brandName }}" required clearable label="品牌名" placeholder="点击填写" input-align="right" size="large" bindfocus="isInputFocus" bindblur="isInputBlur" data-name="brandNameErrRed" error="{{ErrRed.brandNameErrRed&&!brandName}}" />
   <view class="logo_box">
     <view class="logo_con">
       <view class="logo_con_title">
         <text class="">*</text>品牌logo
       </view>
       <view class="logo_up">
-        <van-uploader file-list="{{ fileList }}" max-count="1" bind:after-read="afterRead" accept="image" deletable="{{ true }}"/>
+        <van-uploader file-list="{{ fileList }}" max-count="1" bind:after-read="afterRead" accept="image" deletable="{{ true }}" />
       </view>
     </view>
   </view>
   <!--  <van-field>
   </van-field> -->
-  <van-field required clearable label="经营类目" placeholder="点击选择" input-align="right" size="large" />
-  <van-field model:value="{{ contact }}" required clearable label="联系人" placeholder="点击填写" input-align="right" size="large" />
-  <van-field model:value="{{ telephone }}" required clearable label="联系方式" placeholder="点击填写" input-align="right" size="large" />
+  <van-field model:value="{{ classify }}" required clearable label="经营类目" placeholder="点击选择" input-align="right" size="large" bindfocus="isInputFocus" bindblur="isInputBlur" data-name="classifyErrRed" error="{{ErrRed.classifyErrRed&&!classify}}" />
+  <van-field model:value="{{ contact }}" required clearable label="联系人" placeholder="点击填写" input-align="right" size="large" bindfocus="isInputFocus" bindblur="isInputBlur" data-name="contactErrRed" error="{{ErrRed.contactErrRed&&!contact}}" />
+  <van-field model:value="{{ telephone }}" error-message="{{telephoneErrTitle}}" error="{{ErrRed.telephoneErrRed}}" required clearable label="联系方式" placeholder="点击填写" input-align="right" size="large" data-name="telephoneErrRed" bindblur="inputTelephoneBlur" bindfocus="isInputFocus" />
   <van-field model:value="{{ companyName }}" clearable label="注册公司名" placeholder="点击填写" input-align="right" size="large" />
   <van-field model:value="{{ companyIntroduce }}" clearable label="公司介绍" placeholder="点击填写" input-align="right" size="large" />
   <van-field model:value="{{ companyAddress }}" clearable label="地址" placeholder="点击填写" input-align="right" size="large" />
   <van-field model:value="{{ userCode }}" clearable label="统一社会代码" placeholder="点击填写" input-align="right" size="large" />
 </van-cell-group>
+<!-- -->
 <view class="login_but">
-  <van-button type="info" size="large" bindtap="userPerfectMsg">立即创建</van-button>
+  <van-button type="info" size="large" bindtap="setUserMsg">立即创建</van-button>
 </view>
 
 <view class="jumpOver" bindtap="toHomePage">跳过</view>

+ 12 - 0
project.private.config.json

@@ -41,6 +41,18 @@
                     "pathName": "pages/userMessage/index",
                     "query": "",
                     "scene": null
+                },
+                {
+                    "name": "用户",
+                    "pathName": "pages/tabbarPage/User/index",
+                    "query": "",
+                    "scene": null
+                },
+                {
+                    "name": "商户注册",
+                    "pathName": "pages/userPerfectMsg/index",
+                    "query": "",
+                    "scene": null
                 }
             ]
         }

+ 1 - 1
utils/api.js

@@ -16,7 +16,7 @@ class ApiModel extends HTTP {
             data
         })
     }
-    /* 个人信息,修改个人信息, */
+    /* 查询个人信息,修改个人信息,商户信息调整申请 */
     basic(data) {
         return this.request({
             url: "",

+ 2 - 2
utils/util.js

@@ -1,4 +1,4 @@
-const formatTime = date => {
+/* const formatTime = date => {
   const year = date.getFullYear()
   const month = date.getMonth() + 1
   const day = date.getDate()
@@ -16,4 +16,4 @@ const formatNumber = n => {
 
 module.exports = {
   formatTime
-}
+} */

+ 48 - 0
utils/verify.js

@@ -0,0 +1,48 @@
+class TestVerify {
+    /* 用户名校验 */
+    userName(name) {
+        if (name == "") {
+            wx.showToast({
+                title: '用户名不可为空!',
+                icon: 'none'
+            })
+            return false;
+        } else if (name.length < 2 || name.length > 8) {
+            wx.showToast({
+                title: '用户名在6-8位之间',
+                icon: 'none'
+            })
+            return false;
+        };
+        return true;
+    }
+
+    /* 手机号校验 */
+    phoneNumber(number, title) {
+        //校验格式
+        const regMobile = /^(0|86\17951)?(13[0-9]|15[0123456789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
+        if (!regMobile.test(number)) {
+            if (title) wx.showToast({
+                title: '请输入正确手机号码',
+                icon: 'none',
+            })
+            return false;
+        }
+        return true;
+    }
+
+    /* 必填项目/附件是否上传校验 */
+    required(value, title) {
+        if (value.length <= 1) {
+            if (title) wx.showToast({
+                title: title,
+                icon: 'none'
+            })
+            return false;
+        }
+        return true;
+    }
+}
+export {
+    TestVerify
+}