list.vue 3.9 KB

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