index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view>
  3. <view class="address-window" :class="address.address == true ? 'on' : ''">
  4. <view class='title'>选择地址<text class='iconfont icon-guanbi' @tap='close'></text></view>
  5. <view class='list'>
  6. <view class='item acea-row row-between-wrapper' :class='active == index ? "font-color" : ""'
  7. v-for="(item, index) in addressList" @tap='tapAddress(index, item.id)' :key='index'>
  8. <text class='iconfont icon-ditu' :class='active == index ? "font-color" : ""'></text>
  9. <view class='address'>
  10. <view class='name' :class='active == index ? "font-color" : ""'>{{ item.realName }}<text class='phone'>{{
  11. item.phone }}</text></view>
  12. <view class='line1'>{{ item.province }}{{ item.city }}{{ item.district }}{{ item.detail }}</view>
  13. </view>
  14. <text class='iconfont icon-complete' :class='active == index ? "font-color" : ""'></text>
  15. </view>
  16. </view>
  17. <!-- 无地址 -->
  18. <view class='pictrue' v-if="!is_loading && !addressList.length">
  19. <image src='/static/images/noAddress.png'></image>
  20. </view>
  21. <view class='addressBnt bg-color' @tap='goAddressPages'>添加地址</view>
  22. </view>
  23. <view class='mask' catchtouchmove="true" :hidden='address.address == false' @tap='close'></view>
  24. </view>
  25. </template>
  26. <script setup>
  27. import { ref } from 'vue';
  28. import { getAddressList } from '@/api/user.js';
  29. const props = defineProps({
  30. pagesUrl: {
  31. type: String,
  32. default: '',
  33. },
  34. address: {
  35. type: Object,
  36. default: () => ({
  37. address: true,
  38. addressId: 0,
  39. }),
  40. },
  41. isLog: {
  42. type: Boolean,
  43. default: false,
  44. }
  45. });
  46. const emit = defineEmits(['OnChangeAddress', 'changeClose', 'changeTextareaStatus', 'OnDefaultAddress']);
  47. const active = ref(0);
  48. const is_loading = ref(true);
  49. const addressList = ref([]);
  50. // 对外暴露获取地址的方法
  51. defineExpose({
  52. fetchAddressList
  53. });
  54. function tapAddress(e, addressid) {
  55. active.value = e;
  56. let a = {};
  57. for (let i = 0, leng = addressList.value.length; i < leng; i++) {
  58. if (addressList.value[i].id == addressid) {
  59. a = addressList.value[i];
  60. }
  61. }
  62. emit('OnChangeAddress', a);
  63. }
  64. function close() {
  65. emit('changeClose');
  66. emit('changeTextareaStatus');
  67. }
  68. function goAddressPages() {
  69. emit('changeClose');
  70. emit('changeTextareaStatus');
  71. uni.navigateTo({
  72. url: props.pagesUrl
  73. });
  74. }
  75. function fetchAddressList() {
  76. getAddressList({
  77. page: 1,
  78. limit: 5
  79. }).then(res => {
  80. let list = res.data.list;
  81. addressList.value = list;
  82. is_loading.value = false;
  83. let defaultAddress = {};
  84. // 处理默认选中项
  85. if (!props.address.addressId) return;
  86. for (let i = 0, leng = list.length; i < leng; i++) {
  87. if (list[i].id == props.address.addressId) {
  88. active.value = i;
  89. defaultAddress = list[i];
  90. }
  91. }
  92. emit('OnDefaultAddress', defaultAddress);
  93. }).catch((error) => {
  94. console.error('fetchAddressList', error)
  95. })
  96. }
  97. // 监听 address.address 打开时刷新列表
  98. // watch(() => props.address.address, (val) => {
  99. // if (val) {
  100. // fetchAddressListFn();
  101. // }
  102. // }, { immediate: true });
  103. </script>
  104. <style scoped lang="scss">
  105. .address-window {
  106. background-color: #fff;
  107. position: fixed;
  108. bottom: 0;
  109. left: 0;
  110. width: 100%;
  111. z-index: 101;
  112. transform: translate3d(0, 100%, 0);
  113. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  114. }
  115. .address-window.on {
  116. transform: translate3d(0, 0, 0);
  117. }
  118. .address-window .title {
  119. font-size: 32rpx;
  120. font-weight: bold;
  121. text-align: center;
  122. height: 123rpx;
  123. line-height: 123rpx;
  124. position: relative;
  125. }
  126. .address-window .title .iconfont {
  127. position: absolute;
  128. right: 30rpx;
  129. color: #8a8a8a;
  130. font-size: 35rpx;
  131. }
  132. .address-window .list .item {
  133. margin-left: 30rpx;
  134. padding-right: 30rpx;
  135. border-bottom: 1px solid #eee;
  136. height: 129rpx;
  137. font-size: 25rpx;
  138. color: #333;
  139. }
  140. .address-window .list .item .iconfont {
  141. font-size: 37rpx;
  142. color: #2c2c2c;
  143. }
  144. .address-window .list .item .iconfont.icon-complete {
  145. font-size: 30rpx;
  146. color: #fff;
  147. }
  148. .address-window .list .item .address {
  149. width: 560rpx;
  150. }
  151. .address-window .list .item .address .name {
  152. font-size: 28rpx;
  153. font-weight: bold;
  154. color: #282828;
  155. margin-bottom: 4rpx;
  156. }
  157. .address-window .list .item .address .name .phone {
  158. margin-left: 18rpx;
  159. }
  160. .address-window .addressBnt {
  161. font-size: 30rpx;
  162. font-weight: bold;
  163. color: #fff;
  164. width: 690rpx;
  165. height: 86rpx;
  166. border-radius: 43rpx;
  167. text-align: center;
  168. line-height: 86rpx;
  169. margin: 85rpx auto;
  170. }
  171. .address-window .pictrue {
  172. width: 414rpx;
  173. height: 336rpx;
  174. margin: 0 auto;
  175. }
  176. .address-window .pictrue image {
  177. width: 100%;
  178. height: 100%;
  179. }
  180. </style>