myaddress.js 2.3 KB
const app = getApp();

Page({

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

    list: []

  },

  onLoad: function (options) {

  },


  onReady: function () {

  },


  onShow: function () {
    let that = this;
    that.getList();

  },
  //列表  
  getList() {
    // return
    let that = this;
    let url = '/index/second/addressList';
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    app.post(url, '', head).then((res) => {
      console.log(res)
      that.setData({
        list: res
      })
    }).catch((err) => {

    })
  },

  // 删除
  bindDelete(e) {

    var that = this
    var id = e.currentTarget.dataset.id;
    let url = '/index/second/deleteAddress';
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let params = {
      address_id: id
    }
    // console.log(params)
    wx.showModal({
      title: '提示',
      content: '确定删除该地址吗?',
      success(res) {
        if (res.confirm) {
          app.post(url, params, head).then((res) => {
            wx.showToast({
              title: '删除成功',
            })
            setTimeout(function () {
              that.onShow()
            }, 1200)
            console.log('ss')

          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  // 编辑
  bindCompile(e) {
    // console.log(e)
    var id = e.currentTarget.dataset.id
    // console.log(id)
    wx.navigateTo({
      url: '/pages/myaddcompile/myaddcompile?id=' + id,
    })
  },



  //新增地址 
  getAddress() {
    wx.navigateTo({
      url: '/pages/myaddcompile/myaddcompile',
    })

  },
  // 选择地址
  getchoose(e) {
    console.log(e)
    let index = e.currentTarget.dataset.index;
    wx.setStorageSync('tempAdress', this.data.list[index])
    wx.navigateBack({
      delta: 0,
    })


  },





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

  },

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

  },

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

  },

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

  },

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

  }
})