list.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="container">
  3. <view class="address-list" v-for="(item, index) in addressList" :key="item.id">
  4. <view class="address-item" @click="handleClick" @longpress="handleLongPress(item)">
  5. <view class="left">
  6. <u-avatar :text="item.name ? item.name.slice(0, 1) : 'U'" fontSize="18" randomBgColor></u-avatar>
  7. </view>
  8. <view class="middle">
  9. <view class="info">
  10. <view class="name">{{ item.name }}</view>
  11. <view class="mobile">{{ item.mobile }}</view>
  12. <u-tag class="type" v-if="item.type === 1" text="默认" plain size="mini" type="success"></u-tag>
  13. </view>
  14. <view class="detail">
  15. <u--text :lines="2" size="14" color="#939393" :text="item.detailAddress"></u--text>
  16. </view>
  17. </view>
  18. <navigator class="right" :url="`/pages/address/update?addressId=${item.id}`" open-type="navigate" hover-class="none">
  19. <u-icon name="edit-pen" size="28"></u-icon>
  20. </navigator>
  21. </view>
  22. </view>
  23. <navigator class="fixed-btn-box" url="/pages/address/create" open-type="navigate" hover-class="none">
  24. <u-button type="primary" size="large" text="新增地址"></u-button>
  25. </navigator>
  26. <u-safe-bottom customStyle="background: #ffffff"></u-safe-bottom>
  27. </view>
  28. </template>
  29. <script>
  30. import { getAddressList, deleteAddress } from '../../api/address'
  31. export default {
  32. data() {
  33. return {
  34. addressList: []
  35. }
  36. },
  37. onLoad() {},
  38. onShow() {
  39. this.loadAddressListData()
  40. },
  41. methods: {
  42. loadAddressListData() {
  43. getAddressList().then(res => {
  44. this.addressList = res.data
  45. })
  46. },
  47. handleLongPress(item) {
  48. uni.showModal({
  49. title: '提示',
  50. content: `删除收件人[${item.name}${item.mobile}]\n地址:${item.detailAddress.slice(0, 5)}......${item.detailAddress.slice(-6)}?`,
  51. success: res => {
  52. if (res.confirm) {
  53. deleteAddress({ id: item.id }).then(res => {
  54. uni.$u.toast('地址已删除')
  55. this.loadAddressListData();
  56. })
  57. } else if (res.cancel) {
  58. //console.log('用户点击取消')
  59. }
  60. }
  61. })
  62. },
  63. handleClick(){
  64. // TODO 提交订单时选择地址逻辑
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .address-list {
  71. .address-item {
  72. padding: 10rpx 0;
  73. border-bottom: $custom-border-style;
  74. @include flex-space-between;
  75. .left {
  76. margin: 20rpx;
  77. }
  78. .middle {
  79. flex: 1;
  80. margin: 20rpx;
  81. @include flex(column);
  82. .info {
  83. @include flex-left;
  84. .name {
  85. font-size: 30rpx;
  86. font-weight: 700;
  87. }
  88. .mobile {
  89. font-size: 28rpx;
  90. margin-left: 15rpx;
  91. }
  92. .type {
  93. margin-left: 15rpx;
  94. }
  95. }
  96. .detail {
  97. margin-top: 10rpx;
  98. }
  99. }
  100. .right {
  101. margin: 20rpx;
  102. }
  103. }
  104. }
  105. .fixed-btn-box {
  106. position: fixed;
  107. bottom: 0;
  108. left: 0;
  109. width: 750rpx;
  110. }
  111. </style>