index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view>
  3. <view class="address-window" :class="address.address ? '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":""' />
  9. <view class='address'>
  10. <view class='name' :class='active==index?"font-color":""'>
  11. {{ item.name }}
  12. <text class='phone'>{{ item.mobile }}</text>
  13. </view>
  14. <view class='line1'>{{ item.areaName }} {{ item.detailAddress }}</view>
  15. </view>
  16. <text class='iconfont icon-complete' :class='active === index?"font-color":""' />
  17. </view>
  18. </view>
  19. <!-- 无地址 -->
  20. <view class='pictrue' v-if="!is_loading && !addressList.length">
  21. <image src='../../static/images/noAddress.png'></image>
  22. </view>
  23. <view class='addressBnt bg-color' @tap='goAddressPages'>选择其地址</view>
  24. </view>
  25. <view class='mask' catchtouchmove="true" :hidden='!address.address' @tap='close' />
  26. </view>
  27. </template>
  28. <script>
  29. import * as AddressApi from '@/api/member/address.js';
  30. export default {
  31. props: {
  32. pagesUrl: {
  33. type: String,
  34. default: '',
  35. },
  36. address: {
  37. type: Object,
  38. default: function() {
  39. return {
  40. address: true, // 是否打开
  41. addressId: 0,
  42. };
  43. }
  44. },
  45. isLog: {
  46. type: Boolean,
  47. default: false,
  48. }
  49. },
  50. data() {
  51. return {
  52. active: 0, // 激活的 addressList 下标
  53. is_loading: true,
  54. addressList: []
  55. };
  56. },
  57. methods: {
  58. /**
  59. * 选中某个地址
  60. */
  61. tapAddress: function(e, addressid) {
  62. this.active = e;
  63. for (let i = 0; i < this.addressList.length; i++) {
  64. if (this.addressList[i].id === addressid) {
  65. this.$emit('OnChangeAddress', this.addressList[i]);
  66. break
  67. }
  68. }
  69. },
  70. close: function() {
  71. this.$emit('changeClose');
  72. },
  73. goAddressPages: function() {
  74. this.$emit('changeClose');
  75. uni.navigateTo({
  76. url: this.pagesUrl
  77. });
  78. },
  79. getAddressList: function() {
  80. AddressApi.getAddressList().then(res => {
  81. const addressList = res.data;
  82. this.$set(this, 'addressList', addressList);
  83. this.is_loading = false;
  84. // 处理默认选中项
  85. if (!this.address.addressId) {
  86. return;
  87. }
  88. let defaultAddress = {};
  89. for (let i = 0; i < addressList.length; i++) {
  90. if (addressList[i].id === this.address.addressId) {
  91. this.active = i;
  92. defaultAddress = this.addressList[i];
  93. }
  94. }
  95. })
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped lang="scss">
  101. .address-window {
  102. background-color: #fff;
  103. position: fixed;
  104. bottom: 0;
  105. left: 0;
  106. width: 100%;
  107. z-index: 101;
  108. transform: translate3d(0, 100%, 0);
  109. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  110. }
  111. .address-window.on {
  112. transform: translate3d(0, 0, 0);
  113. }
  114. .address-window .title {
  115. font-size: 32rpx;
  116. font-weight: bold;
  117. text-align: center;
  118. height: 123rpx;
  119. line-height: 123rpx;
  120. position: relative;
  121. }
  122. .address-window .title .iconfont {
  123. position: absolute;
  124. right: 30rpx;
  125. color: #8a8a8a;
  126. font-size: 35rpx;
  127. }
  128. .address-window .list .item {
  129. margin-left: 30rpx;
  130. padding-right: 30rpx;
  131. border-bottom: 1px solid #eee;
  132. height: 129rpx;
  133. font-size: 25rpx;
  134. color: #333;
  135. }
  136. .address-window .list .item .iconfont {
  137. font-size: 37rpx;
  138. color: #2c2c2c;
  139. }
  140. .address-window .list .item .iconfont.icon-complete {
  141. font-size: 30rpx;
  142. color: #fff;
  143. }
  144. .address-window .list .item .address {
  145. width: 560rpx;
  146. }
  147. .address-window .list .item .address .name {
  148. font-size: 28rpx;
  149. font-weight: bold;
  150. color: #282828;
  151. margin-bottom: 4rpx;
  152. }
  153. .address-window .list .item .address .name .phone {
  154. margin-left: 18rpx;
  155. }
  156. .address-window .addressBnt {
  157. font-size: 30rpx;
  158. font-weight: bold;
  159. color: #fff;
  160. width: 690rpx;
  161. height: 86rpx;
  162. border-radius: 43rpx;
  163. text-align: center;
  164. line-height: 86rpx;
  165. margin: 85rpx auto;
  166. }
  167. .address-window .pictrue {
  168. width: 414rpx;
  169. height: 336rpx;
  170. margin: 0 auto;
  171. }
  172. .address-window .pictrue image {
  173. width: 100%;
  174. height: 100%;
  175. }
  176. </style>