2025-10-20

收货地址完成
This commit is contained in:
2025-10-20 10:33:19 +08:00
parent 448f281570
commit 091b655a0f
3 changed files with 90 additions and 21 deletions

View File

@@ -9,6 +9,10 @@ const baseURL = "http://192.168.0.26:3000/api"
export const addressAPI = {
// 列表
getList: (params) => http.get(baseURL + '/addresses', params),
addAddress: (data) => http.post(baseURL + "/addresses", data),
getAddress: (id) => http.get(baseURL + `/addresses/${id}`),
editAddress: (data) => http.put(baseURL + `/addresses/${data.id}`, data),
delAddress: (id) => http.delete(baseURL + `/addresses/${id}`)
}
export default {

View File

@@ -34,7 +34,8 @@
</view>
</view>
<view class="item-icon">
<image v-if="!isManage" style="width: 100%;height: 100%;" src="/static/icon/Edit.png" mode="">
<image v-if="!isManage" @click="handleEdit(item)" style="width: 100%;height: 100%;"
src="/static/icon/Edit.png" mode="">
</image>
<template v-else>
<image v-if="!isIncludeId(item.id)" style="width: 100%;height: 100%;"
@@ -48,7 +49,7 @@
</scroll-view>
<!-- 新增/修改 -->
<u-popup v-model="showForm" mode="bottom" length="60%" class="form-popup" @close="form={}">
<u-popup v-model="showForm" mode="bottom" length="60%" class="form-popup" @close="form={label:0}">
<view class="form">
<view class="form-item u-m-b-30">
<view class="item-title">
@@ -61,7 +62,7 @@
<image class="must-icon" src="/static/my/must.png" mode=""></image>详细地址与门牌号
</view>
<view class="item-value">
<u-input v-model="form.detailed_address" placeholder="请输入详细地址与门牌号" type="text" />
<u-input v-model="form.detailed_address" maxlength="30" placeholder="请输入详细地址与门牌号" type="text" />
</view>
</view>
<view class="form-item">
@@ -69,7 +70,7 @@
<image class="must-icon" src="/static/my/must.png" mode=""></image>收货人名字
</view>
<view class="item-value">
<u-input v-model="form.receiver_name" placeholder="请输入收货人名字" type="text" />
<u-input v-model="form.recipient_name" maxlength="10" placeholder="请输入收货人名字" type="text" />
</view>
</view>
<view class="form-item">
@@ -77,7 +78,7 @@
<image class="must-icon" src="/static/my/must.png" mode=""></image>手机号
</view>
<view class="item-value">
<u-input v-model="form.receiver_phone" placeholder="请输入收货人名字" type="text" />
<u-input v-model="form.phone" maxlength="11" type="number" placeholder="请输入收货人手机号" />
</view>
</view>
<view class="form-item">
@@ -85,14 +86,14 @@
标签
</view>
<view class="item-tag u-m-t-10">
<span class="active"></span>
<span>公司</span>
<span>学校</span>
<span :class="{active:form.label==0}" @click="handleChangeTag(0)"></span>
<span :class="{active:form.label==1}" @click="handleChangeTag(1)">公司</span>
<span :class="{active:form.label==2}" @click="handleChangeTag(2)">学校</span>
</view>
</view>
<view class="form-item">
<view class="item-title">
<span class="u-m-r-10">是否设置为默认</span><u-checkbox v-model="form.is_default"
<span class="u-m-r-10">是否设置为默认地址</span><u-checkbox v-model="form.is_default"
:disabled="false"></u-checkbox>
</view>
</view>
@@ -105,6 +106,8 @@
value-name="code" child-name="children" @confirm="handleRegion"></u-select>
<!-- 确认是否删除 -->
<u-modal v-model="showDel" content="是否删除选中的地址" :show-cancel-button="true" @confirm="handleDel"></u-modal>
<!-- 提示 -->
<u-toast ref="msgRef" />
</view>
</template>
@@ -128,16 +131,42 @@
fontSize: '40rpx',
lineHeight: '52px'
}
const msgRef = ref()
const isManage = ref(false)
const showDel = ref(false)
const showForm = ref(false)
const showRegitionPicker = ref(false)
const form = ref({})
const form = ref({
label: 0
})
const handleAdd = () => {
showForm.value = true
}
const handleEdit = (item) => {
let data = {
id: item.id,
regionLabel: item.province_name + '/' + item.district_name + '/' + item.city_name,
province_code: item.province,
city_code: item.city,
district_code: item.district,
detailed_address: item.detailed_address,
recipient_name: item.receiver_name,
phone: item.receiver_phone,
is_default: item.is_default
}
if (item.label == '家') {
data.label = 0
}
if (item.label == '公司') {
data.label = 1
}
if (item.label == '学校') {
data.label = 2
}
form.value = data
showForm.value = true
}
const handleManage = () => {
if (isManage.value) {
ids.value = []
@@ -147,8 +176,18 @@
const showDelModel = () => {
showDel.value = true
}
const handleDel = () => {
const handleDel = async () => {
// TODO 删除
for (var i = 0; i < ids.value.length; i++) {
await addressAPI.delAddress(ids.value[i])
}
msgRef.value.show({
title: '删除成功',
type: 'success'
})
isManage.value = false
ids.value = []
loadData()
}
// 打开省市区选择
const openProvince = () => {
@@ -157,14 +196,39 @@
// 选择省市区
const handleRegion = (e) => {
form.value.regionLabel = e[0].label + "/" + e[1].label + "/" + e[2].label
form.value.province = e[0].value
form.value.city = e[1].value
form.value.district = e[2].value
form.value.district_id = e[2].value
form.value.province_code = e[0].value
form.value.city_code = e[1].value
form.value.district_code = e[2].value
}
const handleChangeTag = (val) => {
form.value.label = val
}
// 确认提交
const handleSubmit = () => {
if (form.value.id != null) {
addressAPI.editAddress(form.value).then(res => {
if (res.success) {
msgRef.value.show({
title: '修改成功',
type: 'success'
})
showForm.value = false
loadData()
}
})
} else {
addressAPI.addAddress(form.value).then(res => {
if (res.success) {
msgRef.value.show({
title: '添加成功',
type: 'success'
})
showForm.value = false
loadData()
}
})
}
}
const scrollHeight = ref(0)

View File

@@ -8,9 +8,6 @@ const token = uni.getStorageSync('token')
const commonHeaders = {
'Content-Type': 'application/json'
}
if (token) {
commonHeaders['Authorization'] = `Bearer ${token}`
}
// 请求队列用于管理loading
let requestQueue = 0
@@ -68,7 +65,6 @@ const request = (config) => {
// }
let requestUrl = url
let queryString = ''
if (Object.keys(params).length > 0) {
@@ -78,6 +74,11 @@ const request = (config) => {
requestUrl += (requestUrl.includes('?') ? '&' : '?') + queryString
}
const currToken = uni.getStorageSync('token')
if (currToken) {
commonHeaders.Authorization = `Bearer ${currToken}`
}
// 合并请求头
const requestHeader = {
...commonHeaders,