address.vue 4.4 KB

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