address.vue 4.3 KB

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