list.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. uni.navigateBack()
  73. }
  74. },
  75. addAddress(type, item) {
  76. uni.navigateTo({
  77. url: `/pages/address/create?type=${type}&data=${JSON.stringify(item)}`
  78. })
  79. },
  80. //添加或修改成功之后回调
  81. refreshList(data, type) {
  82. const that = this
  83. that.$api.request('get', 'address/app/getAllAddress').then(res => {
  84. that.addressList = res.data
  85. })
  86. },
  87. deleteShow(item) {
  88. const that = this
  89. uni.showModal({
  90. title: '删除提示',
  91. content: '您确定要删除该地址吗?',
  92. showCancel: true,
  93. confirmText: '删除',
  94. success: (e) => {
  95. if (e.confirm) {
  96. that.$api.request('post', 'address/app/deleteAddress',{
  97. id: item.id
  98. }).then(res => {
  99. this.refreshList()
  100. })
  101. }
  102. },
  103. fail: () => {}
  104. })
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang='scss'>
  110. page {
  111. padding-bottom: 120upx;
  112. background-color: #F6F6F6;
  113. }
  114. .content {
  115. position: relative;
  116. }
  117. .list {
  118. display: flex;
  119. align-items: center;
  120. padding: 20upx 30upx;
  121. ;
  122. background: #fff;
  123. position: relative;
  124. }
  125. .wrapper {
  126. display: flex;
  127. flex-direction: column;
  128. flex: 1;
  129. }
  130. .address-box {
  131. display: flex;
  132. align-items: center;
  133. .tag {
  134. font-size: 24upx;
  135. color: $base-color;
  136. margin-right: 10upx;
  137. background: #fffafb;
  138. border: 1px solid #ffb4c7;
  139. border-radius: 4upx;
  140. padding: 4upx 10upx;
  141. line-height: 1;
  142. }
  143. .address {
  144. font-size: 28upx;
  145. color: $font-color-light;
  146. }
  147. }
  148. .u-box {
  149. font-size: 30upx;
  150. color: $font-color-dark;
  151. margin-top: 16upx;
  152. .name {
  153. margin-right: 30upx;
  154. }
  155. }
  156. .icon-bianji {
  157. display: flex;
  158. align-items: center;
  159. height: 80upx;
  160. font-size: 40upx;
  161. color: $font-color-light;
  162. padding-left: 30upx;
  163. }
  164. .add-btn {
  165. position: fixed;
  166. left: 30upx;
  167. right: 30upx;
  168. bottom: 16upx;
  169. z-index: 95;
  170. display: flex;
  171. align-items: center;
  172. justify-content: center;
  173. width: 690upx;
  174. height: 80upx;
  175. font-size: 32upx;
  176. color: #fff;
  177. background-color: $base-color;
  178. border-radius: 10upx;
  179. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  180. }
  181. </style>