You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

183 lines
3.7 KiB

  1. <template>
  2. <view class="content b-t">
  3. <view class="list b-b" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
  4. <view class="wrapper">
  5. <view class="address-box">
  6. <text v-if="item.is_default" class="tag">默认</text>
  7. <text class="address">{{item.province.name+item.city.name+item.area.name+' '+item.address}}</text>
  8. </view>
  9. <view class="u-box">
  10. <text class="name">{{item.name}}</text>
  11. <text class="mobile">{{item.mobile}}</text>
  12. </view>
  13. </view>
  14. <text class="yticon icon-bianji" @click.stop="addAddress('edit', item.id)"></text>
  15. <text class="yticon icon-lajitong" @click.stop="deleteAddress(item.id,index)"></text>
  16. </view>
  17. <button class="add-btn" @click="addAddress('add')">Add New Address</button>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. source: 0,
  25. addressList: []
  26. }
  27. },
  28. onLoad(option) {
  29. console.log(option.source);
  30. this.source = option.source;
  31. },
  32. onShow() {
  33. this.getList();
  34. },
  35. methods: {
  36. //获取我的收货地址
  37. async getList() {
  38. let list = await this.$api.request('/address/all', 'POST', {
  39. page: 1,
  40. pagesize: 50
  41. });
  42. if (list) {
  43. this.addressList = list;
  44. }
  45. },
  46. //选择地址
  47. checkAddress(item) {
  48. if (this.source == 1) {
  49. //this.$api.prePage()获取上一页实例,在App.vue定义
  50. this.$api.prePage().addressData = item;
  51. uni.navigateBack()
  52. }
  53. },
  54. addAddress(type, id = 0) {
  55. uni.navigateTo({
  56. url: `/pages/address/addressManage?type=${type}&id=${id}`
  57. })
  58. },
  59. //添加或修改成功之后回调
  60. refreshList(data, type) {
  61. //添加或修改后事件,这里直接在最前面添加了一条数据,实际应用中直接刷新地址列表即可
  62. this.addressList.unshift(data);
  63. console.log(data, type);
  64. },
  65. async deleteAddress(id, index) {
  66. let [error, res] = await uni.showModal({
  67. title: 'Sure to delete address?',
  68. cancelText:'Cancel',
  69. confirmText:'OK',
  70. content: this.addressList[index].address
  71. })
  72. if (res.confirm) {
  73. let data = await this.$api.request('/address/delete?id=' + id);
  74. if (data) {
  75. if (this.$api.prePage().addressData && this.$api.prePage().addressData.id) {
  76. if (this.$api.prePage().addressData.id == this.addressList[index].id) {
  77. this.$api.prePage().addressData = {};
  78. }
  79. }
  80. this.addressList.splice(index, 1);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang='scss'>
  88. page {
  89. padding-bottom: 120upx;
  90. }
  91. .content {
  92. position: relative;
  93. }
  94. .list {
  95. display: flex;
  96. align-items: center;
  97. padding: 20upx 30upx;
  98. ;
  99. background: #fff;
  100. position: relative;
  101. }
  102. .wrapper {
  103. display: flex;
  104. flex-direction: column;
  105. flex: 1;
  106. }
  107. .address-box {
  108. display: flex;
  109. align-items: center;
  110. .tag {
  111. font-size: 24upx;
  112. color: $base-color;
  113. margin-right: 10upx;
  114. background: #fffafb;
  115. border: 1px solid #ffb4c7;
  116. border-radius: 4upx;
  117. padding: 4upx 10upx;
  118. line-height: 1;
  119. }
  120. .address {
  121. font-size: 30upx;
  122. color: $font-color-dark;
  123. }
  124. }
  125. .u-box {
  126. font-size: 28upx;
  127. color: $font-color-light;
  128. margin-top: 16upx;
  129. .name {
  130. margin-right: 30upx;
  131. }
  132. }
  133. .icon-bianji {
  134. display: flex;
  135. align-items: center;
  136. height: 80upx;
  137. font-size: 40upx;
  138. color: $font-color-light;
  139. padding-left: 30upx;
  140. }
  141. .icon-lajitong {
  142. color: $font-color-light;
  143. padding-left: 25rpx;
  144. }
  145. .add-btn {
  146. position: fixed;
  147. left: 30upx;
  148. right: 30upx;
  149. bottom: 16upx;
  150. z-index: 95;
  151. display: flex;
  152. align-items: center;
  153. justify-content: center;
  154. width: 690upx;
  155. height: 80upx;
  156. font-size: 32upx;
  157. color: #fff;
  158. background-color: $base-color;
  159. border-radius: 10upx;
  160. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  161. }
  162. </style>