feat:完成删除和编辑地址

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

@ -57,7 +57,14 @@
<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>
<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>
<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>
@ -160,9 +167,20 @@ export default {
addressUser: "", addressUser: "",
addressPhone: "", addressPhone: "",
defaultAddress: true, defaultAddress: true,
selectData: {}, selectData: {
area: {
value: "",
},
city: {
value: "",
},
province: {
value: "",
},
},
addressList: [{}], addressList: [{}],
curAddressListItem: 0, curAddressListItem: 0,
editIndex: 0,
}; };
}, },
created() { created() {
@ -187,6 +205,16 @@ export default {
}, },
setAddressData(i) { setAddressData(i) {
let vm = this; 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() { onSwtich() {
this.dialogVisible = true; this.dialogVisible = true;
@ -230,7 +258,8 @@ export default {
}; };
let res; let res;
if (vm.isEdit) { if (vm.isEdit) {
res = await ApiPutAddress(params); let editParams = Object.assign(vm.addressList[vm.editIndex], params);
res = await ApiPutAddress(editParams);
} else { } else {
res = await ApiPostAddress(params); res = await ApiPostAddress(params);
} }

@ -10,7 +10,7 @@
<div> <div>
<div class="title">收货地址</div> <div class="title">收货地址</div>
<BsAddress <BsAddress
ref="bsaddress" ref="bsAddress"
@getList="getList" @getList="getList"
:isAccount="true" :isAccount="true"
:isEdit="isEdit" :isEdit="isEdit"
@ -44,6 +44,8 @@
</div> </div>
</template> </template>
<script> <script>
import { ApiPutAddress, ApiDeleteAddress } from "@/plugins/api/base";
import BsAddress from "@/components/BsAddress.vue"; import BsAddress from "@/components/BsAddress.vue";
import UiButton from "@/components/UiButton.vue"; import UiButton from "@/components/UiButton.vue";
export default { export default {
@ -59,8 +61,34 @@ export default {
this.addressList = list || []; this.addressList = list || [];
}, },
editItem(i) { editItem(i) {
console.log(i) console.log(i);
this.$refs.bsaddress.setAddressData(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