feat:个人中心收货地址

merge-requests/18/head
张征 3 years ago
parent dfdd61c054
commit 867e6dd653

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<div class="address flex flex-middle" v-if="!isEdit"> <div class="address flex flex-middle" v-if="!isOperation && !isAccount">
<article class="address__msg"> <article class="address__msg">
<div class="address__msg-line flex flex-middle"> <div class="address__msg-line flex flex-middle">
<img src="@/assets/img/goods/point.png" alt="收货地址" /> <img src="@/assets/img/goods/point.png" alt="收货地址" />
@ -39,13 +39,21 @@
/> />
切换地址 切换地址
</UiButton> </UiButton>
<UiButton type="grey" @click="isEdit = true" class="flex flex-middle"> <UiButton
type="grey"
@click="isOperation = true"
class="flex flex-middle"
>
<img class="icon" src="@/assets/img/goods/add.png" alt="新建地址" /> <img class="icon" src="@/assets/img/goods/add.png" alt="新建地址" />
新建地址 新建地址
</UiButton> </UiButton>
</div> </div>
</div> </div>
<div class="address flex flex-middle" v-else> <div
class="address"
:class="isAccount ? 'account' : 'flex flex-middle'"
v-else
>
<article class="address__msg"> <article class="address__msg">
<div class="address__msg-line flex flex-middle"> <div class="address__msg-line flex flex-middle">
<span class="address__msg-line--type">所在区域</span> <span class="address__msg-line--type">所在区域</span>
@ -71,14 +79,17 @@
></el-input> ></el-input>
</div> </div>
</article> </article>
<div class="hr"></div> <div class="hr" v-if="!isAccount"></div>
<div class="address__operation flex flex-column flex-middle"> <div
class="address__operation flex flex-middle"
:class="!isAccount ? 'flex-column' : ''"
>
<el-checkbox v-model="defaultAddress"></el-checkbox> <el-checkbox v-model="defaultAddress"></el-checkbox>
<div> <div>
<UiButton <UiButton
v-if="addressList && addressList.length" v-if="addressList && addressList.length && !isAccount"
type="grey" type="grey"
@click="isEdit = false" @click="isOperation = false"
>取消</UiButton >取消</UiButton
> >
<UiButton type="yellow_panel" @click="onAddAddress" <UiButton type="yellow_panel" @click="onAddAddress"
@ -115,8 +126,12 @@
</template> </template>
<script> <script>
import UiButton from "@/components/UiButton.vue"; import UiButton from "@/components/UiButton.vue";
import { IsPhone } from "@/plugins/utils/index.js";
import { ApiGetAddress, ApiPostAddress } from "@/plugins/api/base"; import {
ApiGetAddress,
ApiPostAddress,
ApiPutAddress,
} from "@/plugins/api/base";
export default { export default {
components: { UiButton }, components: { UiButton },
props: { props: {
@ -124,6 +139,14 @@ export default {
type: Object, type: Object,
default: () => {}, default: () => {},
}, },
isAccount: {
type: Boolean,
default: false,
},
isEdit: {
type: Boolean,
default: false,
},
}, },
model: { model: {
prop: "addressData", prop: "addressData",
@ -131,7 +154,7 @@ export default {
}, },
data() { data() {
return { return {
isEdit: false, isOperation: false,
dialogVisible: false, dialogVisible: false,
detailAddress: "", detailAddress: "",
addressUser: "", addressUser: "",
@ -150,17 +173,21 @@ export default {
let vm = this; let vm = this;
let res = await ApiGetAddress(); let res = await ApiGetAddress();
if (res.result && res.result.length) { if (res.result && res.result.length) {
vm.isEdit = false; vm.isOperation = false;
vm.addressList = res.result; vm.addressList = res.result;
let curIndex = vm.addressList.findIndex((item) => item.id == 3); let curIndex = vm.addressList.findIndex((item) => item.isDefault);
vm.curAddressListItem = vm.curAddressListItem =
curIndex > -1 ? vm.addressList[curIndex] : vm.addressList[0]; curIndex > -1 ? vm.addressList[curIndex] : vm.addressList[0];
vm.$emit("getList", vm.addressList);
vm.$emit("emitAddress", vm.curAddressListItem); vm.$emit("emitAddress", vm.curAddressListItem);
} else { } else {
vm.isEdit = true; vm.isOperation = true;
} }
console.log("获取收货地址", res); console.log("获取收货地址", res);
}, },
setAddressData(i) {
let vm = this;
},
onSwtich() { onSwtich() {
this.dialogVisible = true; this.dialogVisible = true;
}, },
@ -185,7 +212,7 @@ export default {
vm.$message.error("请输入收货人~"); vm.$message.error("请输入收货人~");
return; return;
} }
if (!vm.addressPhone) { if (!IsPhone(vm.addressPhone)) {
vm.$message.error("请输入收货人手机号码~"); vm.$message.error("请输入收货人手机号码~");
return; return;
} }
@ -201,7 +228,12 @@ export default {
province: vm.selectData.province.value, province: vm.selectData.province.value,
provinceCode: vm.selectData.province.code, provinceCode: vm.selectData.province.code,
}; };
let res = await ApiPostAddress(params); let res;
if (vm.isEdit) {
res = await ApiPutAddress(params);
} else {
res = await ApiPostAddress(params);
}
if (!res.error) { if (!res.error) {
vm.$message.success("添加成功!"); vm.$message.success("添加成功!");
vm.getAddressData(); vm.getAddressData();
@ -355,4 +387,8 @@ export default {
padding: 0; padding: 0;
} }
} }
.account {
width: 1000px;
}
</style> </style>

@ -7,17 +7,82 @@
--> -->
<template> <template>
<div>我是地址管理页面</div> <div>
<div class="title">收货地址</div>
<BsAddress
ref="bsaddress"
@getList="getList"
:isAccount="true"
:isEdit="isEdit"
></BsAddress>
<el-table :data="addressList" style="width: 100%">
<el-table-column prop="name" label="收货人" width="130px">
</el-table-column>
<el-table-column prop="phone" label="手机号码" width="140px">
</el-table-column>
<el-table-column label="收货地址" width="430px">
<template slot-scope="scope">
{{
scope.row.area +
scope.row.city +
scope.row.province +
scope.row.detailAddress
}}
</template>
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<div class="btns">
<span @click="editItem(scope.$index)"></span>
<span @click="deleteItem(scope.row)"></span>
<span v-if="scope.row.isDefault" class="default"></span>
<span v-else @click="setItem(scope.row)"></span>
</div>
</template>
</el-table-column>
</el-table>
</div>
</template> </template>
<script> <script>
import BsAddress from "@/components/BsAddress.vue";
import UiButton from "@/components/UiButton.vue";
export default { export default {
data(){ components: { BsAddress, UiButton },
data() {
return { return {
isEdit: false,
addressList: [],
};
},
methods: {
getList(list) {
this.addressList = list || [];
},
editItem(i) {
console.log(i)
this.$refs.bsaddress.setAddressData(i)
},
},
};
</script>
<style lang="scss" scoped>
.btns {
span {
cursor: pointer;
margin-right: 40px;
&:hover {
color: #ff875b;
}
} }
.default {
display: inline-block;
width: 84px;
height: 30px;
border-radius: 4px;
border: 1px solid #ff875b;
color: #ff875b;
text-align: center;
line-height: 30px;
} }
} }
</script>
<style lang="scss" scoped>
</style> </style>

@ -119,7 +119,6 @@
</div> </div>
</template> </template>
<script> <script>
import BsAddress from "@/components/BsAddress.vue";
import UiMoney from "@/components/UiMoney.vue"; import UiMoney from "@/components/UiMoney.vue";
import UiButton from "@/components/UiButton.vue"; import UiButton from "@/components/UiButton.vue";
import UiGoodsItem from "@/components/UiGoodsItem.vue"; import UiGoodsItem from "@/components/UiGoodsItem.vue";
@ -129,7 +128,7 @@ import {
ApiGetRecommendedGoodsList, ApiGetRecommendedGoodsList,
} from "@/plugins/api/goods"; } from "@/plugins/api/goods";
export default { export default {
componetns: { UiMoney, UiButton, UiGoodsItem, BsAddress }, componetns: { UiMoney, UiButton, UiGoodsItem },
data() { data() {
return { return {
curBuyNum: 1, curBuyNum: 1,

Loading…
Cancel
Save