list.vue 3.7 KB

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