list.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!-- 收件地址列表 -->
  2. <template>
  3. <s-layout title="收货地址" :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. 导入微信地址
  16. </button>
  17. <button class="add-btn ss-reset-button ui-Shadow-Main"
  18. @tap="sheep.$router.go('/pages/user/address/edit')">
  19. 新增收货地址
  20. </button>
  21. </view>
  22. </su-fixed>
  23. <s-empty v-if="state.list.length === 0 && !state.loading" text="暂无收货地址" 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. const state = reactive({
  41. list: [], // 地址列表
  42. loading: true,
  43. });
  44. // 选择收货地址
  45. const onSelect = (addressInfo) => {
  46. uni.$emit('SELECT_ADDRESS', {
  47. addressInfo,
  48. });
  49. sheep.$router.back();
  50. };
  51. // 导入微信地址
  52. // TODO 芋艿:未测试
  53. function importWechatAddress() {
  54. let wechatAddress = {};
  55. // #ifdef MP
  56. uni.chooseAddress({
  57. success: (res) => {
  58. wechatAddress = {
  59. consignee: res.userName,
  60. mobile: res.telNumber,
  61. province_name: res.provinceName,
  62. city_name: res.cityName,
  63. district_name: res.countyName,
  64. address: res.detailInfo,
  65. region: '',
  66. is_default: false,
  67. };
  68. if (!isEmpty(wechatAddress)) {
  69. sheep.$router.go('/pages/user/address/edit', {
  70. data: JSON.stringify(wechatAddress),
  71. });
  72. }
  73. },
  74. fail: (err) => {
  75. console.log("uni.chooseAddress调用失败,问题是:", err);
  76. },
  77. });
  78. // #endif
  79. // #ifdef H5
  80. sheep.$platform.useProvider('wechat').jssdk.openAddress({
  81. success: (res) => {
  82. wechatAddress = {
  83. // consignee: res.userName,
  84. // mobile: res.telNumber,
  85. // province_name: res.provinceName,
  86. // city_name: res.cityName,
  87. // district_name: res.countryName,
  88. // address: res.detailInfo,
  89. // region: '',
  90. // is_default: false,
  91. consignee: "1123123123",
  92. mobile: "123213123",
  93. province_name: "123213123",
  94. city_name: '"123213123"',
  95. district_name: res.countryName,
  96. address: res.detailInfo,
  97. region: '',
  98. is_default: false,
  99. };
  100. if (!isEmpty(wechatAddress)) {
  101. sheep.$router.go('/pages/user/address/edit', {
  102. data: JSON.stringify(wechatAddress),
  103. });
  104. }
  105. },
  106. });
  107. // #endif
  108. }
  109. onShow(async () => {
  110. state.list = (await AddressApi.getAddressList()).data;
  111. state.loading = false;
  112. });
  113. onBeforeMount(() => {
  114. if (!!uni.getStorageSync('areaData')) {
  115. return;
  116. }
  117. // 提前加载省市区数据
  118. AreaApi.getAreaTree().then((res) => {
  119. if (res.code === 0) {
  120. uni.setStorageSync('areaData', res.data);
  121. }
  122. });
  123. });
  124. </script>
  125. <style lang="scss" scoped>
  126. .footer-box {
  127. .add-btn {
  128. flex: 1;
  129. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  130. border-radius: 80rpx;
  131. font-size: 30rpx;
  132. font-weight: 500;
  133. line-height: 80rpx;
  134. color: $white;
  135. position: relative;
  136. z-index: 1;
  137. }
  138. .sync-wxaddress {
  139. flex: 1;
  140. line-height: 80rpx;
  141. background: $white;
  142. border-radius: 80rpx;
  143. font-size: 30rpx;
  144. font-weight: 500;
  145. color: $dark-6;
  146. margin-right: 18rpx;
  147. }
  148. }
  149. </style>