list.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="page">
  3. <NoData v-if="!loading && list.length < 1"></NoData>
  4. <view class="list" v-else>
  5. <AddressCard v-for="item in list" :key="item.id" :address="item" :selected="item.id == selectId"
  6. @delete="deletePopup" @success="getAddressList" @tapItem="handleSelectAddr" :isSelect="isSelect">
  7. </AddressCard>
  8. </view>
  9. <view class="bottom-fixed-con">
  10. <u-button class="flex-1" type="primary"
  11. @click="$u.route({ url: '/pages-mine/pages/address/add-or-update' })">
  12. <text>添加地址</text>
  13. </u-button>
  14. </view>
  15. <common-dialog ref="deleteDialog" title="温馨提示" @confirm="confirmDelete">
  16. <text>确定删除此地址信息吗?</text>
  17. </common-dialog>
  18. </view>
  19. </template>
  20. <script>
  21. import AddressCard from '@/pages-mine/components/address-card.vue';
  22. import commonDialog from '@/components/common-dialog.vue';
  23. export default {
  24. components: {
  25. AddressCard,
  26. commonDialog
  27. },
  28. data() {
  29. return {
  30. selectId: '',
  31. deleteId: '', //要删除的id
  32. isBack: false,
  33. loading: false,
  34. editAddress: 0,
  35. list: [],
  36. options: [{
  37. text: '设为默认',
  38. style: {
  39. backgroundColor: '#22ac38'
  40. }
  41. },
  42. {
  43. text: '删除',
  44. style: {
  45. backgroundColor: '#dd524d'
  46. }
  47. }
  48. ],
  49. isSelect: false, //是否是选择地址
  50. };
  51. },
  52. onLoad(ops) {
  53. if (ops.id) {
  54. this.selectId = ops.id
  55. this.isSelect = ops.isSelect
  56. this.editAddress = ops.editAddress || 0
  57. }
  58. },
  59. onShow(ops) {
  60. this.getAddressList();
  61. },
  62. methods: {
  63. //选择地址
  64. handleSelectAddr(item) {
  65. if (this.editAddress == 1) {
  66. uni.$emit('selectEditAddr', item)
  67. uni.setStorageSync('selectEditAddr', item)
  68. } else {
  69. uni.$emit('selectAddr', item)
  70. uni.setStorageSync('selectAddr', item)
  71. }
  72. uni.navigateBack({
  73. delta: 1
  74. })
  75. },
  76. //打开删除弹窗
  77. deletePopup(id) {
  78. this.deleteId = id
  79. this.$refs.deleteDialog?.openPopup()
  80. },
  81. // 删除
  82. confirmDelete() {
  83. uni.$u.http.post(`/token/user/address/remove/${this.deleteId}`).then((res) => {
  84. if (res.code == 200) {
  85. this.$u.toast(`删除成功`);
  86. this.getAddressList()
  87. }
  88. })
  89. },
  90. // 设为默认
  91. setDefaultAddress({
  92. id
  93. }) {
  94. uni.$u.http.post(`/token/user/address/setDefault/${id}`).then(res => {
  95. if (res.code == 200) {
  96. uni.showToast({
  97. icon: "none",
  98. title: "设置默认地址成功"
  99. })
  100. this.getAddressList()
  101. } else {
  102. uni.showToast(res.msg)
  103. }
  104. })
  105. },
  106. getAddressList() {
  107. this.loading = true;
  108. uni.$u.http.get('/token/user/address/list?content=' + '').then(res => {
  109. if (res.code == 200) {
  110. this.list = res.data;
  111. }
  112. }).finally(() => this.loading = false)
  113. }
  114. },
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. .list {
  119. padding: 20rpx 30rpx 180rpx;
  120. box-sizing: border-box;
  121. }
  122. </style>