普兆健康管家前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.0 KiB

  1. <template>
  2. <view class="page__view">
  3. <navbar title="选择地址" leftClick @leftClick="$utils.navigateBack" color="#191919" bgColor="#FFFFFF" />
  4. <view class="main">
  5. <view class="card" v-for="item in list" :key="item.id">
  6. <addressCard
  7. :data="item"
  8. @defaultChange="onDefaultChange(item.id, $event)"
  9. @click="onSelect(item)"
  10. @edit="onEdit(item.id)"
  11. @delete="onDelete(item.id)"
  12. ></addressCard>
  13. </view>
  14. </view>
  15. <view class="flex bottom">
  16. <button class="btn" @click="onAdd">新建地址</button>
  17. </view>
  18. <addressPopup ref="addressPopup" @submitted="getData"></addressPopup>
  19. </view>
  20. </template>
  21. <script>
  22. import mixinsList from '@/mixins/list.js'
  23. import addressCard from './addressCard.vue'
  24. import addressPopup from '@/pages_order/address/addressPopup.vue'
  25. export default {
  26. mixins: [mixinsList],
  27. components: {
  28. addressCard,
  29. addressPopup,
  30. },
  31. data() {
  32. return {
  33. mixinsListApi: 'getAddressList',
  34. queryParams: {
  35. pageNo: 1,
  36. pageSize: 10,
  37. },
  38. }
  39. },
  40. onLoad() {
  41. this.queryParams.userId = this.userInfo.id
  42. this.getData()
  43. },
  44. methods: {
  45. async onDefaultChange(addressId) {
  46. console.log('onDefaultChange', addressId)
  47. try {
  48. await this.$fetch('setAddressDefault', { addressId })
  49. this.getData()
  50. } catch (err) {
  51. }
  52. },
  53. onSelect(data) {
  54. this.$store.commit('setAddressInfo', data)
  55. this.$utils.navigateBack()
  56. },
  57. async onDelete(addressId) {
  58. uni.showToast({
  59. icon: 'loading',
  60. title: '正在删除',
  61. });
  62. try {
  63. await this.$fetch('deleteAddress', { addressId })
  64. uni.showToast({
  65. icon: 'success',
  66. title: '删除成功',
  67. });
  68. this.getData()
  69. } catch (err) {
  70. }
  71. },
  72. onEdit(id) {
  73. this.$refs.addressPopup.open(id)
  74. },
  75. onAdd() {
  76. this.$refs.addressPopup.open()
  77. },
  78. },
  79. }
  80. </script>
  81. <style scoped lang="scss">
  82. .page__view {
  83. width: 100vw;
  84. min-height: 100vh;
  85. background-color: $uni-bg-color;
  86. position: relative;
  87. /deep/ .nav-bar__view {
  88. position: fixed;
  89. top: 0;
  90. left: 0;
  91. }
  92. }
  93. .main {
  94. padding: calc(var(--status-bar-height) + 160rpx) 40rpx 254rpx 40rpx;
  95. }
  96. .card {
  97. & + & {
  98. margin-top: 40rpx;
  99. }
  100. }
  101. .bottom {
  102. position: fixed;
  103. left: 0;
  104. bottom: 0;
  105. align-items: flex-start;
  106. width: 100vw;
  107. // height: 214rpx;
  108. padding: 32rpx 40rpx;
  109. padding-bottom: calc(env(safe-area-inset-bottom) + 32rpx);
  110. background: #FFFFFF;
  111. box-sizing: border-box;
  112. .btn {
  113. width: 100%;
  114. padding: 16rpx 0;
  115. box-sizing: border-box;
  116. font-family: PingFang SC;
  117. font-weight: 500;
  118. font-size: 36rpx;
  119. line-height: 1;
  120. color: #FFFFFF;
  121. background-image: linear-gradient(to right, #4B348F, #845CFA);
  122. border-radius: 41rpx;
  123. }
  124. }
  125. </style>