<template>
  <view>
    <addrAdd v-model="from.uname" desc="收货人姓名"></addrAdd>
    <addrAdd v-model="from.phone" desc="手机号码"></addrAdd>
    <addrAdd v-model="from.address" desc="收货地址"></addrAdd>
    <view @click="tijiao" class="btn">
      <chooseaddrBtn1></chooseaddrBtn1>
    </view>
  </view>
</template>
<script>
import addrAdd from "../../components/addr/addr-add";
import chooseaddrBtn1 from "../../components/chooseaddr/chooseaddr-btn1";
import { requestP } from "../../static/js/request";
export default {
  components: {
    addrAdd,
    chooseaddrBtn1
  },
  data() {
    return {
      from: {}
    };
  },
  methods: {
    tijiao() {
      if (this.from.id) {
        requestP({
          url: "user/update_user_address",
          data: this.from
        }).then(res => {
          console.log(res);
          uni.showToast({
            title: "修改成功",
            duration: 2000,
            icon: "success"
          });
          uni.navigateTo({
            url:"/pages/chooseaddr/chooseaddr"
          })
        });
      } else {
        requestP({
          url: "user/add_user_address",
          data: this.from
        }).then(res => {
          console.log(res);
          uni.showToast({
            title: "添加成功",
            duration: 2000,
            icon: "success"
          });
            uni.navigateTo({
            url:"/pages/chooseaddr/chooseaddr"
          })
        });
        
      }
    }
  },
  onLoad(a) {
    if (a.id) {
      this.from = uni.getStorageSync("address");
      this.from.address_id = this.from.id;
    }
  }
};
</script>
<style lang="scss">
.btn {
  position: fixed;
  bottom: 14upx;
  left: 31upx;
}
</style>