ll
liukangdong
2024-08-15 ebc6e7ee67f13e7aa311e737dfcb4c5caed112ee
wechat_jiaxuan/pages/userinfo/index.js
@@ -2,7 +2,7 @@
  uploadUrl,
  editMember,
  getMemberInfo,
  getArea
  getWxMiniPhone
} from '../../api/index'
Page({
@@ -21,6 +21,7 @@
    district: '',
    housearea: '',
    
    addrValues: [],
    addr: {},
    areaData: [],
@@ -33,7 +34,19 @@
      val5: '',
    }
  },
  onShow() {
  onLoad() {
    wx.getUserInfo({
      success: function(res) {
        console.log('res', res);
        var userInfo = res.userInfo
        var nickName = userInfo.nickName
        var avatarUrl = userInfo.avatarUrl
        var gender = userInfo.gender //性别 0:未知、1:男、2:女
        var province = userInfo.province
        var city = userInfo.city
        var country = userInfo.country
      }
    })
    this.initData()
  },
  onSubmit() {
@@ -56,7 +69,6 @@
    })
    editMember({
      ...addr,
      imgurl: imgurl || '',
      name: name || '',
      nickname: nickname || '',
      phone: phone || '',
@@ -65,6 +77,7 @@
      longitude: longitude || '',
      district: district || '',
      housearea: housearea || '',
      imgurl: imgurl || null,
      housetype: houseType.val1 + '-' + houseType.val2 + '-' + houseType.val3 + '-' + houseType.val4 + '-' + houseType.val5
    }).then(res => {
      wx.setStorageSync('member', res.data)
@@ -98,6 +111,7 @@
        longitude: res.data.longitude || '',
        district: res.data.district || '',
        housearea: res.data.housearea || '',
        addrValues: [res.data.provinceCode, res.data.cityCode, res.data.areaCode],
        addr: {
          provinceCode: res.data.provinceCode,
          provinceName: res.data.provinceName,
@@ -109,32 +123,40 @@
      })
    })
    getArea().then(res => {
      this.setData({ areaData: res.data })
    })
  },
  positionChange (e) {
    console.log(e.detail.value)
    const names = e.detail.value
    const codes = e.detail.code
    let addr = {
      provinceCode: codes[0] + '00',
      provinceName: names[0],
      cityCode: codes[1] + '00',
      cityName: names[1],
      areaCode: codes[2] + '00',
      areaName: names[2],
    }
    this.setData({ addr })
  regionChange(e) {
    console.log(e)
    if(e.detail.value &&e.detail.value.length ==3){
      var tn = e.detail.label.split("-")
      const addr = {
        provinceCode: e.detail.value[0] ,
        provinceName: tn[0],
        cityCode:  e.detail.value[1] ,
        cityName:  tn[1],
        areaCode: e.detail.value[2] ,
        areaName:  tn[2]
      }
      this.setData({ addr, showAreaList: false })
      console.log('selectedOptions', addr);
    }
  },
  bindRegionChange(e) {
    console.log('picker发送选择改变,携带值为', e.detail.value)
    const temp = e.detail.value
    this.setData({
      region: e.detail.value
    })
  },
  // positionChange (e) {
  //   console.log(e.detail.value)
  //   const names = e.detail.value
  //   const codes = e.detail.code
  //   let addr = {
  //     provinceCode: codes[0] + '00',
  //     provinceName: names[0],
  //     cityCode: codes[1] + '00',
  //     cityName: names[1],
  //     areaCode: codes[2] + '00',
  //     areaName: names[2],
  //   }
  //   this.setData({ addr })
  //   console.log('addr', this.data.addr);
  // },
  getBindchooseavatar(e) {
    console.log('e', e);
    var that = this
    if (e.detail.avatarUrl) {
      wx.uploadFile({
@@ -150,23 +172,38 @@
            imgurl: data.data.imgaddr,
            imgurlFull: data.data.url,
          })
          console.log('imgurlFull', this.data);
        }
      })
    }
  },
  getPhoneNumber (e) {
    const data = { ...e.detail }
    getWxMiniPhone({
      encryptedData: data.encryptedData,
      iv: data.iv,
      sessionKey: wx.getStorageSync('sessionKey') || data.iv,
    }).then(res => {
      this.setData({
        phone: res.data
      })
    })
  },
  getNickName(e) {
    this.setData({ nikname: e.detail.value })
    this.setData({ nickname: e.detail.value })
  },
  changeAddr() {
    // console.log('点击了');
    wx.chooseLocation({
      type: 'wgs84',
      success: (res) => {
        console.log('res', res);
        this.setData({
          longitude: res.longitude,
          latitude: res.latitude,
          address: res.address,
        })
        console.log('address', this.data.address);
      }
    })
  },