checkPayMode.js 4.7 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_popup2 = common_vendor.resolveComponent("u-popup");
  _easycom_u_popup2();
}
const _easycom_u_popup = () => "../uni_modules/uview-plus/components/u-popup/u-popup.js";
if (!Math) {
  _easycom_u_popup();
}
const _sfc_main = {
  props: {
    payParams: {
      type: Object,
      default: {}
    },
    modeShow: {
      type: Boolean,
      default: false
    },
    adressId: {
      type: String,
      default: ""
    },
    totalPrice: {
      type: String,
      default: 0
    },
    balance: {
      type: String,
      default: 0
    },
    isOrderPay: {
      type: Boolean,
      default: false
    },
    orderId: {
      type: String,
      default: ""
    },
    carId: {
      type: String,
      default: ""
    }
  },
  emits: ["canclePop"],
  setup(__props, { emit }) {
    const props = __props;
    common_vendor.onMounted(() => {
      setTimeout(() => {
        if (props.totalPrice > props.balance) {
          payMode[1].shows = false;
        }
      }, 100);
    });
    common_vendor.watchEffect(() => {
      if (props.totalPrice < props.balance) {
        payMode[1].shows = true;
      }
    });
    const payMode = common_vendor.reactive([
      { id: 1, name: "\u5FAE\u4FE1\u652F\u4ED8", check: true, modeUrl: "/static/shopCarIc/weCaat.png", shows: true },
      { id: 2, name: "\u4F59\u989D\u652F\u4ED8", check: false, modeUrl: "/static/shopCarIc/yue.png", shows: true }
    ]);
    common_vendor.ref(0);
    let defaultMode = common_vendor.ref(0);
    let checkPay = (index) => {
      defaultMode.value = index;
    };
    const subOrder = () => {
      if (props.car_Id) {
        console.log("\u8D2D\u7269\u8F66\u652F\u4ED8", props.car_Id);
        getCarPays();
      } else {
        console.log("dindan\u652F\u4ED8", props.car_Id);
        props.isOrderPay ? getOrderPays() : getPays();
      }
    };
    const goRecharge = () => {
      common_vendor.index.navigateTo({ url: "/pages/mine/recharge" });
    };
    const canclePop = () => {
      emit("canclePop");
    };
    const { proxy } = common_vendor.getCurrentInstance();
    const getPays = async () => {
      try {
        let { id, num, specId } = props.payParams;
        let params = {
          goods_id: id,
          num,
          goods_spec_id: specId,
          address_id: props.adressId,
          fangs: defaultMode.value == 0 ? 1 : 2,
          remark: ""
        };
        const res = await api_index.getPay(params);
        proxy.$methods.pay(res);
        canclePop();
      } catch (err) {
        common_vendor.index.showToast({ title: err, icon: "none" });
        console.log("getPay", err);
      }
    };
    const getCarPays = async () => {
      try {
        let params = {
          cart_ids: props.car_Id,
          address_id: props.adressId,
          remark: "",
          fangs: defaultMode.value == 0 ? 1 : 2
        };
        const res = await api_index.getCarPay(params);
        proxy.$methods.showTN("\u4F59\u989D\u652F\u4ED8\u6210\u529F~");
        canclePop();
        console.log("getCarPay", res);
      } catch (err) {
        common_vendor.index.showToast({ title: err, icon: "none" });
        console.log("getCarPay", err);
      }
    };
    const getOrderPays = async () => {
      try {
        const res = await api_index.getOrderPay(props.orderId, defaultMode.value == 0 ? 1 : 2);
        proxy.$methods.pay(res);
        canclePop();
        console.log("getOrderPay", res);
      } catch (err) {
        common_vendor.index.showToast({ title: err, icon: "none" });
        console.log("getOrderPay", err);
      }
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.f(common_vendor.unref(payMode), (item, index, i0) => {
          return common_vendor.e({
            a: item.modeUrl,
            b: common_vendor.t(item.name),
            c: item.shows
          }, item.shows ? {
            d: common_vendor.unref(defaultMode) == index ? "/static/shopCarIc/modeCheck.png" : "/static/shopCarIc/checks.png"
          } : {
            e: common_vendor.o(goRecharge)
          }, {
            f: item.id,
            g: common_vendor.o(($event) => common_vendor.unref(checkPay)(index), item.id)
          });
        }),
        b: common_vendor.o(subOrder),
        c: common_vendor.o(canclePop),
        d: common_vendor.p({
          show: __props.modeShow,
          bgColor: "#F6F8FA",
          closeable: true,
          round: "12"
        })
      };
    };
  }
};
var Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/vue/\u5927\u5065\u5EB7\u5546\u57CE/healthMall/componets/checkPayMode.vue"]]);
wx.createComponent(Component);