list.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!-- 收件地址列表 -->
  2. <template>
  3. <s-layout :title="t('address.virtual_goods_address')" :bgStyle="{ color: '#FFF' }">
  4. <view v-if="state.list.length">
  5. <s-address-item spuType="0" hasBorderBottom v-for="item in state.list" :key="item.id" :item="item"
  6. @tap="onSelect(item)" />
  7. </view>
  8. <su-fixed bottom placeholder>
  9. <view class="footer-box ss-flex ss-row-between ss-p-20">
  10. <!-- 微信小程序和微信H5 -->
  11. <button class="add-btn ss-reset-button ui-Shadow-Main"
  12. @tap="sheep.$router.go('/pages/user/dummyAddress/edit')">
  13. {{ t('address.add_new_shipping_address') }}
  14. </button>
  15. </view>
  16. </su-fixed>
  17. <s-empty v-if="state.list.length === 0 && !state.loading" :text="t('address.no_shipping_address')" icon="/static/data-empty.png" />
  18. </s-layout>
  19. </template>
  20. <script setup>
  21. import {
  22. reactive,
  23. onBeforeMount
  24. } from 'vue';
  25. import {
  26. onShow
  27. } from '@dcloudio/uni-app';
  28. import sheep from '@/sheep';
  29. import {
  30. isEmpty
  31. } from 'lodash';
  32. import AreaApi from '@/sheep/api/system/area';
  33. import AddressApi from '@/sheep/api/member/address';
  34. import $helper from '@/sheep/helper';
  35. import { t } from '@/locale'
  36. const state = reactive({
  37. list: [], // 地址列表
  38. loading: true,
  39. });
  40. // 选择收货地址
  41. const onSelect = (addressInfo) => {
  42. uni.$emit('SELECT_ADDRESS', {
  43. addressInfo,
  44. });
  45. sheep.$router.back();
  46. };
  47. // 导入微信地址
  48. // TODO 非繁人:未测试
  49. function importWechatAddress() {
  50. let wechatAddress = {};
  51. // #ifdef MP
  52. uni.chooseAddress({
  53. success: (res) => {
  54. wechatAddress = {
  55. consignee: res.userName,
  56. mobile: res.telNumber,
  57. province_name: res.provinceName,
  58. city_name: res.cityName,
  59. district_name: res.countyName,
  60. address: res.detailInfo,
  61. region: '',
  62. is_default: false,
  63. };
  64. if (!isEmpty(wechatAddress)) {
  65. sheep.$router.go('/pages/user/dummyAddress/edit', {
  66. data: JSON.stringify(wechatAddress),
  67. });
  68. }
  69. },
  70. fail: (err) => {
  71. console.log("uni.chooseAddress调用失败,问题是:", err);
  72. },
  73. });
  74. // #endif
  75. // #ifdef H5
  76. sheep.$platform.useProvider('wechat').jssdk.openAddress({
  77. success: (res) => {
  78. wechatAddress = {
  79. consignee: res.userName,
  80. mobile: res.telNumber,
  81. province_name: res.provinceName,
  82. city_name: res.cityName,
  83. district_name: res.countryName,
  84. address: res.detailInfo,
  85. region: '',
  86. is_default: false,
  87. };
  88. if (!isEmpty(wechatAddress)) {
  89. sheep.$router.go('/pages/user/dummyAddress/edit', {
  90. data: JSON.stringify(wechatAddress),
  91. });
  92. }
  93. },
  94. });
  95. // #endif
  96. }
  97. onShow(async () => {
  98. state.list = (await AddressApi.getAddressList(2)).data;
  99. state.loading = false;
  100. });
  101. onBeforeMount(() => {
  102. if (!!uni.getStorageSync('areaData')) {
  103. return;
  104. }
  105. // 提前加载省市区数据
  106. AreaApi.getAreaTree().then((res) => {
  107. if (res.code === 0) {
  108. uni.setStorageSync('areaData', res.data);
  109. }
  110. });
  111. });
  112. </script>
  113. <style lang="scss" scoped>
  114. .footer-box {
  115. .add-btn {
  116. flex: 1;
  117. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  118. border-radius: 80rpx;
  119. font-size: 30rpx;
  120. font-weight: 500;
  121. line-height: 80rpx;
  122. color: $white;
  123. position: relative;
  124. z-index: 1;
  125. }
  126. .sync-wxaddress {
  127. flex: 1;
  128. line-height: 80rpx;
  129. background: $white;
  130. border-radius: 80rpx;
  131. font-size: 30rpx;
  132. font-weight: 500;
  133. color: $dark-6;
  134. margin-right: 18rpx;
  135. }
  136. }
  137. </style>