list.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. }
  56. if (ops.isSelect) {
  57. this.isSelect = ops.isSelect
  58. }
  59. if (ops.editAddress) {
  60. this.editAddress = ops.editAddress
  61. }
  62. },
  63. onShow(ops) {
  64. this.getAddressList();
  65. },
  66. methods: {
  67. //选择地址
  68. handleSelectAddr(item) {
  69. if (!this.isSelect) return;
  70. if (this.editAddress == 1) {
  71. uni.$emit('selectEditAddr', item)
  72. uni.setStorageSync('selectEditAddr', item)
  73. } else {
  74. uni.$emit('selectAddr', item)
  75. uni.setStorageSync('selectAddr', item)
  76. }
  77. uni.navigateBack({
  78. delta: 1
  79. })
  80. },
  81. //打开删除弹窗
  82. deletePopup(id) {
  83. this.deleteId = id
  84. this.$refs.deleteDialog?.openPopup()
  85. },
  86. // 删除
  87. confirmDelete() {
  88. uni.$u.http.post(`/token/user/address/remove/${this.deleteId}`).then((res) => {
  89. if (res.code == 200) {
  90. this.$u.toast(`删除成功`);
  91. this.getAddressList()
  92. }
  93. })
  94. },
  95. // 设为默认
  96. setDefaultAddress({
  97. id
  98. }) {
  99. uni.$u.http.post(`/token/user/address/setDefault/${id}`).then(res => {
  100. if (res.code == 200) {
  101. uni.showToast({
  102. icon: "none",
  103. title: "设置默认地址成功"
  104. })
  105. this.getAddressList()
  106. } else {
  107. uni.showToast(res.msg)
  108. }
  109. })
  110. },
  111. getAddressList() {
  112. this.loading = true;
  113. uni.$u.http.get('/token/user/address/list?content=' + '').then(res => {
  114. if (res.code == 200) {
  115. this.list = res.data;
  116. }
  117. }).finally(() => this.loading = false)
  118. }
  119. },
  120. };
  121. </script>
  122. <style lang="scss" scoped>
  123. .list {
  124. padding: 20rpx 30rpx 180rpx;
  125. box-sizing: border-box;
  126. }
  127. </style>