"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const api_api = require("../../api/api.js");
const store_index = require("../../store/index.js");
const utils_fun = require("../../utils/fun.js");
if (!Array) {
  const _easycom_up_tag2 = common_vendor.resolveComponent("up-tag");
  const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
  const _easycom_up_button2 = common_vendor.resolveComponent("up-button");
  const _easycom_uni_popup_dialog2 = common_vendor.resolveComponent("uni-popup-dialog");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_up_tag2 + _easycom_up_icon2 + _easycom_up_button2 + _easycom_uni_popup_dialog2 + _easycom_uni_popup2)();
}
const _easycom_up_tag = () => "../../uni_modules/uview-plus/components/u-tag/u-tag.js";
const _easycom_up_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
const _easycom_up_button = () => "../../uni_modules/uview-plus/components/u-button/u-button.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_up_tag + _easycom_up_icon + _easycom_up_button + _easycom_uni_popup_dialog + _easycom_uni_popup)();
}
const _sfc_main = {
  __name: "star",
  setup(__props) {
    const inputDialog = common_vendor.ref(null);
    let info = common_vendor.reactive({});
    let currentPrice = common_vendor.ref({});
    let id = common_vendor.ref("");
    let userCard = common_vendor.ref([]);
    let userCardId = common_vendor.ref(null);
    let payType = common_vendor.ref(null);
    let dataForm = common_vendor.reactive({
      money: 30
    });
    common_vendor.onLoad((options) => {
      if (options.q) {
        let search = decodeURIComponent(options.q);
        search = search.split("?")[1];
        const pairs = search ? search.split("&") : [];
        const query = {};
        for (let i = 0; i < pairs.length; ++i) {
          const [key, value] = pairs[i].split("=");
          query[key] = query[key] || decodeURIComponent(value);
        }
        if (query.num) {
          id.value = query.num;
          infoDate(query.num);
        }
      }
      if (options.id) {
        id.value = options.id;
        infoDate(options.id);
      }
    });
    let getUserCard = async (e) => {
      let _res = await api_api.userCardUsableList({ stationId: e });
      userCard.value = _res;
      if (_res.length == 0) {
        payType.value = 1;
      }
    };
    let infoDate = async (e) => {
      let _res = await api_api.gunInfo({ deviceNo: e });
      info = _res;
      getUserCard(_res.stationId);
      currentPrice.value = _res.currentPrice;
      console.log(_res.deviceNo, "_res.deviceNo");
      console.log(_res.gunNo, "_res.gunNo");
      store_index.store.commit("setInsertStatus", _res.insertStatus);
      common_vendor.index.sendSocketMessage({
        data: JSON.stringify({
          command: "sub",
          deviceNo: _res.deviceNo,
          gunNo: _res.gunNo
        }),
        success: (res) => {
          console.log("发送成功");
        },
        fail: (err) => {
          console.log(err);
          console.log("发送失败");
        }
      });
    };
    let dialogInputConfirm = (e) => {
      dataForm.money = e;
    };
    let openDialog = () => {
      console.log(12345);
      inputDialog.value.open();
    };
    let toRechargeCard = async () => {
      common_vendor.index.showLoading({
        title: "启动充电中...",
        mask: true
      });
      let _res = await api_api.startChargingByCard({
        deviceNo: info.deviceNo,
        gunNo: info.gunNo,
        amount: dataForm.money,
        userCardId: userCardId.value
      });
      store_index.store.commit("setTransactionNo", _res.transactionNo);
      store_index.store.commit("setSokStatus", 0);
      timeMap(_res);
    };
    let toRecharge = async () => {
      common_vendor.index.showLoading({
        title: "启动充电中...",
        mask: true
      });
      let _res = await api_api.startChargingByWallet({
        deviceNo: info.deviceNo,
        gunNo: info.gunNo,
        amount: dataForm.money
      });
      store_index.store.commit("setTransactionNo", _res.transactionNo);
      store_index.store.commit("setSokStatus", 0);
      timeMap(_res);
    };
    const timeMap = (_res) => {
      var time = setInterval(async () => {
        if (store_index.store.state.sokStatus != 1) {
          let _data = await api_api.ordersInfo({
            transactionNo: _res.transactionNo
          });
          store_index.store.commit("setDataObj", _data);
          if (_data.status == 3) {
            common_vendor.index.hideLoading();
            common_vendor.index.navigateTo({
              url: `/pageOrder/recharge/recharge?transactionNo=${_res.transactionNo}&type=order`
            });
            clearTimeout(time);
            store_index.store.commit("setSokStatus", 0);
          }
          if (_data.status == -1) {
            common_vendor.index.hideLoading();
            common_vendor.index.showModal({
              title: "提示",
              content: "启动失败，请重试",
              showCancel: false,
              confirmText: "确认",
              success: () => {
              }
            });
            clearTimeout(time);
            store_index.store.commit("setSokStatus", 0);
          }
          if (_data.status == -2) {
            common_vendor.index.hideLoading();
            common_vendor.index.showModal({
              title: "提示",
              content: "启动超时，请重试",
              showCancel: false,
              confirmText: "确认",
              success: () => {
              }
            });
            clearTimeout(time);
            store_index.store.commit("setSokStatus", 0);
          }
        }
      }, 5e3);
    };
    const payTo = () => {
      let itemList = ["余额付款"];
      if (userCard.value.length != 0) {
        itemList.push("电卡支付");
      }
      common_vendor.index.showActionSheet({
        itemList,
        success: function(res) {
          payType.value = res.tapIndex + 1;
        },
        fail: function(res) {
          console.log(res.errMsg);
        }
      });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.t(common_vendor.unref(info).stationName),
        b: common_vendor.t(common_vendor.unref(info).gunName),
        c: common_assets._imports_0$6,
        d: common_vendor.o(($event) => common_vendor.unref(utils_fun.copy)(common_vendor.unref(info).gunName)),
        e: common_vendor.t(common_vendor.unref(info).occupyCostInfo),
        f: common_vendor.t(common_vendor.unref(info).parkCostInfo),
        g: common_vendor.p({
          size: "mini",
          text: `当前计费时间段:${common_vendor.unref(currentPrice).startTime}-${common_vendor.unref(currentPrice).endTime}`,
          plain: true,
          plainFill: true
        }),
        h: common_vendor.t(common_vendor.unref(currentPrice).totalAmount),
        i: common_vendor.unref(store_index.store).state.insertStatus == 1
      }, common_vendor.unref(store_index.store).state.insertStatus == 1 ? {
        j: common_vendor.p({
          size: "mini",
          text: "已插枪",
          plain: true,
          plainFill: true
        })
      } : {}, {
        k: common_vendor.t(common_vendor.unref(payType) == 1 ? "余额付款" : common_vendor.unref(payType) == 2 ? "电卡支付" : "请选择"),
        l: common_vendor.o(payTo),
        m: common_vendor.unref(payType) == 1
      }, common_vendor.unref(payType) == 1 ? {
        n: common_vendor.p({
          size: "mini",
          text: `余额原路退款`,
          plain: true,
          plainFill: true
        }),
        o: common_vendor.t(common_vendor.unref(dataForm).money),
        p: common_vendor.o((...args) => common_vendor.unref(openDialog) && common_vendor.unref(openDialog)(...args))
      } : {}, {
        q: common_vendor.unref(payType) == 2
      }, common_vendor.unref(payType) == 2 ? {
        r: common_vendor.f(common_vendor.unref(userCard), (item, index, i0) => {
          return common_vendor.e({
            a: common_vendor.unref(userCardId) == item.id
          }, common_vendor.unref(userCardId) == item.id ? {
            b: "2dd6a3c8-3-" + i0,
            c: common_vendor.p({
              name: "checkbox-mark",
              color: "#fff"
            })
          } : {}, {
            d: common_vendor.t(item.name),
            e: common_vendor.t(item.cardNo),
            f: common_vendor.t(item.balance),
            g: common_vendor.o(($event) => common_vendor.isRef(userCardId) ? userCardId.value = item.id : userCardId = item.id),
            h: index
          });
        })
      } : {}, {
        s: common_vendor.t(common_vendor.unref(currentPrice).totalAmount),
        t: !common_vendor.unref(payType)
      }, !common_vendor.unref(payType) ? {
        v: common_vendor.p({
          customStyle: {
            height: "80rpx",
            width: "230rpx"
          },
          disabled: true,
          color: "#4879e6",
          text: "请选择支付方式",
          shape: "circle"
        })
      } : {}, {
        w: common_vendor.unref(payType) == 1
      }, common_vendor.unref(payType) == 1 ? {
        x: common_vendor.o(common_vendor.unref(toRecharge)),
        y: common_vendor.p({
          customStyle: {
            height: "80rpx",
            width: "280rpx"
          },
          color: "#4879e6",
          shape: "circle",
          text: "余额支付，启动充电"
        })
      } : {}, {
        z: common_vendor.unref(payType) == 2
      }, common_vendor.unref(payType) == 2 ? {
        A: common_vendor.o(common_vendor.unref(toRechargeCard)),
        B: common_vendor.p({
          customStyle: {
            height: "80rpx",
            width: "280rpx"
          },
          disabled: !common_vendor.unref(userCardId),
          color: "#4879e6",
          text: common_vendor.unref(userCardId) ? "电卡支付，启动充电" : "请选择电卡",
          shape: "circle"
        })
      } : {}, {
        C: () => ({
          r: inputClose
        }),
        D: common_vendor.o(common_vendor.unref(dialogInputConfirm)),
        E: common_vendor.p({
          mode: "input",
          title: "请输入预付金额",
          value: common_vendor.unref(dataForm).money,
          placeholder: "请输入内容"
        }),
        F: () => ({
          r: inputDialog,
          k: "inputDialog"
        }),
        G: common_vendor.p({
          type: "dialog"
        })
      });
    };
  }
};
my.createPage(_sfc_main);
