<template>
|
<div>
|
<van-popup v-model:show="showDizhi" position="bottom" :style="{ height: '100%' }">
|
<van-nav-bar
|
title="收货地址管理"
|
left-text="返回"
|
left-arrow
|
@click-left="onClickLeft"
|
/>
|
<van-address-list
|
v-model="chosenAddressId"
|
:list="list"
|
default-tag-text="默认"
|
@add="onAdd"
|
@edit="onEdit"
|
/>
|
</van-popup>
|
<van-popup v-model:show="editDizhi" position="bottom" :style="{ height: '100%' }">
|
<van-nav-bar
|
title="编辑地址"
|
left-text="返回"
|
left-arrow
|
@click-left="onClickLeft2"
|
/>
|
<van-address-edit
|
ref="addressEditRef"
|
:area-list="areaList"
|
show-delete
|
show-set-default
|
show-search-result
|
:address-info="addressInfo"
|
:area-columns-placeholder="['请选择', '请选择', '请选择']"
|
@save="onSave"
|
@delete="onDelete"
|
/>
|
</van-popup>
|
</div>
|
</template>
|
<script setup lang="ts">
|
|
import { Toast } from 'vant'
|
import { ref } from 'vue'
|
import { areaList } from '@vant/area-data'
|
import type { AddressEditInstance } from 'vant'
|
import { ajaxPost } from '@/utils/axios'
|
import { userInfoStore } from '@/stores/userInfo'
|
const userInfo = userInfoStore()
|
const emit = defineEmits(['fanhuiFun'])
|
const showDizhi=ref(false)
|
const editDizhi=ref(false)
|
const addressEditRef = ref<AddressEditInstance>()
|
const chosenAddressId = ref(1)
|
const addressInfo=ref({
|
code:'',
|
id:0,
|
name:'',
|
addressDetail:'',
|
tel:'',
|
city:'',
|
county:'',
|
areaCode:'',
|
address:'',
|
isDefault:false
|
})
|
const list = ref([
|
{
|
id: 0,
|
code:'',
|
name:'',
|
tel:'',
|
province:'',
|
city:'',
|
county:'',
|
areaCode:'',
|
address:'',
|
isDefault:false
|
},
|
])
|
const getDefDizhi=(isload:boolean)=>{
|
const pasm=`page=0&size=0&wherecondition=patient_code="${userInfo.patient.patientInfo.code}"`
|
ajaxPost('/patient/address/list', pasm).then((re: any) => {
|
console.log('默认地址')
|
console.log(re)
|
if (re.list.length===0){
|
list.value=[]
|
onAdd()
|
} else {
|
list.value=[]
|
re.list.forEach((e:any)=>{
|
list.value.push({
|
id: e.id,
|
code:e.code,
|
name:e.receivePersonName,
|
tel:e.receivePersonMobile,
|
province:'',
|
city:e.addressArea.split(',')[0],
|
county:e.addressArea.split(',')[1],
|
areaCode:e.remark,
|
address:e.patientAddress,
|
isDefault:e.patientIsDefault===1?true:false,
|
})
|
if (isload){
|
if (e.patientIsDefault===1){
|
chosenAddressId.value=(e.id)
|
}
|
}
|
})
|
console.log(list.value)
|
}
|
|
})
|
}
|
// 打开地址列表
|
const openShow=(id:number)=>{
|
showDizhi.value=true
|
chosenAddressId.value=id
|
getDefDizhi(false)
|
}
|
const onClickLeft=()=>{
|
showDizhi.value=false
|
console.log('返回父级组件',chosenAddressId.value)
|
const row=list.value.find((e:any)=> e.id===chosenAddressId.value)
|
emit('fanhuiFun',row)
|
}
|
const onClickLeft2=()=>{
|
addressEditRef.value?.setAddressDetail('3434343')
|
editDizhi.value=false
|
}
|
const onAdd = () =>{
|
editDizhi.value=true
|
console.log('用户信息')
|
console.log(userInfo.patient)
|
addressInfo.value={
|
code:'',
|
id:0,
|
name:userInfo.patient.patientInfo.patientName,
|
addressDetail:userInfo.patient.patientInfo.patientAddress,
|
tel:userInfo.patient.patientInfo.patientTelNo,
|
city:'',
|
county:'',
|
areaCode:'',
|
address:'',
|
isDefault:false
|
}
|
}
|
const onEdit = (item:any, index:number) =>{
|
console.log(item,index)
|
addressInfo.value={
|
code:item.code,
|
id:item.id,
|
name:item.name,
|
addressDetail:item.address,
|
tel:item.tel,
|
city:item.city,
|
county:item.county,
|
areaCode:item.areaCode,
|
address:'',
|
isDefault:item.isDefault
|
}
|
editDizhi.value=true
|
}
|
const onSave = (form:any) => {
|
const pasm={
|
addressArea: [form.city,form.county].toString(),
|
id: addressInfo.value.id,
|
code:addressInfo.value.code,
|
patientAddress: form.addressDetail,
|
patientCode: userInfo.patient.patientInfo.code,
|
patientIsDefault: form.isDefault===true?1:0,
|
receivePersonMobile: form.tel,
|
receivePersonName: form.name,
|
// 存地址code
|
remark: form.areaCode,
|
}
|
if (pasm.id===0){
|
ajaxPost('/patient/address/add', pasm).then((re: any) => {
|
console.log('默认地址')
|
console.log(re)
|
Toast.success('保存成功')
|
getDefDizhi(false)
|
chosenAddressId.value=re.id
|
editDizhi.value=false
|
})
|
} else {
|
ajaxPost('/patient/address/update', pasm).then((re: any) => {
|
console.log('默认地址')
|
chosenAddressId.value=re.id
|
console.log(re)
|
Toast.success('保存成功')
|
getDefDizhi(false)
|
editDizhi.value=false
|
})
|
}
|
|
|
|
|
}
|
const onDelete = () => {
|
ajaxPost('patient/address/delete','id='+addressInfo.value.id).then(re=>{
|
editDizhi.value=false
|
console.log(re)
|
Toast.success('删除成功!')
|
}).finally(()=>{
|
getDefDizhi(true)
|
})
|
}
|
defineExpose({
|
openShow
|
} )
|
</script>
|