"use strict";
const common_vendor = require("../../common/vendor.js");
if (!Array) {
  const _component_up_button = common_vendor.resolveComponent("up-button");
  const _component_up_popup = common_vendor.resolveComponent("up-popup");
  (_component_up_button + _component_up_popup)();
}
const _sfc_main = {
  __name: "index",
  props: {
    attr: {
      type: Object,
      default: () => ({})
    },
    showPopup: {
      type: Boolean,
      default: false
    },
    limitNum: {
      type: Number,
      default: 0
    },
    isShow: {
      type: Number,
      default: 0
    },
    iSbnt: {
      type: Number,
      default: 0
    },
    iSplus: {
      type: Number,
      default: 0
    },
    iScart: {
      type: Number,
      default: 0
    }
  },
  emits: [
    "goCat",
    "iptCartNum",
    "myevent",
    "ChangeCartNum",
    "attrVal",
    "ChangeAttr",
    "submit",
    "closePopup"
  ],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const calcNumPrice = common_vendor.computed(() => {
      var _a;
      if (!((_a = props.attr) == null ? void 0 : _a.productSelect)) {
        return "0.00";
      }
      const { storePrice, cart_num } = props.attr.productSelect;
      if (!storePrice || !cart_num) {
        return "0.00";
      }
      const price = Number(storePrice);
      const quantity = Number(cart_num);
      if (isNaN(price) || isNaN(quantity)) {
        return "0.00";
      }
      if (price < 0 || quantity < 0) {
        return "0.00";
      }
      const total = price * quantity;
      return total.toFixed(2);
    });
    function bindCode() {
      emit("iptCartNum", props.attr.productSelect.cart_num);
    }
    function close() {
      emit("closePopup");
    }
    function submit() {
      emit("submit");
    }
    function CartNumDes() {
      emit("ChangeCartNum", false);
    }
    function CartNumAdd() {
      emit("ChangeCartNum", true);
    }
    function tapAttr(indexw, indexn) {
      emit("attrVal", { indexw, indexn });
      if (props.attr.productAttr && props.attr.productAttr[indexw]) {
        props.attr.productAttr[indexw].index = props.attr.productAttr[indexw].attrValues[indexn];
      }
      const value = getCheckedValue().join(",");
      emit("ChangeAttr", value);
    }
    function getCheckedValue() {
      const productAttr = props.attr.productAttr || [];
      const value = [];
      for (let i = 0; i < productAttr.length; i++) {
        for (let j = 0; j < productAttr[i].attrValues.length; j++) {
          if (productAttr[i].index === productAttr[i].attrValues[j]) {
            value.push(productAttr[i].attrValues[j]);
          }
        }
      }
      return value;
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: __props.attr.productSelect.image,
        b: common_vendor.t(__props.attr.productSelect.storeName),
        c: common_vendor.t(calcNumPrice.value),
        d: __props.isShow
      }, __props.isShow ? {
        e: common_vendor.t(__props.attr.productSelect.stock)
      } : {}, {
        f: __props.limitNum
      }, __props.limitNum ? {
        g: common_vendor.t(__props.attr.productSelect.quota)
      } : {}, {
        h: common_vendor.o(close),
        i: common_vendor.f(__props.attr.productAttr, (item, indexw, i0) => {
          return {
            a: common_vendor.t(item.attrName),
            b: common_vendor.f(item.attrValues, (itemn, indexn, i1) => {
              return {
                a: common_vendor.t(itemn),
                b: common_vendor.n(item.index === itemn ? "on" : ""),
                c: common_vendor.o(($event) => tapAttr(indexw, indexn), indexn),
                d: indexn
              };
            }),
            c: indexw
          };
        }),
        j: common_vendor.n(__props.attr.productSelect.cart_num <= 1 ? "on" : ""),
        k: common_vendor.o(CartNumDes),
        l: common_vendor.o([($event) => __props.attr.productSelect.cart_num = $event.detail.value, ($event) => bindCode(__props.attr.productSelect.cart_num)]),
        m: __props.attr.productSelect.cart_num,
        n: __props.iSplus
      }, __props.iSplus ? {
        o: common_vendor.n(__props.attr.productSelect.cart_num >= __props.attr.productSelect.stock ? "on" : ""),
        p: common_vendor.o(CartNumAdd)
      } : {
        q: common_vendor.n(__props.attr.productSelect.cart_num >= __props.attr.productSelect.quota || __props.attr.productSelect.cart_num >= __props.attr.productSelect.stock || __props.attr.productSelect.cart_num >= __props.attr.productSelect.num ? "on" : ""),
        r: common_vendor.o(CartNumAdd)
      }, {
        s: __props.attr.productSelect.stock > 0
      }, __props.attr.productSelect.stock > 0 ? {
        t: common_vendor.o(submit),
        v: common_vendor.p({
          type: "primary",
          text: "确定"
        })
      } : {
        w: common_vendor.o(submit),
        x: common_vendor.p({
          type: "primary",
          text: "已售罄"
        })
      }, {
        y: common_vendor.n((__props.iSbnt ? "join" : "") + " " + (__props.iScart ? "joinCart" : "")),
        z: common_vendor.o(close),
        A: common_vendor.p({
          show: __props.showPopup,
          closeOnClickOverlay: true
        })
      });
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2914200c"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/components/productWindow/index.js.map
