address.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // customized/pages/address/address.js
  2. let app = getApp();
  3. let host = app.globalData.servsers; // 请求的url
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. addressList: [],
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. },
  16. /**
  17. * 生命周期函数--监听页面初次渲染完成
  18. */
  19. onReady: function () {
  20. },
  21. /**
  22. * 生命周期函数--监听页面显示
  23. */
  24. onShow: function () {
  25. this.getaddress()
  26. },
  27. /**
  28. * 生命周期函数--监听页面隐藏
  29. */
  30. onHide: function () {
  31. },
  32. /**
  33. * 生命周期函数--监听页面卸载
  34. */
  35. onUnload: function () {
  36. },
  37. /**
  38. * 页面相关事件处理函数--监听用户下拉动作
  39. */
  40. onPullDownRefresh: function () {
  41. },
  42. /**
  43. * 页面上拉触底事件的处理函数
  44. */
  45. getaddress() {
  46. wx.showLoading({
  47. title: '加载中',
  48. })
  49. let that = this;
  50. wx.request({
  51. url: host + '/adressapi/adressview',
  52. header: {
  53. 'content-type': 'application/x-www-form-urlencoded'
  54. },
  55. data: {
  56. user_id: app.globalData.user_id,// 'oovpNwjlsY6xx8ceCebFa1dOLd9E' //app.globalData.user_id,
  57. },
  58. success(res) {
  59. console.log(res, "address")
  60. that.setData({
  61. addressList:[...res.data.rows]
  62. })
  63. },
  64. complete(){
  65. wx.hideLoading()
  66. }
  67. })
  68. },
  69. addAddress(){
  70. wx.navigateTo({
  71. url: '/customized/pages/address/add/add',
  72. })
  73. },
  74. delAddress(e){
  75. let that = this, id = e.target.dataset.id;
  76. wx.showModal({
  77. title: '提示',
  78. content: '是否确定删除地址?',
  79. success(res){
  80. if (res.confirm) {
  81. console.log('用户点击确定')
  82. wx.request({
  83. url: host + '/adressapi/delete',
  84. header: {
  85. 'content-type': 'application/x-www-form-urlencoded'
  86. },
  87. method:'get',
  88. data:{
  89. id: id
  90. },
  91. success(res){
  92. console.log(res,"删除");
  93. wx.showToast({
  94. title: '删除成功!',
  95. icon:'none'
  96. })
  97. that.getaddress()
  98. }
  99. })
  100. } else if (res.cancel) {
  101. console.log('用户点击取消')
  102. }
  103. }
  104. })
  105. console.log(e.target.dataset.id)
  106. },
  107. editAddress(e){
  108. wx.setStorageSync('address', e.target.dataset.item)
  109. wx.navigateTo({
  110. url: '/customized/pages/address/add/add?type=edit',
  111. })
  112. },
  113. selectAddress(e){ // 选中地址
  114. console.log(e)
  115. wx.setStorageSync('accountAddress', e.currentTarget.dataset.item)
  116. wx.navigateBack({
  117. delta: 1
  118. })
  119. // wx.navigateTo({
  120. // url: '/customized/pages/accounts/accounts?type=selectAddress',
  121. // })
  122. }
  123. })