完善下单逻辑及其ui展示,修复支付倒计时显示错误bug
This commit is contained in:
@@ -17,6 +17,15 @@
|
||||
<input class="input" v-model="regionString" placeholder="省市区县、乡镇等" placeholder-class="placeholder" />
|
||||
<text class="arrow-icon">›</text>
|
||||
</view>
|
||||
<view class="location-action-row">
|
||||
<view class="location-action-btn" @click="fillCurrentLocation">
|
||||
<text class="location-action-text">获取当前位置</text>
|
||||
</view>
|
||||
<view class="location-action-btn" @click="pickLocation">
|
||||
<text class="location-action-text">地图选点</text>
|
||||
</view>
|
||||
</view>
|
||||
<text v-if="locationHint != ''" class="location-hint">{{ locationHint }}</text>
|
||||
<view class="form-item detail-item">
|
||||
<text class="label">详细地址</text>
|
||||
<textarea class="textarea" v-model="formData.detail" placeholder="街道、楼牌号等" placeholder-class="placeholder" maxlength="100"></textarea>
|
||||
@@ -85,6 +94,9 @@ type Address = {
|
||||
detail: string
|
||||
isDefault: boolean
|
||||
label?: string
|
||||
latitude?: number
|
||||
longitude?: number
|
||||
coordinateType?: string
|
||||
}
|
||||
|
||||
const isEdit = ref(false)
|
||||
@@ -92,6 +104,9 @@ const addressId = ref('')
|
||||
const regionString = ref('')
|
||||
const tags = ['家', '公司', '学校']
|
||||
const smartInput = ref('')
|
||||
const locationHint = ref('')
|
||||
const latitude = ref(0)
|
||||
const longitude = ref(0)
|
||||
|
||||
type AddressForm = {
|
||||
name: string
|
||||
@@ -120,6 +135,9 @@ const loadAddress = async (id: string) => {
|
||||
formData.isDefault = address.is_default
|
||||
formData.label = address.label ?? ''
|
||||
regionString.value = `${address.province} ${address.city} ${address.district}`.trim()
|
||||
latitude.value = address.latitude ?? 0
|
||||
longitude.value = address.longitude ?? 0
|
||||
locationHint.value = latitude.value != 0 || longitude.value != 0 ? `已定位:${latitude.value}, ${longitude.value}` : ''
|
||||
} else {
|
||||
// 如果Supabase没有找到,尝试从本地存储加载
|
||||
const storedAddresses = uni.getStorageSync('addresses')
|
||||
@@ -133,6 +151,9 @@ const loadAddress = async (id: string) => {
|
||||
formData.isDefault = localAddress.isDefault
|
||||
formData.label = localAddress.label ?? ''
|
||||
regionString.value = `${localAddress.province} ${localAddress.city} ${localAddress.district}`.trim()
|
||||
latitude.value = localAddress.latitude ?? 0
|
||||
longitude.value = localAddress.longitude ?? 0
|
||||
locationHint.value = latitude.value != 0 || longitude.value != 0 ? `已定位:${latitude.value}, ${longitude.value}` : ''
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,6 +172,9 @@ const loadAddress = async (id: string) => {
|
||||
formData.isDefault = address.isDefault
|
||||
formData.label = address.label ?? ''
|
||||
regionString.value = `${address.province} ${address.city} ${address.district}`.trim()
|
||||
latitude.value = address.latitude ?? 0
|
||||
longitude.value = address.longitude ?? 0
|
||||
locationHint.value = latitude.value != 0 || longitude.value != 0 ? `已定位:${latitude.value}, ${longitude.value}` : ''
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析本地地址数据失败', e)
|
||||
@@ -159,6 +183,42 @@ const loadAddress = async (id: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const applyLocation = (latitudeValue: number, longitudeValue: number, addressText: string, locationName: string) => {
|
||||
latitude.value = latitudeValue
|
||||
longitude.value = longitudeValue
|
||||
locationHint.value = `已定位:${latitudeValue}, ${longitudeValue}`
|
||||
if (addressText != '') {
|
||||
regionString.value = addressText
|
||||
}
|
||||
if (locationName != '' && formData.detail == '') {
|
||||
formData.detail = locationName
|
||||
}
|
||||
}
|
||||
|
||||
const fillCurrentLocation = () => {
|
||||
uni.getLocation({
|
||||
type: 'gcj02',
|
||||
success: (res) => {
|
||||
applyLocation(res.latitude, res.longitude, regionString.value, '')
|
||||
uni.showToast({ title: '已获取当前位置', icon: 'success' })
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '定位失败,请手动输入地址', icon: 'none' })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const pickLocation = () => {
|
||||
uni.chooseLocation({
|
||||
success: (res) => {
|
||||
applyLocation(res.latitude, res.longitude, res.address ?? '', res.name ?? '')
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '当前环境不支持地图选点,可手动输入', icon: 'none' })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options == null) return
|
||||
const optionsObj = options as UTSJSONObject
|
||||
@@ -216,7 +276,10 @@ const saveAddress = async () => {
|
||||
detail_address: formData.detail,
|
||||
postal_code: '', // 如果需要可以添加邮政编码字段
|
||||
is_default: formData.isDefault,
|
||||
label: formData.label
|
||||
label: formData.label,
|
||||
latitude: latitude.value,
|
||||
longitude: longitude.value,
|
||||
coordinate_type: 'gcj02'
|
||||
} as AddAddressParams
|
||||
|
||||
let success = false
|
||||
@@ -231,8 +294,11 @@ const saveAddress = async () => {
|
||||
district: district,
|
||||
detail_address: formData.detail,
|
||||
postal_code: '',
|
||||
is_default: formData.isDefault,
|
||||
label: formData.label
|
||||
is_default: formData.isDefault,
|
||||
label: formData.label,
|
||||
latitude: latitude.value,
|
||||
longitude: longitude.value,
|
||||
coordinate_type: 'gcj02'
|
||||
} as UpdateAddressParams
|
||||
success = await supabaseService.updateAddress(addressId.value, updateData)
|
||||
} else {
|
||||
@@ -271,7 +337,10 @@ const saveAddress = async () => {
|
||||
district: district,
|
||||
detail: formData.detail,
|
||||
isDefault: formData.isDefault,
|
||||
label: formData.label
|
||||
label: formData.label,
|
||||
latitude: latitude.value,
|
||||
longitude: longitude.value,
|
||||
coordinateType: 'gcj02'
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -284,7 +353,10 @@ const saveAddress = async () => {
|
||||
district: district,
|
||||
detail: formData.detail,
|
||||
isDefault: formData.isDefault,
|
||||
label: formData.label
|
||||
label: formData.label,
|
||||
latitude: latitude.value,
|
||||
longitude: longitude.value,
|
||||
coordinateType: 'gcj02'
|
||||
}
|
||||
addresses.push(newAddress)
|
||||
}
|
||||
@@ -437,6 +509,38 @@ const deleteAddress = () => {
|
||||
border-radius: 16px; /* 详细地址区域也增加圆角 */
|
||||
}
|
||||
|
||||
.location-action-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.location-action-btn {
|
||||
flex: 1;
|
||||
min-height: 40px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #f1f5f9;
|
||||
border-radius: 20px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.location-action-btn:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.location-action-text {
|
||||
font-size: 13px;
|
||||
color: #2563eb;
|
||||
}
|
||||
|
||||
.location-hint {
|
||||
display: block;
|
||||
margin-bottom: 12px;
|
||||
font-size: 12px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.detail-item .label {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user