index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const WXAPI = require('apifm-wxapi')
  2. const AUTH = require('../../utils/auth')
  3. const app = getApp()
  4. Page({
  5. data: {
  6. },
  7. selectTap: function(e) {
  8. console.log(e);
  9. var id = e.currentTarget.dataset.id;
  10. WXAPI.updateAddress({
  11. token: wx.getStorageSync('token'),
  12. id: id,
  13. isDefault: 'true'
  14. }).then(function(res) {
  15. wx.navigateBack({})
  16. })
  17. },
  18. addAddess: function() {
  19. wx.navigateTo({
  20. url: "/pages/address-add/index"
  21. })
  22. },
  23. editAddess: function(e) {
  24. console.log(e);
  25. wx.navigateTo({
  26. url: "/pages/address-add/index?id=" + e.currentTarget.dataset.id
  27. })
  28. },
  29. onLoad: function() {
  30. },
  31. onShow: function() {
  32. AUTH.checkHasLogined().then(isLogined => {
  33. if (isLogined) {
  34. this.initShippingAddress();
  35. } else {
  36. AUTH.login(this)
  37. }
  38. })
  39. },
  40. async initShippingAddress() {
  41. wx.showLoading({
  42. title: '',
  43. })
  44. const res = await WXAPI.queryAddress(wx.getStorageSync('token'))
  45. wx.hideLoading({
  46. success: (res) => {},
  47. })
  48. if (res.code == 0) {
  49. this.setData({
  50. addressList: res.data
  51. });
  52. } else if (res.code == 700) {
  53. this.setData({
  54. addressList: null
  55. });
  56. } else {
  57. wx.showToast({
  58. title: res.msg,
  59. icon: 'none'
  60. })
  61. }
  62. },
  63. onPullDownRefresh() {
  64. this.initShippingAddress()
  65. wx.stopPullDownRefresh()
  66. },
  67. })