address.vue 4.5 KB

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