| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- // pages/personalInformation/personalInformation.js
- const api = require('../../api/index')
- const app = getApp()
- const upload = require('../../utils/upload')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- userinfo:{},
- imgHttp:app.globalData.imghttp,
- show:false,
- fieldMessage:{}
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getUserinfo()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 页面功能
- */
- //获取用户信息
- getUserinfo(){
- api.selectPerson({},false).then(res=>{
- if(res.code == 200){
- this.setData(
- {
- userinfo:res.data
- }
- )
- }
- })
- },
- //更新用户信息
- editMessage(field,value){
- var params = {}
- params[field] = value
- api.editPerson(params).then(res=>{
- if(res.code == 200){
- this.setData(
- {
- ["userinfo."+field]:value
- }
- )
- this.onClose()
- var pages = getCurrentPages()
- var currentPage = pages[pages.length - 2]
- currentPage.setData(
- {
- ["userinfo."+field]:value
- }
- )
- }
- })
- },
- //获取用户信息
- getUserInfo(e){
- console.log(e)
- var url = e.detail.avatarUrl
- this.setData(
- {
- ["userinfo.avatarUrl"]:url
- }
- )
- upload.upload(url).then(res=>{
- if(res.code == 200){
- this.editMessage('fileGuid',res.data[0])
- }
- })
-
- },
- //栏位值修改
- fieldEdit(e){
- console.log(e)
- var {field,label} = e.currentTarget.dataset
- var value = this.data.userinfo[field] || ''
- this.setData(
- {
- fieldMessage:{
- field:field,
- label:label,
- value:value
- },
- show:true
- }
- )
- },
- //关闭
- onClose(){
- this.setData(
- {
- show:false,
- fieldMessage:{},
- }
- )
- },
- //清空输入框
- clearInput(e){
- this.setData(
- {
- ["fieldMessage.value"]:''
- }
- )
- },
- //获取输入框的值
- changeInput(e){
- var value = e.detail.value
- this.setData(
- {
- ["fieldMessage.value"]:value
- }
- )
- },
- //保存
- saveMessage(){
- var field = this.data.fieldMessage.field
- var value = this.data.fieldMessage.value
- this.editMessage(field,value)
- },
- //退出登录
- logout(){
- api.logout().then(res=>{
- if(res.code == 200){
- this.setData(
- {
- isLogin:false
- }
- )
- wx.setStorageSync('token', '')
- wx.navigateBack()
- }
- })
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|