address.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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')">新增地址</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: '确定删除地址?',
  68. content: this.addressList[index].address
  69. })
  70. if (res.confirm) {
  71. let data = await this.$api.request('/address/delete?id=' + id);
  72. if (data) {
  73. if (this.$api.prePage().addressData && this.$api.prePage().addressData.id) {
  74. if (this.$api.prePage().addressData.id == this.addressList[index].id) {
  75. this.$api.prePage().addressData = {};
  76. }
  77. }
  78. this.addressList.splice(index, 1);
  79. }
  80. }
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang='scss'>
  86. page {
  87. padding-bottom: 120upx;
  88. }
  89. .content {
  90. position: relative;
  91. }
  92. .list {
  93. display: flex;
  94. align-items: center;
  95. padding: 20upx 30upx;
  96. ;
  97. background: #fff;
  98. position: relative;
  99. }
  100. .wrapper {
  101. display: flex;
  102. flex-direction: column;
  103. flex: 1;
  104. }
  105. .address-box {
  106. display: flex;
  107. align-items: center;
  108. .tag {
  109. font-size: 24upx;
  110. color: $base-color;
  111. margin-right: 10upx;
  112. background: #fffafb;
  113. border: 1px solid #ffb4c7;
  114. border-radius: 4upx;
  115. padding: 4upx 10upx;
  116. line-height: 1;
  117. }
  118. .address {
  119. font-size: 30upx;
  120. color: $font-color-dark;
  121. }
  122. }
  123. .u-box {
  124. font-size: 28upx;
  125. color: $font-color-light;
  126. margin-top: 16upx;
  127. .name {
  128. margin-right: 30upx;
  129. }
  130. }
  131. .icon-bianji {
  132. display: flex;
  133. align-items: center;
  134. height: 80upx;
  135. font-size: 40upx;
  136. color: $font-color-light;
  137. padding-left: 30upx;
  138. }
  139. .icon-lajitong {
  140. color: $font-color-light;
  141. padding-left: 25rpx;
  142. }
  143. .add-btn {
  144. position: fixed;
  145. left: 30upx;
  146. right: 30upx;
  147. bottom: 16upx;
  148. z-index: 95;
  149. display: flex;
  150. align-items: center;
  151. justify-content: center;
  152. width: 690upx;
  153. height: 80upx;
  154. font-size: 32upx;
  155. color: #fff;
  156. background-color: $base-color;
  157. border-radius: 10upx;
  158. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  159. }
  160. </style>