feat:完成删除和编辑地址

merge-requests/18/head
张征 3 years ago
parent 19b13516ce
commit fc829b4d49

@ -57,7 +57,14 @@
<article class="address__msg">
<div class="address__msg-line flex flex-middle">
<span class="address__msg-line--type">所在区域</span>
<no-ssr><v-distpicker @selected="onSelected"></v-distpicker></no-ssr>
<no-ssr
><v-distpicker
:province="selectData.province.value"
:city="selectData.city.value"
:area="selectData.area.value"
@selected="onSelected"
></v-distpicker
></no-ssr>
</div>
<div class="address__msg-line flex flex-middle">
<span class="address__msg-line--type">详细地址</span>
@ -160,9 +167,20 @@ export default {
addressUser: "",
addressPhone: "",
defaultAddress: true,
selectData: {},
selectData: {
area: {
value: "",
},
city: {
value: "",
},
province: {
value: "",
},
},
addressList: [{}],
curAddressListItem: 0,
editIndex: 0,
};
},
created() {
@ -187,6 +205,16 @@ export default {
},
setAddressData(i) {
let vm = this;
vm.editIndex = i;
let editItem = vm.addressList[i];
console.log(editItem);
vm.$set(vm.selectData.area, "value", editItem.area);
vm.$set(vm.selectData.city, "value", editItem.city);
vm.$set(vm.selectData.province, "value", editItem.province);
vm.$set(vm, "detailAddress", editItem.detailAddress);
vm.$set(vm, "defaultAddress", editItem.isDefault);
vm.$set(vm, "addressUser", editItem.name);
vm.$set(vm, "addressPhone", editItem.phone);
},
onSwtich() {
this.dialogVisible = true;
@ -230,7 +258,8 @@ export default {
};
let res;
if (vm.isEdit) {
res = await ApiPutAddress(params);
let editParams = Object.assign(vm.addressList[vm.editIndex], params);
res = await ApiPutAddress(editParams);
} else {
res = await ApiPostAddress(params);
}

@ -10,7 +10,7 @@
<div>
<div class="title">收货地址</div>
<BsAddress
ref="bsaddress"
ref="bsAddress"
@getList="getList"
:isAccount="true"
:isEdit="isEdit"
@ -44,6 +44,8 @@
</div>
</template>
<script>
import { ApiPutAddress, ApiDeleteAddress } from "@/plugins/api/base";
import BsAddress from "@/components/BsAddress.vue";
import UiButton from "@/components/UiButton.vue";
export default {
@ -59,8 +61,34 @@ export default {
this.addressList = list || [];
},
editItem(i) {
console.log(i)
this.$refs.bsaddress.setAddressData(i)
console.log(i);
this.isEdit = true;
this.$refs.bsAddress.setAddressData(i);
},
async setItem(item) {
let params = JSON.parse(JSON.stringify(item));
params.isDefault = true;
let res = await ApiPutAddress(params);
this.$refs.bsAddress.getAddressData();
if (!res.error) {
this.$message.success("设置成功~");
}
},
deleteItem(item) {
let vm = this;
vm.$alert("确认删除此收货地址吗?", "提示", {
confirmButtonText: "确定",
callback: async () => {
let res = await ApiDeleteAddress({
idList: [item.id],
});
if (!res.error) {
vm.$message.success("删除成功~");
vm.$refs.bsAddress.getAddressData();
}
console.log(res);
},
});
},
},
};

Loading…
Cancel
Save