index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view>
  3. <u-navbar title="我的地址" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  4. <view class="addres-list">
  5. <view class="address-item" v-for="(item, index) in list" :key="index">
  6. <view class="contacts">
  7. <text class="name">{{ item.receiver }}</text>
  8. <text class="phone">{{ item.mobile }}</text>
  9. </view>
  10. <view class="address">
  11. <text class="region">{{ `${ item.province }-${ item.city }-${ item.area }` }}</text>
  12. <text class="detail">{{ item.addr }}</text>
  13. </view>
  14. <view class="line"></view>
  15. <view class="item-option">
  16. <view class="_left">
  17. <label class="item-radio" @click.stop="handleSetDefault(item.addrId)">
  18. <radio class="radio" color="#fa2209" :checked="item.addrId == defaultId"></radio>
  19. <text class="text">{{ item.addrId == defaultId ? '默认' : '选择' }}</text>
  20. </label>
  21. </view>
  22. <view class="_right">
  23. <view class="events">
  24. <view class="event-item" @click="handleUpdate(item.addrId)">
  25. <text class="iconfont icon-edit"></text>
  26. <text class="title">编辑</text>
  27. </view>
  28. <view class="event-item" @click="handleRemove(item.addrId)">
  29. <text class="iconfont icon-delete"></text>
  30. <text class="title">删除</text>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <u-empty text="亲,暂无收货地址" marginTop="100" mode="data" v-if="!list.length" />
  38. <!-- 底部操作按钮 -->
  39. <view class="footer-fixed">
  40. <view class="btn-wrapper">
  41. <button type="default" @click="handleCreate">添加地址</button>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import $http from '@/utils/request.js'
  48. export default {
  49. data() {
  50. return {
  51. //当前页面参数
  52. options: {},
  53. // 正在加载
  54. isLoading: true,
  55. // 收货地址列表
  56. list: [],
  57. // 默认收货地址
  58. defaultId: null
  59. }
  60. },
  61. onLoad(options) {
  62. // 当前页面参数
  63. this.options = options
  64. },
  65. onShow() {
  66. // 获取页面数据
  67. this.getPageData()
  68. },
  69. methods: {
  70. // 获取页面数据
  71. getPageData() {
  72. uni.showLoading({
  73. title: '加载中'
  74. });
  75. const app = this
  76. app.isLoading = true
  77. Promise.all([app.getDefaultId(), app.getAddressList()])
  78. .then(() => {
  79. uni.hideLoading();
  80. // 列表排序把默认收货地址放到最前
  81. // app.onReorder()
  82. }).catch(() => {
  83. uni.hideLoading();
  84. })
  85. },
  86. // 获取收货地址列表
  87. getAddressList() {
  88. $http.post('/api/v1/mp/user/addr/list', {}).then(res => {
  89. if (res.code == 0) {
  90. this.list = res.data
  91. }
  92. })
  93. },
  94. // 获取默认的收货地址
  95. getDefaultId() {
  96. $http.post('/api/v1/mp/user/addr/queryDefault', {}).then(res => {
  97. if (res.code == 0) {
  98. this.defaultId = res && res.data && res.data.addrId
  99. }
  100. })
  101. },
  102. // 列表排序把默认收货地址放到最前
  103. onReorder() {
  104. const app = this
  105. app.list.sort(item => {
  106. return item.addrId == app.defaultId ? -1 : 1
  107. })
  108. },
  109. // 添加地址
  110. handleCreate() {
  111. uni.navigateTo({
  112. url: "/packageOperate/address/create"
  113. })
  114. },
  115. // 编辑地址
  116. handleUpdate(addressId) {
  117. uni.navigateTo({
  118. url: `/packageOperate/address/create?addrId=${ addressId }`
  119. })
  120. },
  121. // 删除地址
  122. handleRemove(addressId) {
  123. const _this = this
  124. uni.showModal({
  125. title: "提示",
  126. content: "您确定要删除当前收货地址吗?",
  127. success(res) {
  128. if (res.confirm) {
  129. $http.post('/api/v1/mp/user/addr/remove', {
  130. addrId: addressId
  131. }).then(res => {
  132. if (res.code == 0) {
  133. _this.getPageData()
  134. uni.$u.toast('删除成功');
  135. }
  136. })
  137. }
  138. }
  139. });
  140. },
  141. // 设置默认地址
  142. handleSetDefault(addressId) {
  143. $http.post('/api/v1/mp/user/addr/setDefault', {
  144. addrId: addressId
  145. }).then(res => {
  146. this.getPageData()
  147. })
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. .addres-list {
  154. padding-bottom: calc(constant(safe-area-inset-bottom) + 120rpx);
  155. padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
  156. }
  157. .address-item {
  158. margin: 20rpx auto 20rpx auto;
  159. padding: 30rpx 40rpx;
  160. width: 95%;
  161. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  162. border-radius: 10rpx;
  163. background: #fff;
  164. }
  165. .contacts {
  166. font-size: 30rpx;
  167. margin-bottom: 16rpx;
  168. .name {
  169. margin-right: 16rpx;
  170. }
  171. }
  172. .address {
  173. font-size: 28rpx;
  174. .region {
  175. margin-right: 10rpx;
  176. }
  177. }
  178. .line {
  179. margin: 20rpx 0;
  180. border-bottom: 1rpx solid #f3f3f3;
  181. }
  182. .item-option {
  183. display: flex;
  184. justify-content: space-between;
  185. height: 48rpx;
  186. // 单选框
  187. .item-radio {
  188. font-size: 28rpx;
  189. .radio {
  190. vertical-align: middle;
  191. transform: scale(0.76)
  192. }
  193. .text {
  194. vertical-align: middle;
  195. }
  196. }
  197. // 操作
  198. .events {
  199. display: flex;
  200. align-items: center;
  201. line-height: 48rpx;
  202. .event-item {
  203. font-size: 28rpx;
  204. margin-right: 26rpx;
  205. color: #4c4c4c;
  206. &:last-child {
  207. margin-right: 0;
  208. }
  209. .title {
  210. margin-left: 8rpx;
  211. }
  212. }
  213. }
  214. }
  215. // 底部操作栏
  216. .footer-fixed {
  217. position: fixed;
  218. bottom: var(--window-bottom);
  219. left: 0;
  220. right: 0;
  221. min-height: 120rpx;
  222. z-index: 11;
  223. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  224. background: #fff;
  225. // 设置ios刘海屏底部横线安全区域
  226. padding-bottom: constant(safe-area-inset-bottom);
  227. padding-bottom: env(safe-area-inset-bottom);
  228. .btn-wrapper {
  229. display: flex;
  230. align-items: center;
  231. padding: 20rpx 0;
  232. }
  233. /deep/ button {
  234. width: 441rpx;
  235. height: 88rpx;
  236. line-height: 88rpx;
  237. font-size: 36rpx;
  238. color: #fff;
  239. background-color: #F9822C;
  240. border: none;
  241. border-radius: 44rpx;
  242. }
  243. }
  244. </style>