index.vue 4.6 KB

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