普兆健康管家前端代码仓库
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.

160 lines
3.2 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. onDelete(id) {
  58. uni.showToast({
  59. icon: 'loading',
  60. title: '正在删除',
  61. });
  62. // uni.showLoading({
  63. // title: '正在删除...'
  64. // });
  65. try {
  66. // todo: fetch delete
  67. } catch (err) {
  68. }
  69. setTimeout(() => {
  70. this.list = this.list.filter(item => item.id !== id)
  71. this.total = this.list.length
  72. uni.showToast({
  73. icon: 'success',
  74. title: '删除成功',
  75. });
  76. // uni.showToast({
  77. // icon: 'error',
  78. // title: '删除失败',
  79. // });
  80. }, 1000)
  81. },
  82. onEdit(id) {
  83. this.$refs.addressPopup.open(id)
  84. },
  85. onAdd() {
  86. this.$refs.addressPopup.open()
  87. },
  88. },
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. .page__view {
  93. width: 100vw;
  94. min-height: 100vh;
  95. background-color: $uni-bg-color;
  96. position: relative;
  97. /deep/ .nav-bar__view {
  98. position: fixed;
  99. top: 0;
  100. left: 0;
  101. }
  102. }
  103. .main {
  104. padding: calc(var(--status-bar-height) + 160rpx) 40rpx 254rpx 40rpx;
  105. }
  106. .card {
  107. & + & {
  108. margin-top: 40rpx;
  109. }
  110. }
  111. .bottom {
  112. position: fixed;
  113. left: 0;
  114. bottom: 0;
  115. align-items: flex-start;
  116. width: 100vw;
  117. height: 214rpx;
  118. padding: 32rpx 40rpx;
  119. background: #FFFFFF;
  120. box-sizing: border-box;
  121. .btn {
  122. width: 100%;
  123. padding: 16rpx 0;
  124. box-sizing: border-box;
  125. font-family: PingFang SC;
  126. font-weight: 500;
  127. font-size: 36rpx;
  128. line-height: 1;
  129. color: #FFFFFF;
  130. background-image: linear-gradient(to right, #4B348F, #845CFA);
  131. border-radius: 41rpx;
  132. }
  133. }
  134. </style>