list.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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)" @longpress="deleteShow(item)">
  4. <view class="wrapper">
  5. <view class="u-box">
  6. <text class="name">{{item.consignee}}</text>
  7. <text class="mobile">{{item.phone}}</text>
  8. </view>
  9. <view class="address-box">
  10. <text v-if="item.defaultAddress" class="tag">默认</text>
  11. <text class="address">{{item.province}} {{item.city}} {{item.county}} {{item.address}}</text>
  12. </view>
  13. </view>
  14. <text class="yticon icon-bianji" @click.stop="addAddress('edit', item)"></text>
  15. </view>
  16. <button class="add-btn" @click="addAddress('add')">新增地址</button>
  17. </view> -->
  18. <view class="">
  19. <view v-for="(item, index) in addressList" :key="index"
  20. @click="checkAddress(item)" @longpress="deleteShow(item)"
  21. class="bg-white" style="padding: 30rpx;margin: 20rpx 0;">
  22. <view class="flex justify-between align-center">
  23. <view style="font-size: 32rpx;line-height: 44rpx;color: #333333;font-weight: 500;">
  24. {{item.address}}
  25. </view>
  26. <view @click.stop="addAddress('edit', item)" class="text-green" style="font-size: 24rpx;line-height: 34rpx;">
  27. 编辑
  28. </view>
  29. </view>
  30. <view style="padding: 22rpx 0;font-size: 28rpx;line-height: 40rpx;color: #333333;">
  31. {{item.province}}{{item.city}}{{item.county}}
  32. </view>
  33. <view class="flex" style="font-size: 28rpx;line-height: 40rpx;color: #333333;">
  34. <view v-if="item.defaultAddress"
  35. style="line-height: 1.5;padding: 0 10rpx;border-radius: 8rpx;background-color: #2AAC34;color: #FFFFFF;margin-right: 20rpx;">默认</view>
  36. {{item.consignee}} {{item.phone}}
  37. </view>
  38. </view>
  39. <view style="width: 750rpx;display: flex; position: relative;height: 144rpx;"></view>
  40. <view class="flex justify-center " style="width: 750rpx;position: fixed;bottom: 0;background-color: #F6F6F6;">
  41. <button @click="addAddress('add')" class="round" style="background-color: #2AAC34;width: 560rpx;height: 90rpx;margin-bottom: 54rpx;line-height: 90rpx;color: #FFFFFF;">新增收货地址</button>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. source: 0,
  50. addressList: [],
  51. isFirstLoad: true // 添加首次加载标志
  52. }
  53. },
  54. onShow(){
  55. // 页面显示时刷新列表,包括从其他页面返回时
  56. this.refreshList()
  57. },
  58. onLoad(option) {
  59. // 如果不是首次加载才刷新
  60. if (!this.isFirstLoad) {
  61. this.refreshList()
  62. }
  63. this.isFirstLoad = false // 第一次 onShow 之后设为 false
  64. this.source = option.source;
  65. },
  66. methods: {
  67. //选择地址
  68. checkAddress(item) {
  69. if (this.source == 1) {
  70. //this.$api.prePage()获取上一页实例,在App.vue定义
  71. this.$api.prePage().addressData = item
  72. this.$api.prePage().calcFreightPrice()
  73. uni.navigateBack()
  74. }
  75. },
  76. addAddress(type, item) {
  77. uni.navigateTo({
  78. url: `/pages/address/create?type=${type}&data=${JSON.stringify(item)}`
  79. })
  80. },
  81. //添加或修改成功之后回调
  82. refreshList(data, type) {
  83. const that = this
  84. that.$api.request('get', 'address/app/getAllAddress').then(res => {
  85. that.addressList = res.data
  86. })
  87. },
  88. deleteShow(item) {
  89. const that = this
  90. uni.showModal({
  91. title: '删除提示',
  92. content: '您确定要删除该地址吗?',
  93. showCancel: true,
  94. confirmText: '删除',
  95. success: (e) => {
  96. if (e.confirm) {
  97. that.$api.request('post', 'address/app/deleteAddress',{
  98. id: item.id
  99. }).then(res => {
  100. this.refreshList()
  101. })
  102. }
  103. },
  104. fail: () => {}
  105. })
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang='scss'>
  111. page {
  112. padding-bottom: 120upx;
  113. background-color: #F6F6F6;
  114. }
  115. .content {
  116. position: relative;
  117. }
  118. .list {
  119. display: flex;
  120. align-items: center;
  121. padding: 20upx 30upx;
  122. ;
  123. background: #fff;
  124. position: relative;
  125. }
  126. .wrapper {
  127. display: flex;
  128. flex-direction: column;
  129. flex: 1;
  130. }
  131. .address-box {
  132. display: flex;
  133. align-items: center;
  134. .tag {
  135. font-size: 24upx;
  136. color: $base-color;
  137. margin-right: 10upx;
  138. background: #fffafb;
  139. border: 1px solid #ffb4c7;
  140. border-radius: 4upx;
  141. padding: 4upx 10upx;
  142. line-height: 1;
  143. }
  144. .address {
  145. font-size: 28upx;
  146. color: $font-color-light;
  147. }
  148. }
  149. .u-box {
  150. font-size: 30upx;
  151. color: $font-color-dark;
  152. margin-top: 16upx;
  153. .name {
  154. margin-right: 30upx;
  155. }
  156. }
  157. .icon-bianji {
  158. display: flex;
  159. align-items: center;
  160. height: 80upx;
  161. font-size: 40upx;
  162. color: $font-color-light;
  163. padding-left: 30upx;
  164. }
  165. .add-btn {
  166. position: fixed;
  167. left: 30upx;
  168. right: 30upx;
  169. bottom: 16upx;
  170. z-index: 95;
  171. display: flex;
  172. align-items: center;
  173. justify-content: center;
  174. width: 690upx;
  175. height: 80upx;
  176. font-size: 32upx;
  177. color: #fff;
  178. background-color: $base-color;
  179. border-radius: 10upx;
  180. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  181. }
  182. </style>