<template>
  <van-address-edit
  :area-list="areaList"
  show-postal
  show-delete
  show-set-default
  show-search-result
  :search-result="searchResult"
  :area-columns-placeholder="['请选择', '请选择', '请选择']"
  @save="onSave"
  @delete="onDelete"
  @change-detail="onChangeDetail"
/>
</template>

<script>
import { editaddress } from "../../ajax/getData";
import { Toast } from 'vant';
import { areaList } from '@vant/area-data';
export default {
  data(){
      return{
         areaList,
      searchResult: [],
      userid:null,
      addressdetail:'',
      }
  },
  methods:{
  async onSave(content) {
    //   Toast('save');
    console.log(content);
    let recipient=content.name;
    let tel=content.tel;
    let provinceId=Number(content.areaCode.substring(0,2)+'0000')//省份id
    let cityId=Number(content.areaCode.substring(0,4)+'00') //城市id
    let districtId=Number(content.areaCode);//区域编码
    console.log(provinceId,cityId,districtId);
     console.log(content.areaCode.substring(0,2)+'0000');//城市编码
       console.log(content.areaCode.substring(0,4)+'00'); //市区id
       console.log(content.areaCode) //区域编码
                                      //id     详细地址   /收货人姓名 电话号码 省份id/城市id/区域编码
       let data = await editaddress(this.userid,this.addressdetail,recipient,tel,provinceId,cityId,districtId);

       if(data){
             this.$message({
                                type: 'warning',
                                message: '地址保存成功'
                            });
       }
       console.log(data);
    },
     onDelete() {
       
      Toast('delete');
    },
    onChangeDetail(val){
        this.addressdetail=val;
  
    }



  },
  mounted(){
      let user= JSON.parse(localStorage.getItem("userInfo"));
      // this.userid=user.data.id;
      this.userid=3242

  },
  components:{
  
  },
  

}
</script>

<style>

</style>