address.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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.street}} {{item.village}} {{ 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. this.addressList = data;
  55. });
  56. },
  57. // 设为默认地址
  58. defaultUp(data,ind) {
  59. this.addressList=this.addressList.map((e) => {
  60. e.is_default=0
  61. return e
  62. })
  63. this.addressList[ind].is_default=1
  64. setAddressDefault({
  65. id: data.id
  66. }).then(({ data }) => {
  67. this.loadAddress();
  68. }).catch((e) => {
  69. console.log(e);
  70. });
  71. },
  72. //删除地址
  73. delAddress(item) {
  74. addressDel({
  75. id:item.id
  76. }).then(({data})=>{
  77. this.$api.msg('删除成功')
  78. })
  79. let s = this.addressList.indexOf(item);
  80. this.addressList.splice(s, 1);
  81. },
  82. //选择地址
  83. checkAddress(item) {
  84. if (this.source == 1) {
  85. //this.$api.prePage()获取上一页实例,在App.vue定义
  86. this.$api.prePage().addressData = item;
  87. uni.navigateBack();
  88. }
  89. },
  90. // 添加地址
  91. addAddress(type, item) {
  92. let url=`/pages/set/addressManage?type=${type}`
  93. if(item&&item.id){
  94. url += `&id=${item.id}`;
  95. }
  96. uni.navigateTo({
  97. url
  98. });
  99. },
  100. //添加或修改成功之后回调
  101. refreshList() {
  102. // 重新加载地址
  103. this.loadAddress()
  104. }
  105. }
  106. };
  107. </script>
  108. <style lang="scss">
  109. page {
  110. padding-bottom: 120rpx;
  111. padding-top: 20rpx;
  112. background-color: $page-color-base;
  113. }
  114. .content {
  115. position: relative;
  116. }
  117. .list {
  118. align-items: center;
  119. padding: 20rpx 30rpx;
  120. background: #fff;
  121. margin: 20rpx;
  122. margin-top: 0;
  123. .buttom {
  124. display: flex;
  125. align-items: center;
  126. justify-content: space-between;
  127. padding-top: 10rpx;
  128. .checkbox {
  129. font-size: 44rpx;
  130. line-height: 1;
  131. padding: 4rpx;
  132. color: $font-color-disabled;
  133. background: #fff;
  134. border-radius: 50px;
  135. }
  136. .checkbox.checked {
  137. color: $base-color;
  138. }
  139. .default-buttom {
  140. display: flex;
  141. align-items: center;
  142. }
  143. .operation {
  144. display: flex;
  145. align-items: center;
  146. .blank {
  147. width: 30rpx;
  148. }
  149. }
  150. .text {
  151. padding-left: 10rpx;
  152. font-size: 24rpx;
  153. color: #666666;
  154. }
  155. }
  156. }
  157. .wrapper {
  158. display: flex;
  159. flex-direction: column;
  160. flex: 1;
  161. border-bottom: 1px solid #f0f0f0;
  162. padding-bottom: 20rpx;
  163. }
  164. .address-box {
  165. display: flex;
  166. align-items: center;
  167. justify-content: space-between;
  168. .address {
  169. font-size: $font-base + 2rpx;
  170. color: $font-color-dark;
  171. }
  172. .mobile {
  173. font-size: $font-base;
  174. color: rgba(51, 51, 51, 1);
  175. }
  176. }
  177. .u-box {
  178. font-size: $font-base;
  179. color: $font-color-light;
  180. margin-top: 16rpx;
  181. .name {
  182. margin-right: 30rpx;
  183. }
  184. }
  185. .icon-bianji {
  186. display: flex;
  187. align-items: center;
  188. height: 80rpx;
  189. font-size: 40rpx;
  190. color: $font-color-light;
  191. padding-left: 30rpx;
  192. }
  193. .add-btn {
  194. position: fixed;
  195. left: 30rpx;
  196. right: 30rpx;
  197. bottom: 16rpx;
  198. z-index: 95;
  199. display: flex;
  200. align-items: center;
  201. justify-content: center;
  202. width: 690rpx;
  203. height: 80rpx;
  204. font-size: $font-lg;
  205. color: #fff;
  206. background-color: $base-color;
  207. border-radius: 10rpx;
  208. }
  209. </style>