index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="address-container">
  3. <u-empty v-if="addressList.length === 0" mode="address" icon="/static/images/empty/address.png">
  4. <view class="empty-tips">暂无收货地址</view>
  5. </u-empty>
  6. <view v-else class="address-list">
  7. <view v-for="(item, index) in addressList" :key="index" class="address-item">
  8. <view class="address-info" @click="selectAddress(item)">
  9. <view class="user-info">
  10. <text class="name">{{item.name}}</text>
  11. <text class="phone">{{item.phone}}</text>
  12. <text v-if="item.isDefault" class="default-tag">默认</text>
  13. </view>
  14. <view class="address-detail">{{item.province}}{{item.city}}{{item.district}}{{item.address}}</view>
  15. </view>
  16. <view class="operation">
  17. <view class="edit" @click="editAddress(item)">
  18. <u-icon name="edit-pen" size="40rpx"></u-icon>
  19. </view>
  20. <view class="delete" @click="deleteAddress(item)">
  21. <u-icon name="trash" size="40rpx"></u-icon>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="add-btn">
  27. <u-button type="primary" text="新增收货地址" @click="addAddress" color="#D93025"></u-button>
  28. </view>
  29. <u-modal
  30. :show="showDeleteModal"
  31. @confirm="confirmDelete"
  32. @cancel="showDeleteModal = false"
  33. title="删除确认"
  34. content="确定要删除该收货地址吗?"
  35. showCancelButton>
  36. </u-modal>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. addressList: [],
  44. showDeleteModal: false,
  45. currentAddress: null
  46. }
  47. },
  48. onShow() {
  49. this.getAddressList()
  50. },
  51. methods: {
  52. async getAddressList() {
  53. try {
  54. const res = await this.$api.address.list()
  55. this.addressList = res.data || []
  56. } catch (e) {
  57. this.$u.toast('获取地址列表失败')
  58. }
  59. },
  60. addAddress() {
  61. uni.navigateTo({
  62. url: '/packageShop/pages/address-edit/index'
  63. })
  64. },
  65. editAddress(item) {
  66. uni.navigateTo({
  67. url: '/packageShop/pages/address-edit/index?id=' + item.id
  68. })
  69. },
  70. deleteAddress(item) {
  71. this.currentAddress = item
  72. this.showDeleteModal = true
  73. },
  74. async confirmDelete() {
  75. if (!this.currentAddress) return
  76. try {
  77. await this.$api.address.delete(this.currentAddress.id)
  78. this.$u.toast('删除成功')
  79. this.getAddressList()
  80. } catch (e) {
  81. this.$u.toast('删除失败')
  82. }
  83. this.showDeleteModal = false
  84. this.currentAddress = null
  85. },
  86. selectAddress(item) {
  87. const pages = getCurrentPages()
  88. const prevPage = pages[pages.length - 2]
  89. if (prevPage && prevPage.$vm.setSelectedAddress) {
  90. prevPage.$vm.setSelectedAddress(item)
  91. uni.navigateBack()
  92. }
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .address-container {
  99. min-height: 100vh;
  100. background: #f5f5f5;
  101. padding-bottom: 120rpx;
  102. .address-list {
  103. padding: 20rpx;
  104. .address-item {
  105. background: #fff;
  106. border-radius: 12rpx;
  107. padding: 30rpx;
  108. margin-bottom: 20rpx;
  109. .address-info {
  110. .user-info {
  111. margin-bottom: 16rpx;
  112. .name {
  113. font-size: 32rpx;
  114. font-weight: bold;
  115. margin-right: 20rpx;
  116. }
  117. .phone {
  118. font-size: 28rpx;
  119. color: #666;
  120. }
  121. .default-tag {
  122. background: #D93025;
  123. color: #fff;
  124. font-size: 20rpx;
  125. padding: 4rpx 12rpx;
  126. border-radius: 4rpx;
  127. margin-left: 20rpx;
  128. }
  129. }
  130. .address-detail {
  131. font-size: 28rpx;
  132. color: #333;
  133. line-height: 1.4;
  134. }
  135. }
  136. .operation {
  137. display: flex;
  138. justify-content: flex-end;
  139. margin-top: 20rpx;
  140. border-top: 1rpx solid #eee;
  141. padding-top: 20rpx;
  142. .edit, .delete {
  143. padding: 10rpx 20rpx;
  144. }
  145. }
  146. }
  147. }
  148. .add-btn {
  149. position: fixed;
  150. bottom: 0;
  151. left: 0;
  152. right: 0;
  153. padding: 20rpx 40rpx;
  154. background: #fff;
  155. }
  156. .empty-tips {
  157. font-size: 28rpx;
  158. color: #999;
  159. margin-top: 20rpx;
  160. }
  161. }
  162. </style>