"use strict";
const common_vendor = require("../../../common/vendor.js");
const utils_emitter = require("../../../utils/emitter.js");
const api_request = require("../../../api/request.js");
const _sfc_main = {
  __name: "addressComponent",
  setup(__props) {
    common_vendor.ref([null, null]);
    const addressList = common_vendor.ref([]);
    common_vendor.wx$1.getStorageSync("userInfo");
    common_vendor.onMounted(() => {
      getAddressList();
    });
    common_vendor.onShow(() => {
      getAddressList();
    });
    const getAddressList = async () => {
      const res = await common_vendor.index.request({
        url: api_request.baseUrl + "/address/list",
        method: "POST",
        header: {
          "cookie": common_vendor.wx$1.getStorageSync("cookie")
        }
      });
      console.log("组件的地址信息---->", res.data);
      addressList.value = res.data.data;
    };
    const close = () => {
      utils_emitter.emitter.emit("close");
    };
    const radioChange = (event) => {
      const index = event.detail.value;
      const temp = addressList.value[index];
      utils_emitter.emitter.emit("addressInfo", temp);
      utils_emitter.emitter.emit("close");
    };
    const toNewAddress = () => {
      common_vendor.index.navigateTo({
        url: "/pages/Shopping-cart/newaddress_Info/newaddress_Info"
      });
    };
    const editAddress = (value) => {
      console.log("地址信息", value);
      common_vendor.index.navigateTo({
        url: "/pages/Shopping-cart/newaddress_Info/newaddress_Info?editInfo=" + JSON.stringify(value)
      });
    };
    const deleteAddress = async (id) => {
      const res = await common_vendor.index.request({
        url: api_request.baseUrl + "/address/delete",
        method: "POST",
        header: {
          "cookie": common_vendor.wx$1.getStorageSync("cookie")
        },
        data: { id }
      });
      if (res.data.code === 1) {
        getAddressList();
      }
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.o(close),
        b: common_vendor.f(addressList.value, (item, index, i0) => {
          return {
            a: index,
            b: index === _ctx.current,
            c: common_vendor.t(item.name),
            d: common_vendor.t(item.phone),
            e: common_vendor.o(($event) => editAddress(item), index),
            f: common_vendor.o(($event) => deleteAddress(item.id), index),
            g: common_vendor.t(item.detailAddress),
            h: index
          };
        }),
        c: common_vendor.o(radioChange),
        d: common_vendor.o(toNewAddress)
      };
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c20b9e4d"], ["__file", "D:/微信小程序/课设整合/匠承非遗小程序端/jiangchengfeiyi-xiaochengxu/pages/order/component/addressComponent.vue"]]);
wx.createComponent(Component);
