list.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. list: [],
  35. options: [{
  36. text: '设为默认',
  37. style: {
  38. backgroundColor: '#22ac38'
  39. }
  40. },
  41. {
  42. text: '删除',
  43. style: {
  44. backgroundColor: '#dd524d'
  45. }
  46. }
  47. ],
  48. isSelect: false, //是否是选择地址
  49. };
  50. },
  51. onLoad(ops) {
  52. if (ops.id) {
  53. this.selectId = ops.id
  54. this.isSelect = ops.isSelect
  55. }
  56. },
  57. onShow(ops) {
  58. this.getAddressList();
  59. },
  60. methods: {
  61. //选择地址
  62. handleSelectAddr(item) {
  63. uni.$emit('selectAddr', item)
  64. uni.navigateBack({
  65. delta: 1
  66. })
  67. },
  68. //打开删除弹窗
  69. deletePopup(id) {
  70. this.deleteId = id
  71. this.$refs.deleteDialog?.openPopup()
  72. },
  73. // 删除
  74. confirmDelete() {
  75. uni.$u.http.post(`/token/user/address/remove/${this.deleteId}`).then((res) => {
  76. if (res.code == 200) {
  77. this.$u.toast(`删除成功`);
  78. this.getAddressList()
  79. }
  80. })
  81. },
  82. // 设为默认
  83. setDefaultAddress({
  84. id
  85. }) {
  86. uni.$u.http.post(`/token/user/address/setDefault/${id}`).then(res => {
  87. if (res.code == 200) {
  88. uni.showToast({
  89. icon: "none",
  90. title: "设置默认地址成功"
  91. })
  92. this.getAddressList()
  93. } else {
  94. uni.showToast(res.msg)
  95. }
  96. })
  97. },
  98. getAddressList() {
  99. this.loading = true;
  100. uni.$u.http.get('/token/user/address/list?content=' + '').then(res => {
  101. if (res.code == 200) {
  102. this.list = res.data;
  103. }
  104. }).finally(() => this.loading = false)
  105. }
  106. },
  107. };
  108. </script>
  109. <style lang="scss" scoped>
  110. .list {
  111. padding: 20rpx 30rpx 180rpx;
  112. box-sizing: border-box;
  113. }
  114. </style>