<template>
<div>
    <Myheader></Myheader>
  <div class="usermain">
    <div class="rc-main" v-for="(item, index) in list" :key="index">
        <div class="rc-center">
      <div class="rc-header">
        <em>
          {{ item.recipient }}
        </em>
        <span>
          {{ item.recipientPhone }}
        </span>
      </div>
      <div class="rc-address">
        <span>
          {{ item.detailAddress }}
        </span>
      </div>
      <div class="rc-footer">
        <div class="rc-foot">
          <span>设置为默认收货地址</span>

          <!-- <van-switch v-model="checked" /> -->
        </div>
        <div class="rc-right">
          <span @click="onEdit(item, index)">编辑</span>
          <span @click="userdelete(item, index)">删除</span>
        </div>
      </div>
    </div>

 
    </div>
  </div>
     <div class="rc-button">
      <div class="rc-footbutton" @click="onAdd()">
        <span>新增收货地址</span>
      </div>
    </div>
  </div>
</template>

<script>
import { areaList } from "@vant/area-data";
import { selectaddress } from "../../ajax/getData";
import { editdelete } from "../../ajax/getData";
import Myheader from "~/components/header.vue";
import { Toast } from "vant";
export default {
  data() {
    return {
      chosenAddressId: "1",
      checked: true,
      userid: null,
      usermessage:null,
      list: [
        {
          id: 1,
          name: "张三",
          tel: "13000000000",
          address: "浙江省杭州市西湖区文三路 138 号",
          isDefault: true,
        },
        {
          id: 2,
          name: "李四",
          tel: "1310000000",
          address: "浙江省杭州市拱墅区莫干山路 50 号",
        },
           {
          id: 3,
          name: "李四",
          tel: "1310000000",
          address: "浙江省杭州市拱墅区莫干山路 50 号",
        },
      ],
      areaList,
    };
  },
  methods: {
    onAdd() {
      Toast("新增地址");

      this.$router.push({ path: "/useraddress/addaddress" });
    },
    onEdit(item, index) {
      let userid = item.id;
      console.log(item);
      this.$router.push({
        path: "/useraddress/editaddress",
        query: {
          id: item,
        },
      });
    },
    //删除地址
    async userdelete(item) {
      console.log(item.memberId);
      let data = await editdelete(this.userid, item.id);
     this.editaddress(this.usermessage);
      console.log(data);
    },

    //查询人的所有地址
    async editaddress(user) {
      let data = await selectaddress(user.data.id);
        this.list=data.data;
        console.log(this.list);
      console.log(data);
    },
  },
  components: {
    Myheader,
  },

  mounted() {
    //地址的查询
    this.usermessage = JSON.parse(localStorage.getItem("userInfo"));
       this.editaddress(this.usermessage);
    this.userid = this.usermessage.data.id;
  },
};
</script>

<style lang="less" scoped >
.rc-main {
  width: 93%;
  margin: 0 auto;
  margin-top: 8px;
}
//手机端
@media screen and(min-width: 320px) and(max-width:768px) {
  .rc-button {
    height: 80px;
    background: #ffffff;
    box-shadow: 0px -3px 6px rgba(0, 0, 0, 0.1);
    opacity: 1;
    display: flex;
    align-items: center;
    justify-content: center;

    .rc-footbutton {
      width: 164px;
      height: 48px;
      border: 2px solid #e2001a;
      opacity: 1;
      border-radius: 30px;
      display: flex;
      align-items: center;
      background: #e2001a;
      span {
        display: block;
        text-align: center;
        color: white;
        font-size: 16px;
        width: 100%;
      }
    }
  }
  .rc-header {
    display: flex;
    align-items: center;
    color: #333333;
    em {
      font-style: normal;
      font-size: 14px;
    }
    span {
      display: block;
      margin-left: 8px;
    }
  }
  .rc-address {
    margin-top: 8px;
    text-overflow: -o-ellipsis-lastline;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 14px;
    color: #333333;
  }
  .rc-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    margin-top: 8px;
    .rc-right {
      span {
        border-bottom: 1px solid #666666;
      }
      span:first-child {
        margin-right: 16px;
      }
    }
  }
}
//pc端
@media screen and (min-width: 768px) and (max-width: 1920px) {
    .usermain{
     
        width: 90%;
        margin: 0 auto;
    }
    .rc-main{
       width: 45%;
height: 164px;
margin-top: 60px;
background: #FFFFFF;
border: 1px solid #D7D7D7;
opacity: 1;
border-radius: 3px;
margin-left: 40px;
float: left;
.rc-center{
    margin-top: 24px;
    margin-left: 24px;
}
    }
  .rc-button {
    height: 80px;
    background: #ffffff;
    box-shadow: 0px -3px 6px rgba(0, 0, 0, 0.1);
    opacity: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;

    .rc-footbutton {
      width: 164px;
      height: 48px;
      border: 2px solid #e2001a;
      opacity: 1;
      border-radius: 30px;
      display: flex;
      align-items: center;
      background: #e2001a;
      span {
        display: block;
        text-align: center;
        color: white;
        font-size: 16px;
        width: 100%;
      }
    }
  }
  .rc-header {
    display: flex;
    align-items: center;
    color: #333333;
    em {
      font-style: normal;
      font-size: 14px;
    }
    span {
      display: block;
      margin-left: 8px;
    }
  }
  .rc-address {
    margin-top: 8px;
    text-overflow: -o-ellipsis-lastline;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 14px;
    color: #333333;
  }
  .rc-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    margin-top: 8px;
    .rc-right {
      span {
        border-bottom: 1px solid #666666;
      }
      span:first-child {
        margin-right: 16px;
      }
    }
  }
}
</style>
