| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <template>
- <view class="family-address">
- <view class="page-title">家庭地址设置</view>
-
- <view class="form-section">
- <view class="section-title">所在街道</view>
- <address-picker
- v-model="formData.streetId"
- @change="onAddressChange"
- ref="addressPicker"
- />
- </view>
-
- <view class="form-section" v-if="formData.fullName">
- <view class="section-title">当前地址</view>
- <view class="current-address">
- <text>{{ formData.fullName }}</text>
- </view>
- </view>
-
- <button class="save-btn" @click="saveAddress" :loading="loading">保存地址</button>
- </view>
- </template>
- <script>
- import AddressPicker from '@/components/address-picker.vue'
- import { getFamilyDetail, updateFamilyAddress } from '@/utils/api.js'
- export default {
- components: {
- AddressPicker
- },
- data() {
- return {
- loading: false,
- familyId: null,
- formData: {
- streetId: null,
- province: null,
- city: null,
- district: null,
- street: null,
- fullName: ''
- }
- }
- },
- onLoad(options) {
- if (options.familyId) {
- this.familyId = parseInt(options.familyId)
- this.loadFamilyInfo()
- }
- },
- methods: {
- async loadFamilyInfo() {
- try {
- const res = await getFamilyDetail(this.familyId)
- const family = res.data
-
- if (family) {
- this.formData.streetId = family.streetId
- this.formData.province = family.province
- this.formData.city = family.city
- this.formData.district = family.district
- this.formData.street = family.street
- this.formData.fullName = `${family.province || ''}${family.city || ''}${family.district || ''}${family.street || ''}`
- }
- } catch (e) {
- console.error('加载家庭信息失败', e)
- }
- },
-
- onAddressChange(data) {
- this.formData.streetId = data.streetId
- this.formData.province = data.province
- this.formData.city = data.city
- this.formData.district = data.district
- this.formData.street = data.street
- this.formData.fullName = data.fullName || ''
- },
-
- async saveAddress() {
- if (!this.formData.streetId) {
- uni.showToast({ title: '请选择街道地址', icon: 'none' })
- return
- }
-
- this.loading = true
- try {
- await updateFamilyAddress(this.familyId, {
- streetId: this.formData.streetId,
- province: this.formData.province,
- city: this.formData.city,
- district: this.formData.district,
- street: this.formData.street
- })
-
- uni.showToast({ title: '保存成功', icon: 'success' })
- setTimeout(() => {
- uni.navigateBack()
- }, 1500)
- } catch (e) {
- console.error('保存地址失败', e)
- uni.showToast({ title: '保存失败', icon: 'none' })
- } finally {
- this.loading = false
- }
- }
- }
- }
- </script>
- <style scoped>
- .family-address {
- min-height: 100vh;
- background: #f5f5f5;
- padding: 20rpx;
- }
- .page-title {
- font-size: 36rpx;
- font-weight: bold;
- color: #333;
- padding: 30rpx 0;
- }
- .form-section {
- background: #fff;
- border-radius: 16rpx;
- margin-bottom: 20rpx;
- padding: 20rpx;
- }
- .section-title {
- font-size: 30rpx;
- color: #333;
- font-weight: bold;
- margin-bottom: 20rpx;
- }
- .current-address {
- background: #f9f9f9;
- padding: 20rpx;
- border-radius: 8rpx;
- }
- .current-address text {
- font-size: 28rpx;
- color: #666;
- }
- .save-btn {
- margin-top: 40rpx;
- width: 100%;
- height: 88rpx;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: #fff;
- border-radius: 44rpx;
- font-size: 32rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- </style>
|