odc.xiaohui
2023-04-06 f05a26bb7e036c3d09c84e295f1b77fdb8d9ba08
miniprogram/pages/user/loginInfo/index.ts
@@ -1,22 +1,55 @@
// index.ts
// 获取应用实例
const loginInfo = getApp() 
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';
import Notify from '../../../miniprogram_npm/@vant/weapp/notify/notify';
let myStyle = `
--color:black;
`
let chageStyle = `
--color:red;
`
Page({
  data: {
      user:{},
    isShow:false,
    pic:null
    pic:null,
    viewData: {
        style: myStyle,
        styleId:myStyle
       }
  },
  getName(e){
      console.log(e.detail.value)
      if(e.detail.value){
        this.setData({'viewData.style': myStyle})
      }
     this.data.user.realName=e.detail.value
  },
  getIdcard(e){
    if(e.detail.value){
        this.setData({'viewData.styleId': myStyle})
      }
    this.data.user.userIdcard=e.detail.value
  },
  getPhoneNumber:function(e){
      console.log(e);
  },
  submit(){
      if(!/^[\u4e00-\u9fa5]{2,4}$/.test(this.data.user.realName)){
        // Toast.fail('请输入正确的姓名');
        Notify({ type: 'warning', message: '请输入正确的姓名' });
        this.setData({'viewData.style': chageStyle})
        return
      }
      if(!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(this.data.user.userIdcard)){
        // Toast.fail('请输入正确的身份证号');
        Notify({ type: 'warning', message: '请输入正确的身份证号' });
        this.setData({'viewData.styleId': chageStyle})
        return
      }
    this.data.user.pic=this.data.pic
    this.data.user.id=wx.getStorageSync('id')
    if ( this.data.user.pic == null||this.data.user.realName==null||  this.data.user.realName==null) {
@@ -26,21 +59,39 @@
        })
        return
    }
    console.log("meizhic")
   wx.request({
       url:loginInfo.globalData.url+"/wx/user/add",
       method:"POST",
       data:this.data.user,
       header:{
           'token':wx.getStorageSync('token')
       },
       success:(res)=>{
           wx.setStorageSync('info',true)
           wx.reLaunch({
               url:'../../user/index'
           })
       }
   })
    wx.request({
                    url: loginInfo.globalData.url+"/wx/login",
                    data: {
                        "phone": wx.getStorageSync('phone'),
                    },
                    method: "GET",
                    success: (res) => {
                        wx.setStorageSync('token', res.data.data.token)
                        wx.setStorageSync('role', res.data.data.role)
                        wx.setStorageSync('id', res.data.data.id)
                        wx.setStorageSync('card',res.data.data.time)
                        console.log(res.data.data.id)
                        this.data.user.id= res.data.data.id
                        wx.setStorageSync('id',res.data.data.id)
                        wx.request({
                            url:loginInfo.globalData.url+"/wx/user/add",
                            method:"POST",
                            data:this.data.user,
                            header:{
                                'token':wx.getStorageSync('token')
                            },
                            success:(res)=>{
                                wx.setStorageSync('info',true)
                                wx.reLaunch({
                                    url:'../../user/index'
                                })
                            }
                        })
                    }
                })
  },
face(){
    wx.chooseMedia({
@@ -54,7 +105,7 @@
                filePath: res.tempFiles[0].tempFilePath,
                name: "file",
                header: {
                    'token': wx.getStorageSync('token'),
                    // 'token': wx.getStorageSync('token'),
                    'content-type': 'application/json'
                },
                success:(res)=>{
@@ -63,6 +114,8 @@
                        pic:result.data,
                        isShow:true
                    })
                      // 成功通知
                    Notify({ type: 'primary', message: '采集成功' });
                }
            })
        }