address.vue 4.4 KB

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