import { uploadUrl, editMember, getMemberInfo, getWxMiniPhone } from '../../api/index' Page({ /** * 页面的初始数据 */ data: { imgurl: "", imgurlFull: "", name: "", nickname: "", phone: "", address: '', latitude: '', longitude: '', district: '', housearea: '', addrValues: [], addr: {}, areaData: [], showHouseType: false, houseType: { val1: '', val2: '', val3: '', val4: '', val5: '', } }, 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() { const { imgurl, name, nickname, phone, address, latitude, longitude, district, housearea, houseType, addr } = this.data if (!nickname) return wx.showToast({ title: '请输入昵称', icon: 'none' }) editMember({ ...addr, name: name || '', nickname: nickname || '', phone: phone || '', address: address || '', latitude: latitude || '', 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) wx.showToast({ title: '保存成功', icon: 'none' }) }) }, initData() { getMemberInfo().then(res => { if(res.data.housetype){ const temp = res.data.housetype.split('-') let houseType = { val1: temp[0], val2: temp[1], val3: temp[2], val4: temp[3], val5: temp[4], } this.setData({houseType}) } this.setData({ imgurlFull: res.data.imgurl ? res.data.prefix + res.data.imgurl : '', imgurl: res.data.imgurl, name: res.data.name || '', nickname: res.data.nickname || '', phone: res.data.phone || '', address: res.data.address || '', latitude: res.data.latitude || '', 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, cityCode: res.data.cityCode, cityName: res.data.cityName, areaCode: res.data.areaCode, areaName: res.data.areaName, } }) }) }, 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); } }, // 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({ url: uploadUrl, filePath: e.detail.avatarUrl, formData: { folder: "member" }, name: 'file', success (res) { let data = JSON.parse(res.data) that.setData({ 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({ 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); } }) }, openHouse() { this.setData({ showHouseType: true }) }, onClose() { this.setData({ showHouseType: false }) }, houseBlur(e) { const { str } = e.currentTarget.dataset const { value } = e.detail const houseType = { ...this.data.houseType } houseType[str] = value this.setData({ houseType }) }, selMedia() { wx.chooseMedia({ count: 1, mediaType: ['image'], sourceType: ['album', 'camera'], maxDuration: 16, camera: 'back', success: (res) => { // console.log(res.tempFiles[0].tempFilePath) // console.log(res.tempFiles[0].size) wx.uploadFile({ url: uploadUrl, //仅为示例,非真实的接口地址 filePath: res.tempFiles[0].tempFilePath, name: 'file', formData: { folder: 'member' }, header: { token: wx.getStorageSync('token') }, success: (ress) => { // console.log('ress', JSON.parse(ress.data)); let data = JSON.parse(ress.data) this.setData({ imgurl: data.data.imgaddr, imgurlFull: data.data.url, }) } }) } }) }, onReady() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })