addressMg.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="address-wrapper">
  3. <AddressItem @refresh="getList" v-for="(item, index) in addressList" :key="index" :itemData="item"
  4. :isBack="isBack"></AddressItem>
  5. <view class="bottom-part display-flex-between">
  6. <view class="common-btn common-btn-gray" @click="getWehcatAddress">
  7. <image style="width: 34rpx;height: 34rpx;margin-right: 6rpx;"
  8. :src="`${$getImgBaseUrl()}icon-wechat.png`" mode=""></image>一键获取微信收货地址
  9. </view>
  10. <view @click="addAddress" class="common-btn">添加地址</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import AddressItem from '@/components/AddressItem.vue'
  16. export default {
  17. components: { AddressItem },
  18. data() {
  19. return {
  20. addressList: [],
  21. defaultStyle: { width: '100%', backgroundColor: '#EEEFF1', color: '#1D161F' },
  22. primaryStyle: { width: '100%' },
  23. isBack: false
  24. }
  25. },
  26. onLoad(options) {
  27. if (options.isBack) {
  28. this.isBack = true;
  29. }
  30. },
  31. onShow() {
  32. this.getList()
  33. },
  34. methods: {
  35. getWehcatAddress() {
  36. let _this = this
  37. uni.chooseAddress({
  38. success(res) {
  39. const { userName, telNumber, provinceName, cityName, countyName, detailInfo } = res
  40. const sendData = {
  41. name: userName,
  42. phone: telNumber,
  43. address: detailInfo,
  44. province: provinceName,
  45. city: cityName,
  46. area: countyName
  47. }
  48. _this.$api.addAddress(sendData).then(data => {
  49. _this.getList()
  50. uni.showToast({
  51. title: '保存成功'
  52. })
  53. })
  54. }
  55. })
  56. },
  57. getList() {
  58. this.$api.getAddressList().then(res => {
  59. // uni.hideLoading()
  60. this.addressList = res.data || []
  61. })
  62. },
  63. addAddress() {
  64. uni.navigateTo({
  65. url: '../addAddress/addAddress'
  66. })
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .address-wrapper {
  73. padding: 30rpx 20rpx 160rpx;
  74. .bottom-part {
  75. position: fixed;
  76. bottom: 0;
  77. padding: 10rpx 0 70rpx;
  78. left: 20rpx;
  79. right: 20rpx;
  80. z-index: 100;
  81. width: calc(100% - 40rpx);
  82. background-color: #F5F6F8;
  83. }
  84. }
  85. </style>