popPay.js 5.8 KB
"use strict";
var common_vendor = require("../common/vendor.js");
var api_index = require("../api/index.js");
require("../utils/request.js");
if (!Array) {
  const _easycom_u_number_box2 = common_vendor.resolveComponent("u-number-box");
  const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  (_easycom_u_number_box2 + _easycom_u_popup2)();
}
const _easycom_u_number_box = () => "../uni_modules/uview-plus/components/u-number-box/u-number-box.js";
const _easycom_u_popup = () => "../uni_modules/uview-plus/components/u-popup/u-popup.js";
if (!Math) {
  (_easycom_u_number_box + _easycom_u_popup)();
}
const _sfc_main = {
  props: {
    btnType: {
      type: Number,
      default: 0
    },
    shopType: Number,
    payPopShow: {
      type: Boolean,
      default: false
    },
    shopDetail: {
      type: Object,
      default: {}
    },
    moreSpec: {
      type: Object,
      default: {}
    }
  },
  emits: ["close"],
  setup(__props, { emit }) {
    const props = __props;
    let data = common_vendor.reactive({
      value: 1,
      speList: [],
      indexList: [],
      specID: [],
      specIdList: [],
      formList: {},
      goods_spec_id: ""
    });
    common_vendor.onMounted(() => {
      setTimeout(() => {
        console.log("\u591A\u89C4\u683C", props.moreSpec);
        if (props.moreSpec != null) {
          let spec = props.moreSpec.spec_attr;
          let mateSpecId = props.moreSpec.spec_list;
          data.speList = spec;
          data.specIdList = mateSpecId;
          spec.forEach((item, index) => {
            data.indexList.push({ curIndex: 0 });
            data.specID.push(item.spec_items[0].item_id);
          });
          data.goods_spec_id = data.specID.join("_");
          makeUpId();
        } else {
          data.goods_spec_id = props.shopDetail.spec[0].goods_spec_id;
        }
      }, 200);
    });
    const close = () => {
      emit("close");
    };
    const valChange = (e) => {
      console.log("\u6570\u91CF" + e.value);
      data.value = e.value;
    };
    const popBtn = () => {
      let shopType = props.shopDetail.goodstatus;
      let buyData = { id: props.shopDetail.id, num: data.value, specId: data.goods_spec_id };
      console.log("\u5F53\u524D\u503C\u4E3A: ", buyData);
      props.btnType == 0 ? getAddCars() : common_vendor.index.navigateTo({ url: `/pages/shopCar/confirmOrder?params=${JSON.stringify(buyData)}&shopType=${shopType}` });
    };
    const checkSpec = (index, it, idx) => {
      console.log(index, it, idx);
      data.indexList[index].curIndex = idx;
      if (data.speList.length == 1) {
        data.specID.splice(index, 1, it.item_id);
      } else {
        data.specID.splice(index, data.specID.length > 1 ? 1 : 0, it.item_id);
      }
      makeUpId();
    };
    const makeUpId = () => {
      if (data.specID.length == data.speList.length) {
        let str = data.specIdList.find((item) => item.spec_sku_id == data.specID.join("_"));
        data.formList = str.form;
        data.goods_spec_id = str.goods_spec_id;
        console.log("\u67E5\u627E\u5230\u7684\u89C4\u683C", str, data.specID.join("_"));
      }
    };
    const getAddCars = async () => {
      try {
        let params = {
          goods_id: props.shopDetail.id,
          num: data.value,
          goods_spec_id: data.goods_spec_id
        };
        const res = await api_index.getAddCar(params);
        close();
        common_vendor.index.showToast({ title: "\u6210\u529F\u52A0\u5165\u8D2D\u7269\u8F66~", icon: "none" });
        console.log("getAddCar", res);
      } catch (err) {
        common_vendor.index.showToast({ title: err, icon: "none" });
        console.log("getAddCar", err);
      }
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: __props.shopType !== 3
      }, __props.shopType !== 3 ? {
        b: common_vendor.t(__props.btnType == 0 ? "\u52A0\u5165\u8D2D\u7269\u8F66" : "\u7ACB\u5373\u8D2D\u4E70")
      } : {}, {
        c: __props.shopType === 3
      }, __props.shopType === 3 ? {} : {}, {
        d: __props.shopDetail.spec[0].spec_image,
        e: common_vendor.t(__props.shopDetail.name),
        f: __props.shopDetail.goodstatus !== 3
      }, __props.shopDetail.goodstatus !== 3 ? {
        g: common_vendor.t(__props.shopDetail.spec[0].goods_price)
      } : {
        h: common_vendor.t(__props.shopDetail.spec[0].coscore)
      }, {
        i: common_vendor.f(common_vendor.unref(data).speList, (item, index, i0) => {
          return {
            a: common_vendor.t(item.group_name),
            b: common_vendor.f(item.spec_items, (it, idx, i1) => {
              return {
                a: common_vendor.t(it.spec_value),
                b: it.item_id,
                c: common_vendor.n(idx == common_vendor.unref(data).indexList[index].curIndex ? "checked" : ""),
                d: common_vendor.o(($event) => checkSpec(index, it, idx), it.item_id)
              };
            }),
            c: item.group_id
          };
        }),
        j: common_vendor.o(valChange),
        k: common_vendor.o(($event) => _ctx.value = $event),
        l: common_vendor.p({
          modelValue: _ctx.value
        }),
        m: __props.btnType == 0
      }, __props.btnType == 0 ? {
        n: common_vendor.o(popBtn)
      } : {
        o: common_vendor.t(__props.shopDetail.goodstatus == 3 ? "\u7ACB\u5373\u5151\u6362" : "\u7ACB\u5373\u8D2D\u4E70"),
        p: common_vendor.o(popBtn)
      }, {
        q: common_vendor.o(close),
        r: common_vendor.o(_ctx.open),
        s: common_vendor.p({
          show: __props.payPopShow,
          mode: "bottom",
          closeable: true,
          round: "18"
        })
      });
    };
  }
};
var Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/vue/\u5927\u5065\u5EB7\u5546\u57CE/healthMall/componets/popPay.vue"]]);
wx.createComponent(Component);