| | |
| | | // pages/userinfo/index.js |
| | | import { |
| | | uploadUrl, |
| | | editMember, |
| | | getMemberInfo |
| | | } from '../../api/index' |
| | | Page({ |
| | | |
| | | /** |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | imgurl: "", |
| | | imgurlFull: "", |
| | | name: "", |
| | | nickname: "", |
| | | phone: "", |
| | | address: '', |
| | | latitude: '', |
| | | longitude: '', |
| | | district: '', |
| | | housearea: '', |
| | | // 城市。地址 |
| | | region: [], |
| | | address: '' |
| | | |
| | | showHouseType: false, |
| | | houseType: { |
| | | val1: '', |
| | | val2: '', |
| | | val3: '', |
| | | val4: '', |
| | | val5: '', |
| | | } |
| | | }, |
| | | onLoad(options) { |
| | | |
| | | this.initData() |
| | | }, |
| | | onSubmit() { |
| | | |
| | | const { |
| | | imgurl, |
| | | name, |
| | | nickname, |
| | | phone, |
| | | address, |
| | | latitude, |
| | | longitude, |
| | | district, |
| | | housearea, |
| | | houseType |
| | | } = this.data |
| | | if (!nickname) return wx.showToast({ |
| | | title: '请输入昵称', |
| | | icon: 'none' |
| | | }) |
| | | editMember({ |
| | | imgurl: imgurl || '', |
| | | name: name || '', |
| | | nickname: nickname || '', |
| | | phone: phone || '', |
| | | address: address || '', |
| | | latitude: latitude || '', |
| | | longitude: longitude || '', |
| | | district: district || '', |
| | | housearea: housearea || '', |
| | | housetype: houseType.val1 + '-' + houseType.val2 + '-' + houseType.val3 + '-' + houseType.val4 + '-' + houseType.val5 |
| | | }).then(res => { |
| | | 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 || '', |
| | | }) |
| | | }) |
| | | }, |
| | | changeAddr() { |
| | | console.log('点击了'); |
| | | // console.log('点击了'); |
| | | wx.chooseLocation({ |
| | | type: 'wgs84', |
| | | success: (res) => { |
| | | console.log('res', res); |
| | | this.setData({ |
| | | longitude: res.longitude, |
| | | latitude: res.latitude, |
| | | address: res.address, |
| | | }) |
| | | } |
| | | }) |
| | | }, |
| | |
| | | region: e.detail.value |
| | | }) |
| | | }, |
| | | 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() { |
| | | console.log('dianjile'); |
| | | 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) |
| | | 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, |
| | | }) |
| | | setTimeout(() => { |
| | | console.log('imgurlFull', this.data.imgurlFull); |
| | | }, 1000) |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | }, |