"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_request = require("../../../api/request.js");
const common_assets = require("../../../common/assets.js");
const _sfc_main = {
  __name: "newaddress_Info",
  setup(__props) {
    const userInfo = common_vendor.ref({});
    const addressParam = common_vendor.ref({
      userId: 0,
      name: "",
      phone: "",
      region: "",
      detailAddress: "",
      isDefault: 0
    });
    common_vendor.onLoad((options) => {
      addressParam.value = JSON.parse(options.editInfo);
    });
    common_vendor.onMounted(() => {
      userInfo.value = common_vendor.index.getStorageSync("userInfo");
    });
    const defaultAddress = (event) => {
      event.detail.value[0] ? addressParam.value.isDefault = 1 : addressParam.value.isDefault = 0;
    };
    const newAddress = async () => {
      console.log(addressParam.value);
      addressParam.value.userId = userInfo.value.id;
      const values = Object.values(addressParam.value);
      if (values.some((value) => value === null || value === void 0 || value === "")) {
        await common_vendor.index.showToast({
          icon: "error",
          title: "字段不能为空"
        });
        return;
      }
      const res = await common_vendor.index.request({
        url: api_request.baseUrl + "/address/add",
        method: "POST",
        header: {
          "cookie": wx.getStorageSync("cookie")
        },
        data: { ...addressParam.value }
      });
      console.log("res==>", res.data);
      if (res.data.code === 1) {
        common_vendor.index.navigateBack({
          //返回上一页
        });
      } else {
        common_vendor.index.showToast({
          icon: "error",
          title: "新增地址失败"
        });
        return;
      }
    };
    return (_ctx, _cache) => {
      return {
        a: addressParam.value.name,
        b: common_vendor.o(($event) => addressParam.value.name = $event.detail.value),
        c: addressParam.value.phone,
        d: common_vendor.o(($event) => addressParam.value.phone = $event.detail.value),
        e: addressParam.value.region,
        f: common_vendor.o(($event) => addressParam.value.region = $event.detail.value),
        g: common_vendor.unref(common_assets.dingwei),
        h: addressParam.value.detailAddress,
        i: common_vendor.o(($event) => addressParam.value.detailAddress = $event.detail.value),
        j: common_vendor.o(defaultAddress),
        k: common_vendor.o(newAddress)
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-fb57d854"], ["__file", "D:/jiangchengfeiyi-xiaochengxu/pages/Shopping-cart/newaddress_Info/newaddress_Info.vue"]]);
my.createPage(MiniProgramPage);
