index.vue 4.3 KB

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