address-manage.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="address-manage">
  3. <custom-nav noback="noback" transparent="transparent" ref="ltm" 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. uni.toast(msg)
  42. })
  43. },
  44. methods: {
  45. editAddress(index) { // 点击编辑地址
  46. uni.navigateTo({ url: `../add-address/add-address?index=${String(index)}` })
  47. },
  48. delAddress(index) { // 点击删除地址
  49. uni.showModal({
  50. title: '提示',
  51. content: '确定要删除这个地址?',
  52. success: (res) => {
  53. if (res.confirm) {
  54. _API_AddressDel({ id: this.list[index].id }).then(res => {
  55. this.$store.commit('address/DEL', index)
  56. })
  57. }
  58. }
  59. })
  60. },
  61. chooseAddress(index) { // 如果是选择地址
  62. if (this.title === '选择地址') {
  63. this.$store.commit('address/CHOOSEADDRESS', index)
  64. uni.navigateBack()
  65. }
  66. return
  67. }
  68. },
  69. onShow() {
  70. setTimeout(() => {
  71. uni.showLoading({ mask: true })
  72. _API_AddressGet().then(res => {
  73. this.$store.commit('address/GET_ADDRESS', res.data.list)
  74. })
  75. }, 333)
  76. },
  77. onLoad(opt) {
  78. if (opt.choose) { // 表示用户是从商品详情页或确认订单页进来的
  79. this.title = '选择地址'
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. .address-manage {
  86. @include page();
  87. .content {
  88. .item {
  89. @include flex(column);
  90. min-height: 250rpx;
  91. background: #FFFFFF;
  92. border-bottom: 10rpx solid $app-base-bg;
  93. box-sizing: border-box;
  94. padding: 30rpx 30rpx 0;
  95. .name-phone {
  96. @include flex();
  97. width: 100%;
  98. height: 66rpx;
  99. justify-content: space-between;
  100. .name {
  101. font-size: 32rpx;
  102. }
  103. .phone {
  104. font-size: 26rpx;
  105. }
  106. }
  107. .address {
  108. flex: 1;
  109. width: 100%;
  110. font-size: 26rpx;
  111. color: $app-sec-text-color;
  112. }
  113. .status {
  114. width: 100%;
  115. height: 76rpx;
  116. line-height: 76rpx;
  117. justify-content: space-between;
  118. border-top: 2rpx solid $app-base-bg;
  119. .edit-del {
  120. @include flex();
  121. float: right;
  122. height: 100%;
  123. width: 268rpx;
  124. color: $app-sec-text-color;
  125. justify-content: space-between;
  126. .edit, .del {
  127. flex: 1;
  128. height: 100%;
  129. text-align: center;
  130. &.del {
  131. text-align: right;
  132. }
  133. }
  134. }
  135. }
  136. }
  137. .bottom {
  138. height: 88rpx;
  139. }
  140. }
  141. .noaddress {
  142. @include flex();
  143. height: 100%;
  144. color: $app-sec-text-color;
  145. }
  146. .add-address {
  147. left: 0;
  148. bottom: 0;
  149. margin: 0;
  150. width: 100%;
  151. position: fixed;
  152. border-radius: 0;
  153. }
  154. }
  155. </style>