// page/component/new-pages/user/address/address.js
Page({
  data:{
    address:{
      name:'',
      phone:'',
      detail:''
    }
  },
  onLoad(){
    var self = this;
    // 获取地址信息
    wx.request({
      url: 'http://localhost:8080/getAddress',
      method: 'POST',
      data: {
        
      },
      success(res) {
        self.setData({
          address: res.data
        });
      }
    });
    wx.getStorage({
      key: 'address',
      success: function(res){
        self.setData({
          address : res.data
        })
      }
    })
  },
  formSubmit(e){
    const value = e.detail.value;
    if (value.name && value.phone && value.detail){
      //保存地址
      wx.request({
        url: 'http://localhost:8080/addAdress',
        method: 'POST',
        data: {
          name : value.name,
          phone: value.phone,
          address: value.detail
        },
        success(res) {
          console.log(res)
        }
      });
      wx.setStorage({
        key: 'address',
        data: value,
        success(){
          wx.navigateBack();
        }
      })
    }else{
      wx.showModal({
        title:'提示',
        content:'请填写完整资料',
        showCancel:false
      })
    }
  }
})