address-edit.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="family-address" :style="{ '--font-scale': fontScale }">
  3. <view class="page-title">家庭地址设置</view>
  4. <view class="form-section">
  5. <view class="section-title">所在街道</view>
  6. <address-picker
  7. v-model="formData.streetId"
  8. @change="onAddressChange"
  9. ref="addressPicker"
  10. />
  11. </view>
  12. <view class="form-section" v-if="formData.fullName">
  13. <view class="section-title">当前地址</view>
  14. <view class="current-address">
  15. <text>{{ formData.fullName }}</text>
  16. </view>
  17. </view>
  18. <button class="save-btn" @click="saveAddress" :loading="loading">保存地址</button>
  19. </view>
  20. </template>
  21. <script>
  22. import AddressPicker from '@/components/address-picker.vue'
  23. import { getFamilyDetail, updateFamilyAddress } from '@/utils/api.js'
  24. import fontScaleMixin from '@/mixins/font-scale.js'
  25. export default {
  26. mixins: [fontScaleMixin],
  27. components: {
  28. AddressPicker
  29. },
  30. data() {
  31. return {
  32. loading: false,
  33. familyId: null,
  34. formData: {
  35. streetId: null,
  36. province: null,
  37. city: null,
  38. district: null,
  39. street: null,
  40. fullName: ''
  41. }
  42. }
  43. },
  44. onLoad(options) {
  45. if (options.familyId) {
  46. this.familyId = parseInt(options.familyId)
  47. this.loadFamilyInfo()
  48. }
  49. },
  50. methods: {
  51. async loadFamilyInfo() {
  52. try {
  53. const res = await getFamilyDetail(this.familyId)
  54. const family = res.data
  55. if (family) {
  56. this.formData.streetId = family.streetId
  57. this.formData.province = family.province
  58. this.formData.city = family.city
  59. this.formData.district = family.district
  60. this.formData.street = family.street
  61. this.formData.fullName = `${family.province || ''}${family.city || ''}${family.district || ''}${family.street || ''}`
  62. }
  63. } catch (e) {
  64. console.error('加载家庭信息失败', e)
  65. }
  66. },
  67. onAddressChange(data) {
  68. this.formData.streetId = data.streetId
  69. this.formData.province = data.province
  70. this.formData.city = data.city
  71. this.formData.district = data.district
  72. this.formData.street = data.street
  73. this.formData.fullName = data.fullName || ''
  74. },
  75. async saveAddress() {
  76. if (!this.formData.streetId) {
  77. uni.showToast({ title: '请选择街道地址', icon: 'none' })
  78. return
  79. }
  80. this.loading = true
  81. try {
  82. await updateFamilyAddress(this.familyId, {
  83. streetId: this.formData.streetId,
  84. province: this.formData.province,
  85. city: this.formData.city,
  86. district: this.formData.district,
  87. street: this.formData.street
  88. })
  89. uni.showToast({ title: '保存成功', icon: 'success' })
  90. setTimeout(() => {
  91. uni.navigateBack()
  92. }, 1500)
  93. } catch (e) {
  94. console.error('保存地址失败', e)
  95. uni.showToast({ title: '保存失败', icon: 'none' })
  96. } finally {
  97. this.loading = false
  98. }
  99. }
  100. }
  101. }
  102. </script>
  103. <style scoped lang="scss">
  104. .family-address {
  105. min-height: 100vh;
  106. background: $facade-fill-2;
  107. padding: 20rpx;
  108. }
  109. .page-title {
  110. font-size: calc(36rpx * var(--font-scale, 1));
  111. font-weight: bold;
  112. color: $facade-text-strong;
  113. padding: $uni-space-lg 0;
  114. }
  115. .form-section {
  116. background: $app-surface;
  117. border-radius: 16rpx;
  118. margin-bottom: 20rpx;
  119. padding: 20rpx;
  120. }
  121. .section-title {
  122. font-size: calc(30rpx * var(--font-scale, 1));
  123. color: $facade-text-strong;
  124. font-weight: bold;
  125. margin-bottom: 20rpx;
  126. }
  127. .current-address {
  128. background: $facade-fill-ghost-2;
  129. padding: 20rpx;
  130. border-radius: 8rpx;
  131. }
  132. .current-address text {
  133. font-size: calc(28rpx * var(--font-scale, 1));
  134. color: $facade-text-body;
  135. }
  136. .save-btn {
  137. margin-top: 40rpx;
  138. width: 100%;
  139. height: 88rpx;
  140. background: linear-gradient(135deg, $accent-indigo 0%, $accent-indigo-deep 100%);
  141. color: $app-surface;
  142. border-radius: 24rpx;
  143. font-size: calc(32rpx * var(--font-scale, 1));
  144. display: flex;
  145. align-items: center;
  146. justify-content: center;
  147. }
  148. </style>