address.vue 4.5 KB

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