booking.js 12 KB
"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const common_api = require("../../common/api.js");
require("../../common/login.js");
require("../../common/request.js");
require("../../config.js");
if (!Array) {
  const _easycom_uni_countdown2 = common_vendor.resolveComponent("uni-countdown");
  const _easycom_uni_popup_dialog2 = common_vendor.resolveComponent("uni-popup-dialog");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_countdown2 + _easycom_uni_popup_dialog2 + _easycom_uni_popup2)();
}
const _easycom_uni_countdown = () => "../../uni_modules/uni-countdown/components/uni-countdown/uni-countdown.js";
const _easycom_uni_popup_dialog = () => "../../uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (_easycom_uni_countdown + _easycom_uni_popup_dialog + _easycom_uni_popup)();
}
const _sfc_main = {
  __name: "booking",
  setup(__props) {
    const {
      proxy
    } = common_vendor.getCurrentInstance();
    common_vendor.ref("/static/v1.png");
    common_vendor.ref(["消费记录", "充值记录"]);
    common_vendor.ref(0);
    common_vendor.ref(false);
    const lockPay = common_vendor.ref(false);
    const isClick = common_vendor.ref(false);
    const alertDialog = common_vendor.ref(null);
    const alertPayOk = common_vendor.ref(null);
    const alertPayWrong = common_vendor.ref(null);
    const currUser = common_vendor.ref({});
    const orderId = common_vendor.ref("");
    const order = common_vendor.ref({});
    const orderFrom = common_vendor.ref(0);
    const orderInfo = common_vendor.ref([]);
    const myBalance = common_vendor.ref(0);
    const form = common_vendor.ref({
      payType: "2"
    });
    const countdown = common_vendor.ref({
      start: false,
      minute: 0,
      second: 0
    });
    common_vendor.onLoad((option) => {
      common_vendor.index.showLoading({
        title: "加载中"
      });
      if (option.id) {
        orderFrom.value = 1;
        common_api.getMaItemById(option.id).then((res) => {
          common_vendor.index.hideLoading();
          order.value = res.data;
          form.value.orderId = option.id;
          orderId.value = option.id;
          form.value.orderAmount = res.data.useBalancePrice;
          let leftTime = common_vendor.dayjs(res.data.createTime).add(15, "minute").valueOf() - common_vendor.dayjs().valueOf();
          if (leftTime > 0) {
            countdown.value = {
              start: true,
              minute: Math.floor(leftTime / 1e3 / 60),
              second: Math.ceil(leftTime / 1e3) % 60
            };
          } else {
            countdown.value = {
              start: true
            };
            timeup();
          }
        });
      } else {
        const eventChannel = proxy.getOpenerEventChannel();
        eventChannel.on("acceptDataFromOpenerPage", (data) => {
          orderInfo.value = data.orderInfo;
          orderId.value = data.order.id;
          common_api.getMaItemById(orderId.value).then((res) => {
            common_vendor.index.hideLoading();
            order.value = res.data;
            form.value.orderAmount = res.data.useBalancePrice;
          });
          eventChannel.emit("acceptDataFromOpenedPage");
          countdown.value = {
            start: true
          };
        });
      }
      currUser.value = common_vendor.index.getStorageSync("currUser");
      common_api.getMyBalance().then((res) => {
        myBalance.value = res.data;
      });
    });
    function payChange(evt) {
      form.value.payType = evt.detail.value;
    }
    function pay(n) {
      if (lockPay.value == true) {
        return;
      } else {
        lockPay.value = true;
      }
      if (n == "2" && parseFloat(myBalance.value) < parseFloat(order.value.useBalancePrice)) {
        common_vendor.index.showToast({
          title: "余额不足,无法支付",
          icon: "none",
          duration: 2e3
        });
        lockPay.value = false;
      } else {
        alertDialog.value.open();
      }
    }
    function dialogConfirm() {
      if (isClick.value == true) {
        return;
      } else {
        isClick.value = true;
        common_vendor.index.showLoading({
          title: "支付中..."
        });
        goPayForOrder();
      }
    }
    function goPayForOrder() {
      if (form.value.payType != "2") {
        form.value.orderAmount = order.value.unuseBalancePrice;
      }
      common_api.payForOrder(orderId.value, form.value).then((res) => {
        isClick.value = false;
        if (res.data.weixinData) {
          wePay(res.data.weixinData);
        } else {
          alertPayOk.value.open();
          subscribe();
          lockPay.value = true;
        }
      }).catch(() => {
        alertPayWrong.value.open();
      }).finally(() => {
        common_vendor.index.hideLoading();
      });
    }
    function wePay(configdata) {
      common_vendor.index.requestPayment({
        "provider": "wxpay",
        "appId": configdata.appId,
        "nonceStr": configdata.nonceStr,
        "package": configdata.packageValue,
        // 随机字符串
        "timeStamp": configdata.timeStamp,
        // 时间戳(单位:秒)
        "signType": configdata.signType,
        // 签名,这里用的 MD5/RSA 签名
        "paySign": configdata.paySign,
        success(res) {
          alertPayOk.value.open();
          subscribe();
          common_api.maPayConfirm({
            orderId: orderId.value,
            successFlag: true
          }).then((res2) => {
            lockPay.value = false;
          });
        },
        fail(e) {
          common_vendor.index.showToast({
            title: "支付取消",
            icon: "none",
            duration: 2e3
          });
          common_api.maPayConfirm({
            orderId: orderId.value,
            successFlag: false
          }).then((res) => {
            lockPay.value = false;
          });
        }
      });
    }
    function payCancel() {
      common_vendor.index.showModal({
        title: "提示",
        content: "确定取消订单吗",
        success: function(res) {
          if (res.confirm) {
            const eventChannel = proxy.getOpenerEventChannel();
            common_api.cancelOrder(orderId.value).then((res2) => {
              eventChannel.emit("acceptDataFromOpenedPage");
              common_vendor.index.navigateBack();
            });
          } else if (res.cancel) {
            console.log("用户点击取消");
          }
        }
      });
    }
    function dialogClose() {
      alertDialog.value.close();
      lockPay.value = false;
    }
    function goBillDetail() {
      common_vendor.index.redirectTo({
        url: `/pages/usercenter/billsDetail?id=${orderId.value}`
      });
    }
    function timeup() {
      if (countdown.value.start) {
        common_vendor.index.showModal({
          title: "提示",
          content: "订单支付已超时",
          showCancel: false,
          success: function(res) {
            if (res.confirm) {
              common_api.cancelOrder(orderId.value).then((res2) => {
                common_vendor.index.navigateBack();
              });
            }
          }
        });
      }
    }
    function subscribe() {
      common_vendor.index.requestSubscribeMessage({
        tmplIds: ["p7_a1SGyGvJeOdwx_GKl6UlrWiWpNnejUArbnEPf-k4"],
        success: (res) => {
          console.log("success:", res);
        }
      });
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.t(order.value.id),
        b: orderFrom.value == 0
      }, orderFrom.value == 0 ? {
        c: common_vendor.t(common_vendor.unref(common_vendor.dayjs)().format("YYYY-MM-DD"))
      } : {}, {
        d: orderFrom.value == 1
      }, orderFrom.value == 1 ? {
        e: common_vendor.t(order.value.createTime)
      } : {}, {
        f: common_vendor.t(currUser.value.userName || order.value.orderName),
        g: common_vendor.t(currUser.value.phonenumber || order.value.orderTelno),
        h: order.value.projectName
      }, order.value.projectName ? {
        i: common_vendor.t(order.value.projectName)
      } : order.value.sonList ? {
        k: common_vendor.t(order.value.sonList[0].projectName)
      } : {}, {
        j: order.value.sonList,
        l: order.value.sonList
      }, order.value.sonList ? {
        m: common_vendor.f(order.value.sonList, (info, index, i0) => {
          return {
            a: common_vendor.t(`明细 ${info.siteName}  ${info.orderDate.substring(5, 10)}  (${info.orderTimePeriod.replace(/,/, "-")} )  ${info.orderHour}小时`),
            b: common_vendor.t(info.orderAmount),
            c: info.id
          };
        })
      } : {}, {
        n: !order.value.sonList
      }, !order.value.sonList ? {
        o: common_vendor.t(`明细 ${order.value.siteName} ${order.value.orderDate.substring(5, 10)}  (${order.value.orderTimePeriod.replace(/,/, "-")})  ${order.value.orderHour}小时`),
        p: common_vendor.t(order.value.orderAmount)
      } : {}, {
        q: form.value.payType == "2"
      }, form.value.payType == "2" ? {
        r: common_vendor.t(order.value.unuseBalancePrice)
      } : {}, {
        s: form.value.payType == "2"
      }, form.value.payType == "2" ? {
        t: common_vendor.t(order.value.useBalancePrice)
      } : {}, {
        v: form.value.payType == "7"
      }, form.value.payType == "7" ? {
        w: common_vendor.t(order.value.unuseBalancePrice)
      } : {}, {
        x: form.value.remark,
        y: common_vendor.o(($event) => form.value.remark = $event.detail.value),
        z: common_assets._imports_0,
        A: common_assets._imports_1,
        B: common_vendor.t(myBalance.value),
        C: common_vendor.o(payChange),
        D: orderFrom.value == 0
      }, orderFrom.value == 0 ? {
        E: common_vendor.o(payCancel),
        F: common_vendor.o(timeup),
        G: common_vendor.p({
          color: "#fff",
          splitorColor: "#fff",
          ["show-day"]: false,
          ["show-hour"]: false,
          minute: 15,
          second: 0
        }),
        H: common_vendor.o(($event) => pay(form.value.payType))
      } : {
        I: common_vendor.o(timeup),
        J: common_vendor.p({
          color: "#fff",
          splitorColor: "#fff",
          ["show-day"]: false,
          ["show-hour"]: false,
          start: countdown.value.start,
          minute: countdown.value.minute,
          second: countdown.value.second
        }),
        K: common_vendor.o(($event) => pay(form.value.payType))
      }, {
        L: common_vendor.o(dialogConfirm),
        M: common_vendor.o(dialogClose),
        N: common_vendor.p({
          type: "info",
          cancelText: "取消",
          confirmText: "确定",
          content: "是否确认支付?"
        }),
        O: common_vendor.sr(alertDialog, "86691f90-2", {
          "k": "alertDialog"
        }),
        P: common_vendor.p({
          type: "dialog"
        }),
        Q: common_vendor.o(goBillDetail),
        R: common_vendor.o(goBillDetail),
        S: common_vendor.p({
          type: "success",
          confirmText: "查看订单详情",
          content: "支付成功"
        }),
        T: common_vendor.sr(alertPayOk, "86691f90-4", {
          "k": "alertPayOk"
        }),
        U: common_vendor.p({
          type: "dialog"
        }),
        V: common_vendor.o(goBillDetail),
        W: common_vendor.o(goBillDetail),
        X: common_vendor.p({
          type: "error",
          confirmText: "查看订单详情",
          content: "支付失败"
        }),
        Y: common_vendor.sr(alertPayWrong, "86691f90-6", {
          "k": "alertPayWrong"
        }),
        Z: common_vendor.p({
          type: "dialog"
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-86691f90"], ["__file", "/Users/yangyang/project/j-mini/Venue/pages/index/booking.vue"]]);
wx.createPage(MiniProgramPage);