dizhibox.js 2.8 KB
// pages/dizhibox/dizhibox.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    addresslist: [],
    deladdress: false,
    delid: '',
    addrestype: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (options.addrestype != undefined) {
      this.setData({
        addrestype: options.addrestype
      })
    }

    this.getaddresslist()
  },

  //获取收货地址
  getaddresslist() {
    let that = this;
    var url = 'take/get_all';
    var params = {
      token: wx.getStorageSync('token'),

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        addresslist: res
      })



    }).catch((err) => {

    })

  },
  adddizhi() {
    wx.redirectTo({
      url: '/pages/addaddress/addaddress?type=' + 1,
    })
  },
  seladdress(e) {
    if (this.data.addrestype == 1) {
      let item = e.currentTarget.dataset.item
      let pages = getCurrentPages();

      // let currPage = pages[pages.length - 1]; //当前页面
      let prevPage = pages[pages.length - 2]; //上一个页面

      //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
      prevPage.setData({
        addresstext: item,
        addresstype: 2
      });
      wx.navigateBack({
        checked: true
      })
    }

  },



  // 编辑地址
  edit(e) {
    console.log(e)
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/addaddress/addaddress?id=' + id + '&type=' + 2,
    })

  },

  //删除地址
  deladdress(e) {
    let id = e.currentTarget.dataset.id;
    this.setData({
      delid: id,
      deladdress: true
    })
  },
  cancelorder() {
    this.setData({
      deladdress: false
    })
  },
  suredel() {
    let that = this;
    var url = 'take/delete_take';
    var params = {
      take_id: that.data.delid,
    }
    app.post(url, params).then((res) => {
      console.log(res);
      wx.showToast({
        title: '删除地址成功',
        icon: 'none'
      })

      setTimeout(function() {
        that.setData({
          deladdress: false
        })
        that.getaddresslist()
      }, 1000)



    }).catch((err) => {

    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})