feat: 收货地址

This commit is contained in:
黄泽群
2025-10-28 14:24:47 +08:00
committed by charles
parent bec363fcbf
commit 7f42cb7859
4 changed files with 1499 additions and 1174 deletions
+8
View File
@@ -64,3 +64,11 @@ export function settlementOrder(data) {
data, data,
}); });
} }
export function getPostageQuery(data) {
return request({
url: "/cart/getPostage",
method: "post",
data,
});
}
+3
View File
@@ -35,6 +35,9 @@ export default {
mounted() { mounted() {
this.getAddressList(); this.getAddressList();
}, },
activated () {
this.getAddressList();
},
methods: { methods: {
// 添加地址 // 添加地址
jumpAddAddress() { jumpAddAddress() {
@@ -1,33 +1,59 @@
<template> <template>
<view class="address_add_warp"> <view class="address_add_warp">
<Header :leftTitle="$t('address.add.title')" left-path-type="navigateTo" :leftPath="leftPath" /> <Header
:leftTitle="$t('address.add.title')"
left-path-type="navigateTo"
:leftPath="leftPath"
/>
<view class="address_form"> <view class="address_form">
<view class="add_form_item add_form_item_but"> <view class="add_form_item add_form_item_but">
<view class="add_form_title">收货人</view> <view class="add_form_title">收货人</view>
<up-input placeholder="收货人" border="surround" v-model="form.name" :customStyle="{ <up-input
'border': '0rpx', placeholder="收货人"
}"></up-input> border="surround"
v-model="form.name"
:customStyle="{
border: '0rpx',
}"
></up-input>
</view> </view>
<view class="add_form_item add_form_item_but"> <view class="add_form_item add_form_item_but">
<view class="add_form_title">手机号码</view> <view class="add_form_title">手机号码</view>
<up-input placeholder="请填写收货人手机号" border="surround" v-model="form.mobile" :customStyle="{ <up-input
'border': '0rpx', placeholder="请填写收货人手机号"
}" type="number"></up-input> border="surround"
v-model="form.mobile"
:customStyle="{
border: '0rpx',
}"
type="number"
></up-input>
</view> </view>
<view class="add_form_item add_form_item_but"> <view class="add_form_item add_form_item_but">
<view class="add_form_title">所在地区</view> <view class="add_form_title">所在地区</view>
<view class="region_warp" @click="regionShowCheck(true)"> <view class="region_warp" @click="regionShowCheck(true)">
<view style="color: #808080;margin-left: 22rpx;font-size: 28rpx;">{{ (form.regionStr && <view style="color: #808080; margin-left: 22rpx; font-size: 28rpx">{{
form.regionStr.join("/")) || "所在地区" }}</view> (form.regionStr && form.regionStr.join("/")) || "所在地区"
<up-image src="/static/common/right_soild.png" width="14" height="14" bgColor="#f1f6ff00"></up-image> }}</view>
<up-image
src="/static/common/right_soild.png"
width="14"
height="14"
bgColor="#f1f6ff00"
></up-image>
</view> </view>
</view> </view>
<view class="add_form_item"> <view class="add_form_item">
<view class="add_form_title">详细地址</view> <view class="add_form_title">详细地址</view>
<up-input placeholder="门牌号、小区、楼栋号、单元室等" border="surround" v-model="form.address" :customStyle="{ <up-input
'border': '0rpx', placeholder="门牌号、小区、楼栋号、单元室等"
'height': '100rpx', border="surround"
}"></up-input> v-model="form.address"
:customStyle="{
border: '0rpx',
height: '100rpx',
}"
></up-input>
</view> </view>
</view> </view>
<!-- <view class="address_default"> <!-- <view class="address_default">
@@ -39,20 +65,27 @@
> >
</up-switch> </up-switch>
</view> --> </view> -->
<view class="add_but" @click="addAddress"> <view class="add_but" @click="addAddress"> 保存地址 </view>
保存地址
</view>
<up-toast ref="uToastRef"></up-toast> <up-toast ref="uToastRef"></up-toast>
<up-picker :show="regionShow" ref="uPickerRef" :columns="regionColumns" @confirm="regionConfirm" <up-picker
:loading="regionLoading" @change="regionChange" keyName="label" itemHeight="34" @cancel="regionShow = false" :show="regionShow"
@close="regionShow = false"></up-picker> ref="uPickerRef"
:columns="regionColumns"
@confirm="regionConfirm"
:loading="regionLoading"
@change="regionChange"
keyName="label"
itemHeight="34"
@cancel="regionShow = false"
@close="regionShow = false"
></up-picker>
</view> </view>
</template> </template>
<script> <script>
import { editAddress, getAddressDetail } from '@/api/address.js' import { editAddress, getAddressDetail } from "@/api/address.js";
import { getCascadeRegion } from '@/api/common.js' import { getCascadeRegion } from "@/api/common.js";
import Header from '@/components/header.vue'; import Header from "@/components/header.vue";
export default { export default {
components: { Header }, components: { Header },
@@ -73,17 +106,26 @@ export default {
regionShow: false, regionShow: false,
regionColumns: [], regionColumns: [],
regionLoading: false, regionLoading: false,
leftPath: "/pages/mine_package/mine_address/mine_address", // leftPath: "/pages/mine_package/mine_address/mine_address",
} leftPath: "",
};
}, },
onLoad(option) { onLoad(option) {
const id = option.id; const id = option.id;
const detail = option.detail;
if (id && id !== 0) { if (id && id !== 0) {
this.getById(id); this.getById(id);
} }
const ids = option.ids; const ids = option.ids;
if (ids && ids !== 0) { if (ids && ids !== 0) {
this.leftPath = "/pages/order_package/order_submit/order_submit?ids=" + ids + "&addressShow=true"; this.leftPath =
"/pages/order_package/order_submit/order_submit?ids=" +
ids +
"&addressShow=true";
} else if (detail) {
this.leftPath = "";
} else {
this.leftPath = "/pages/mine_package/mine_address/mine_address";
} }
}, },
methods: { methods: {
@@ -93,7 +135,7 @@ export default {
async getById(id) { async getById(id) {
const parasm = { const parasm = {
id, id,
} };
const resp = await getAddressDetail(parasm); const resp = await getAddressDetail(parasm);
if (resp && resp.bizcode === 100) { if (resp && resp.bizcode === 100) {
const data = resp.data; const data = resp.data;
@@ -133,11 +175,18 @@ export default {
async regionShowCheck(status) { async regionShowCheck(status) {
if (status) { if (status) {
const nation = await this.getRegion(0); const nation = await this.getRegion(0);
const province = nation && nation.length !== 0 ? await this.getRegion(nation[0].id) : []; const province =
const city = province && province.length !== 0 ? await this.getRegion(province[0].id) : []; nation && nation.length !== 0
const area = city && city.length !== 0 ? await this.getRegion(city[0].id) : []; ? await this.getRegion(nation[0].id)
console.log('选择地址的弹框', nation, province, city, area,status) : [];
this.regionColumns = [nation, province, city, area,]; const city =
province && province.length !== 0
? await this.getRegion(province[0].id)
: [];
const area =
city && city.length !== 0 ? await this.getRegion(city[0].id) : [];
console.log("选择地址的弹框", nation, province, city, area, status);
this.regionColumns = [nation, province, city, area];
} else { } else {
this.regionColumns = [[], [], [], []]; this.regionColumns = [[], [], [], []];
} }
@@ -145,34 +194,30 @@ export default {
}, },
// 数据交互 // 数据交互
async getRegion(pId) { async getRegion(pId) {
this.regionLoading = true this.regionLoading = true;
const params = { const params = {
parentId: pId, parentId: pId,
} };
const resp = await getCascadeRegion(params); const resp = await getCascadeRegion(params);
const arrOption = []; const arrOption = [];
if (resp.bizcode === 100) { if (resp.bizcode === 100) {
const data = resp.data; const data = resp.data;
if (data && data.length !== 0) { if (data && data.length !== 0) {
data.map(item => { data.map((item) => {
arrOption.push({ arrOption.push({
id: item.id, id: item.id,
label: item.name, label: item.name,
pId: pId, pId: pId,
}) });
}) });
} }
} }
this.regionLoading = false; this.regionLoading = false;
return arrOption return arrOption;
}, },
// 地区改变 // 地区改变
async regionChange(e) { async regionChange(e) {
const { const { columnIndex, index, picker } = e;
columnIndex,
index,
picker
} = e;
const selectData = this.regionColumns[columnIndex][index]; const selectData = this.regionColumns[columnIndex][index];
const resultData = await this.getRegion(selectData.id); const resultData = await this.getRegion(selectData.id);
if (resultData && resultData.length !== 0) { if (resultData && resultData.length !== 0) {
@@ -183,21 +228,16 @@ export default {
// 提交地址 // 提交地址
regionConfirm(e) { regionConfirm(e) {
const { const { columnIndex, value, values, index } = e;
columnIndex,
value,
values,
index,
} = e;
const regionStr = []; const regionStr = [];
const regionId = []; const regionId = [];
value.map(item => { value.map((item) => {
if (item) { if (item) {
regionStr.push(item.label); regionStr.push(item.label);
regionId.push(item.id); regionId.push(item.id);
} }
}) });
console.log('提交地址--1',value) console.log("提交地址--1", value);
this.form.regionStr = regionStr; this.form.regionStr = regionStr;
if (regionId && regionId.length !== 0) { if (regionId && regionId.length !== 0) {
this.form.countryId = regionId[0] ? regionId[0] : null; this.form.countryId = regionId[0] ? regionId[0] : null;
@@ -213,31 +253,31 @@ export default {
async addAddress() { async addAddress() {
const params = { const params = {
...this.form, ...this.form,
} };
if (!params.name) { if (!params.name) {
this.$refs.uToastRef.show({ this.$refs.uToastRef.show({
type: 'error', type: "error",
message: "请输入收货人", message: "请输入收货人",
}); });
return; return;
} }
if (!params.mobile) { if (!params.mobile) {
this.$refs.uToastRef.show({ this.$refs.uToastRef.show({
type: 'error', type: "error",
message: "请输入收货人手机号", message: "请输入收货人手机号",
}); });
return; return;
} }
if (!params.regionStr) { if (!params.regionStr) {
this.$refs.uToastRef.show({ this.$refs.uToastRef.show({
type: 'error', type: "error",
message: "请选择所在地区", message: "请选择所在地区",
}); });
return; return;
} }
if (!params.address) { if (!params.address) {
this.$refs.uToastRef.show({ this.$refs.uToastRef.show({
type: 'error', type: "error",
message: "请输入详细地址", message: "请输入详细地址",
}); });
return; return;
@@ -264,24 +304,25 @@ export default {
const res = await editAddress(params); const res = await editAddress(params);
if (res && res.bizcode === 100) { if (res && res.bizcode === 100) {
this.$refs.uToastRef.show({ this.$refs.uToastRef.show({
type: 'success', type: "success",
message: params.id && params.id !== 0 ? '修改成功' : "添加成功", message: params.id && params.id !== 0 ? "修改成功" : "添加成功",
}); });
const leftPath = this.leftPath; const leftPath = this.leftPath;
console.log("参数--111-", leftPath) console.log("参数--111-", leftPath);
setTimeout(() => { setTimeout(() => {
if (leftPath) {
uni.navigateTo({ uni.navigateTo({
url: leftPath, url: leftPath,
}) });
}, 2000) } else {
} uni.navigateBack();
}
} }
}, 2000);
} }
},
},
};
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>
File diff suppressed because one or more lines are too long