index.vue 6.0 KB

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