address.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // pages/my/address/address.js
  2. const app =getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. addressList:[],
  9. pageindex: 1
  10. },
  11. onLoad:function(){
  12. },
  13. onShow(){
  14. this.setData({pageindex: 1})
  15. this.address()
  16. },
  17. /**
  18. * 页面上拉触底事件的处理函数
  19. */
  20. onReachBottom: function () {
  21. this.setData({pageindex:this.data.pageindex+=1})
  22. this.address()
  23. },
  24. addSite(e){
  25. let {parmise} = e.currentTarget.dataset
  26. console.log(parmise);
  27. wx.navigateTo({
  28. url: './addSite/addSite?parmise='+parmise,
  29. })
  30. },
  31. editSite(e){
  32. let {parmise} = e.currentTarget.dataset
  33. console.log(parmise);
  34. wx.navigateTo({
  35. url: './addSite/addSite?parmise='+JSON.stringify(parmise),
  36. })
  37. },
  38. //获取地址列表
  39. address(){
  40. var that=this;
  41. app.api.useApi(app.globalData.baseAppUrl + "api/address/index", {
  42. network_id: 1,
  43. page: that.data.pageindex
  44. }, "get").then(function (res) {
  45. if (res.original.code != 200) {
  46. wx.showLoading({
  47. title:res.original.message.msg,
  48. })
  49. that.setData({pageindex: that.data.pageindex -= 1})
  50. } else {
  51. if (that.data.pageindex == 1) {
  52. that.setData({addressList: []})
  53. }
  54. if (res.original.message.data.data.length > 0) {
  55. that.setData({addressList: that.data.addressList.concat(res.original.message.data.data)})
  56. } else {
  57. that.setData({pageindex: that.data.pageindex -= 1})
  58. }
  59. }
  60. setTimeout(function () {
  61. wx.hideLoading({
  62. success: (res) => {},
  63. })
  64. }, 2000);
  65. }).catch(function (err) {
  66. console.log(222);
  67. })
  68. }
  69. })