address-manage.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="address-manage">
  3. <custom-nav ref="ltm" :title="title" />
  4. <view v-if="list.length" class="content">
  5. <view class="item" v-for="(item, index) in list" :key="index" @tap="chooseAddress(index)">
  6. <view class="name-phone">
  7. <text class="name">收货人: {{ item.con_name }}</text>
  8. <text class="phone">{{ item.con_mobile }}</text>
  9. </view>
  10. <view class="address">{{ item | getAddressString }}</view>
  11. <view class="status">
  12. <view class="edit-del">
  13. <text class="edit" @tap.stop="editAddress(index)">
  14. <text class="cuIcon-post icon-right"></text>编辑
  15. </text>
  16. <text class="del" @tap.stop="delAddress(index)">
  17. <text class="cuIcon-delete icon-right"></text>删除
  18. </text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="bottom"></view>
  23. </view>
  24. <view v-else class="noaddress">还没有地址呢</view>
  25. <navigator url="../add-address/add-address" class="add-address big-btn bg">新增地址</navigator>
  26. </view>
  27. </template>
  28. <script>
  29. import { _API_AddressGet, _API_AddressDel } from '@/apis/address.js'
  30. export default {
  31. data() {
  32. return {
  33. title: '地址管理'
  34. }
  35. },
  36. computed: {
  37. list() { return this.$store.state.address.list }
  38. },
  39. created() { // 监听添加或者删除地址消息提示
  40. uni.$on('ADDRESS', msg => {
  41. this.$refs.ltm.toast(msg)
  42. })
  43. },
  44. methods: {
  45. editAddress(index) { // 点击编辑地址
  46. uni.navigateTo({ url: `../add-address/add-address?index=${index}` })
  47. },
  48. delAddress(index) { // 点击删除地址
  49. this.$refs.ltm.modal('提示', ['确定要删除这个地址']).then(() => {
  50. this.$refs.ltm.loading()
  51. _API_AddressDel({ id: this.list[index].id }).then(res => {
  52. this.$store.commit('address/DEL', index)
  53. })
  54. }).catch(() => {
  55. this.$refs.ltm.toast('取消删除')
  56. })
  57. },
  58. chooseAddress(index) { // 如果是选择地址
  59. if (this.title === '选择地址') {
  60. this.$store.commit('address/CHOOSEADDRESS', index)
  61. uni.navigateBack()
  62. }
  63. return
  64. }
  65. },
  66. onLoad(opt) {
  67. if (opt.choose) { // 表示用户是从商品详情页或确认订单页进来的
  68. this.title = '选择地址'
  69. }
  70. if (!this.$store.state.address.requested) { // 当没有请求过地址时请求地址表
  71. this.$refs.ltm.loading()
  72. _API_AddressGet().then(res => {
  73. this.$store.commit('address/GET_ADDRESS', res.data.list)
  74. })
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss">
  80. .address-manage {
  81. @include page();
  82. .content {
  83. .item {
  84. @include flex(column);
  85. min-height: 250rpx;
  86. background: #FFFFFF;
  87. border-bottom: 10rpx solid $app-base-bg;
  88. box-sizing: border-box;
  89. padding: 30rpx 30rpx 0;
  90. .name-phone {
  91. @include flex();
  92. width: 100%;
  93. height: 66rpx;
  94. justify-content: space-between;
  95. .name {
  96. font-size: 32rpx;
  97. }
  98. .phone {
  99. font-size: 26rpx;
  100. }
  101. }
  102. .address {
  103. flex: 1;
  104. width: 100%;
  105. font-size: 26rpx;
  106. color: $app-sec-text-color;
  107. }
  108. .status {
  109. width: 100%;
  110. height: 76rpx;
  111. line-height: 76rpx;
  112. justify-content: space-between;
  113. border-top: 2rpx solid $app-base-bg;
  114. .edit-del {
  115. @include flex();
  116. float: right;
  117. height: 100%;
  118. width: 268rpx;
  119. color: $app-sec-text-color;
  120. justify-content: space-between;
  121. .edit, .del {
  122. flex: 1;
  123. height: 100%;
  124. text-align: center;
  125. &.del {
  126. text-align: right;
  127. }
  128. }
  129. }
  130. }
  131. }
  132. .bottom {
  133. height: 88rpx;
  134. }
  135. }
  136. .noaddress {
  137. @include flex();
  138. height: 100%;
  139. color: $app-sec-text-color;
  140. }
  141. .add-address {
  142. left: 0;
  143. bottom: 0;
  144. margin: 0;
  145. width: 100%;
  146. position: fixed;
  147. border-radius: 0;
  148. }
  149. }
  150. </style>