chenyc
2023-05-28 aae6cb63fac8f2956615481382c101cfd2e7d45c
src/views/jifenShangCheng/components/dizhi.vue
@@ -38,81 +38,168 @@
</template>
<script setup lang="ts">
import { Toast } from 'vant';
import { ref } from 'vue';
import { areaList } from '@vant/area-data';
import type { AddressEditInstance } from 'vant';
name:"dizhibianji"
    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 addressEditRef = ref<AddressEditInstance>()
    const chosenAddressId = ref(1)
const addressInfo=ref({
        id:0,
        name:'',
        addressDetail:'',
        tel:'',
        city:'',
        county:'',
        areaCode:'',
        address:'',
        isDefault:false
    })
    const list = ref([
        {
            id: 0,
            code:'',
    name:'',
    tel:'',
    province:'',
    city:"",
            city:'',
    county:'',
    addressDetail:'',
            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){
                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,
})
const list =[
{
        id: '1',
        name: '张三',
        tel: '13000000000',
        address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        isDefault: true,
      },
      {
        id: '2',
        name: '李四',
        tel: '1310000000',
        address: '浙江省杭州市拱墅区莫干山路 50 号',
      },
]
const openShow=()=>{
                    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');
        addressEditRef.value?.setAddressDetail('3434343')
    editDizhi.value=false
}
const onAdd = () =>{
    editDizhi.value=true
        console.log('用户信息')
        console.log(userInfo.patient)
    addressInfo.value={
        name:'',
        tel:'17717874345',
        province:'',
        city:"",
            id:0,
            name:userInfo.patient.patientInfo.patientName,
            addressDetail:userInfo.patient.patientInfo.patientAddress,
            tel:userInfo.patient.patientInfo.patientTelNo,
            city:'',
        county:'',
        addressDetail:'',
            areaCode:'',
            address:'',
        isDefault:false
    }
}
const onEdit = (item:any, index:number) =>{
    console.log(item)
        console.log(item,index)
    addressInfo.value={
            id:item.id,
        name:item.name,
        tel:item.tel,
        province:'',
        city:"",
        county:'',
        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) => {
    Toast('save');
    console.log(form)
        const pasm={
            addressArea: [form.city,form.county].toString(),
            id: addressInfo.value.id,
            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 = () => Toast('delete');
    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
} )