index.vue 6.2 KB

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