// pages/more/delivery_address/delivery_address.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
  /**
 * 生命周期函数--监听页面显示
 */
  onShow: function () {
    var that = this;
    return false;
    that.getAddressList(that);
  },
  //获取收货地址
  getAddressList: function(that){
    wx.request({
      url: app.globalData.hostname + 　'',
      data: { id: id },
      header: { 'content-type': 'application/json' },
      method: 'GET',
      dataType: 'json',
      success: function(addRes) {
        var addressList = [];
        if (addRes.data.code == 200){
          addressList = addRes.data.data
        }
        that.setData({
          addressList: addressList
        })
      },
      fail: function (addRes) {},
      complete: function (addRes) {},
    })
  },
  //添加新地址
  addNewAddress: function(e){
    wx.navigateTo({
      url: '../new_delivery_address/new_delivery_address?ptype=add',
    })
  },
  //设置默认地址
  setDefaultAddress: function(e){
    var that = this;
    var default_id = e.currentTarget.dataset.default_id;
    that.setData({
      default_id: default_id
    })
  },
  // 编辑地址
  editAddress: function(e){
    var name = '李锋', region = ['广东省','深圳市','龙华新区'],phone = '15180177860',address_detail = '淘金地大厦';
    var dataUrl = 'name=' + name + "&region=" + region + 　"&phone=" + phone + "&address_detail=" + address_detail;
    wx.navigateTo({
      url: '../new_delivery_address/new_delivery_address?ptype=edit&' + dataUrl,
    })
  },
  // 删除地址
  deleteAddress: function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '温馨提示',
      content: '确定要删除该收货地址吗?',
      success: function(res){
        if (res.confirm){
          //删除代码
          return false;
          wx.request({
            url: app.globalData.hostname +　'',
            data: {id:id},
            header: {'content-type': 'application/json'},
            method: 'GET',
            dataType: 'json',
            success: function(delRes) {
              var delToastTitle;
              if(delRes.data.code == 200){
                that.getAddressList(that);
                delToastTitle = '删除成功';
              }else {
                delToastTitle = '删除失败';
              }
              wx.showToast({
                title: delToastTitle,
                duration: 1500
              })
            },
            fail: function (delRes) {},
            complete: function (delRes) {},
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },


})