address.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="content b-t">
  3. <view class="list" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
  4. <view class="wrapper">
  5. <view class="address-box">
  6. <text class="name">{{ item.real_name }}</text>
  7. <text class="mobile">{{ item.phone }}</text>
  8. </view>
  9. <view class="u-box">
  10. <text class="address">{{ item.province + item.city + item.district }} {{ item.detail }}</text>
  11. </view>
  12. </view>
  13. <view class="buttom">
  14. <view class="default-buttom" @click.stop="defaultUp(item,index)">
  15. <view class="iconfont iconroundcheckfill checkbox" :class="{ checked: item.is_default == 1 }"></view>
  16. <text class="text">设为默认地址</text>
  17. </view>
  18. <view class="operation">
  19. <view @click.stop="addAddress('edit', item)">
  20. <text class="iconfont iconedit"></text>
  21. <text class="text">编辑</text>
  22. </view>
  23. <view class="blank"></view>
  24. <view @click.stop="delAddress(item)">
  25. <text class="iconfont icondelete"></text>
  26. <text class="text">删除</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <button class="add-btn" @click="addAddress('add')">新增地址</button>
  32. </view>
  33. </template>
  34. <script>
  35. import { getAddressList,setAddressDefault,addressDel } from '@/api/user.js';
  36. export default {
  37. data() {
  38. return {
  39. source: 0,
  40. addressList: []
  41. };
  42. },
  43. onLoad(option) {
  44. this.source = option.source||0
  45. this.loadAddress();
  46. },
  47. methods: {
  48. // 加载地址
  49. loadAddress() {
  50. getAddressList({
  51. page: 1,
  52. limit: 100
  53. }).then(({ data }) => {
  54. console.log(data)
  55. this.addressList = data.list;
  56. });
  57. },
  58. // 设为默认地址
  59. defaultUp(data,ind) {
  60. this.addressList=this.addressList.map((e) => {
  61. e.is_default=0
  62. return e
  63. })
  64. this.addressList[ind].is_default=1
  65. setAddressDefault({},data.address_id).then(({ data }) => {
  66. this.loadAddress();
  67. }).catch((e) => {
  68. console.log(e);
  69. });
  70. },
  71. //删除地址
  72. delAddress(item) {
  73. addressDel({},item.address_id).then(({data})=>{
  74. this.$api.msg('删除成功')
  75. })
  76. let s = this.addressList.indexOf(item);
  77. this.addressList.splice(s, 1);
  78. },
  79. //选择地址
  80. checkAddress(item) {
  81. if (this.source == 1) {
  82. //this.$api.prePage()获取上一页实例,在App.vue定义
  83. this.$api.prePage().addressData = item;
  84. uni.navigateBack();
  85. }
  86. },
  87. // 添加地址
  88. addAddress(type, item) {
  89. uni.navigateTo({
  90. url: `/pages/set/addressManage?type=${type}&data=${JSON.stringify(item)}`
  91. });
  92. },
  93. //添加或修改成功之后回调
  94. refreshList() {
  95. // 重新加载地址
  96. this.loadAddress()
  97. }
  98. }
  99. };
  100. </script>
  101. <style lang="scss">
  102. page {
  103. padding-bottom: 120rpx;
  104. padding-top: 20rpx;
  105. background-color: $page-color-base;
  106. }
  107. .content {
  108. position: relative;
  109. }
  110. .list {
  111. align-items: center;
  112. padding: 20rpx 30rpx;
  113. background: #fff;
  114. margin: 20rpx;
  115. margin-top: 0;
  116. .buttom {
  117. display: flex;
  118. align-items: center;
  119. justify-content: space-between;
  120. padding-top: 10rpx;
  121. .checkbox {
  122. font-size: 44rpx;
  123. line-height: 1;
  124. padding: 4rpx;
  125. color: $font-color-disabled;
  126. background: #fff;
  127. border-radius: 50px;
  128. }
  129. .checkbox.checked {
  130. color: $base-color;
  131. }
  132. .default-buttom {
  133. display: flex;
  134. align-items: center;
  135. }
  136. .operation {
  137. display: flex;
  138. align-items: center;
  139. .blank {
  140. width: 30rpx;
  141. }
  142. }
  143. .text {
  144. padding-left: 10rpx;
  145. font-size: 24rpx;
  146. color: #666666;
  147. }
  148. }
  149. }
  150. .wrapper {
  151. display: flex;
  152. flex-direction: column;
  153. flex: 1;
  154. border-bottom: 1px solid #f0f0f0;
  155. padding-bottom: 20rpx;
  156. }
  157. .address-box {
  158. display: flex;
  159. align-items: center;
  160. justify-content: space-between;
  161. .address {
  162. font-size: $font-base + 2rpx;
  163. color: $font-color-dark;
  164. }
  165. .mobile {
  166. font-size: $font-base;
  167. color: rgba(51, 51, 51, 1);
  168. }
  169. }
  170. .u-box {
  171. font-size: $font-base;
  172. color: $font-color-light;
  173. margin-top: 16rpx;
  174. .name {
  175. margin-right: 30rpx;
  176. }
  177. }
  178. .icon-bianji {
  179. display: flex;
  180. align-items: center;
  181. height: 80rpx;
  182. font-size: 40rpx;
  183. color: $font-color-light;
  184. padding-left: 30rpx;
  185. }
  186. .add-btn {
  187. position: fixed;
  188. left: 30rpx;
  189. right: 30rpx;
  190. bottom: 16rpx;
  191. z-index: 95;
  192. display: flex;
  193. align-items: center;
  194. justify-content: center;
  195. width: 690rpx;
  196. height: 80rpx;
  197. font-size: $font-lg;
  198. color: #fff;
  199. background-color: $base-color;
  200. border-radius: 10rpx;
  201. }
  202. </style>