index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { getAddressList } from '../../api/user.js';
  2. var app = getApp();
  3. Component({
  4. properties: {
  5. //跳转url链接
  6. pagesUrl:{
  7. type:String,
  8. value:'',
  9. },
  10. address:{
  11. type: Object,
  12. value:{
  13. address:true,
  14. addressId:0,
  15. }
  16. },
  17. isLog:{
  18. type:Boolean,
  19. value:false,
  20. },
  21. },
  22. data: {
  23. active: 0,
  24. //地址列表
  25. addressList:[],
  26. is_loading:true,
  27. },
  28. attached: function () {
  29. },
  30. methods: {
  31. tapAddress: function (e) {
  32. this.setData({ active: e.currentTarget.dataset.id });
  33. this.triggerEvent('OnChangeAddress', e.currentTarget.dataset.addressid);
  34. },
  35. close: function () {
  36. this.setData({ 'address.address': false });
  37. this.triggerEvent('changeTextareaStatus');
  38. },
  39. goAddressPages:function(){
  40. this.setData({ 'address.address': false });
  41. this.triggerEvent('changeTextareaStatus');
  42. wx.navigateTo({url: this.data.pagesUrl});
  43. },
  44. getAddressList:function(){
  45. var that=this;
  46. getAddressList({page:1,limit:5}).then(res=>{
  47. var addressList = res.data;
  48. //处理默认选中项
  49. for (var i = 0, leng = addressList.length; i < leng; i++) {
  50. if (addressList[i].id == that.data.address.addressId) that.setData({ active: i });
  51. }
  52. that.setData({ addressList: addressList,is_loading:false });
  53. })
  54. }
  55. }
  56. })