var e = require("../common/vendor.js"),
  n = require("../service/index.js"),
  r = require("../enums/index.js"),
  t = require("./util.js");
require("../config/index.js");
var i = require("../hooks/useState.js"),
  u = require("./navigate.js");
require("../constant/index.js");
var o = function (n) {
  console.log("onEmit刷新", n),
    e.index.$emit("refreshOrderDetail", n),
    e.index.$emit("updateOrderDetail"),
    e.index.$emit("refreshOrderNum"),
    e.index.$emit("updateOrderList", n),
    e.index.$emit("updateMyOrderList", n);
};
(exports.chooseDrivingLicense = function (e) {
  var r = e.orderNo;
  return t.choosePhoto().then(function (e) {
    return (
      t.showLoading(),
      n.uploadDrivingLicense({ filePath: e, order_no: r }).then(function () {
        o(r), t.hideLoading();
      })
    );
  });
}),
  (exports.getOrderStatus = function (n) {
    var t = e._.find(n, function (e) {
        return e.status === r.ProductStatusEnum.IN_QUERY;
      }),
      i = e._.find(n, function (e) {
        return e.status === r.ProductStatusEnum.TO_BE_UPLOADED;
      }),
      u = e._.every(n, function (e) {
        return (
          e.status === r.ProductStatusEnum.SUCCESS ||
          (e.status == e.status) === r.ProductStatusEnum.FAIL
        );
      });
    return t ? "，查询中" : i ? "，待上传行驶证" : u ? "，查询完成" : "";
  }),
  (exports.getProduct = function (e) {
    var n = i.useState(),
      t = n.insuranceMaintainProduct,
      u = n.accidentProduct,
      o = n.vehicleFiveProduct,
      a = n.saliProduct,
      c = n.saliCheckProduct,
      s = n.commercialInsuranceProduct,
      d = n.violationProduct,
      l = n.vehicleStatusProduct,
      m = null;
    return (
      e.split(",").length > 1
        ? (m = { product_name: "综合车况" })
        : e === r.ProductTypeEnum.INSURANCE_MAINTAIN
        ? (m = t.value)
        : e === r.ProductTypeEnum.ACCIDENT
        ? (m = u.value)
        : e === r.ProductTypeEnum.VEHICLE_FIVE
        ? (m = o.value)
        : e === r.ProductTypeEnum.COMMERICAL_INSURANCE
        ? (m = s.value)
        : e === r.ProductTypeEnum.VIOLATION
        ? (m = d.value)
        : e === r.ProductTypeEnum.SALI
        ? (m = a.value)
        : e === r.ProductTypeEnum.SALI_CHECK
        ? (m = c.value)
        : e === r.ProductTypeEnum.VEHICLE_STATUS && (m = l.value),
      m
    );
  }),
  (exports.getVehicleInfoList = function (n) {
    var r = [
        "厂家名称",
        "车型名称",
        "版本",
        "车型组名称",
        "车型组ID",
        "车ID",
        "年款",
        "上市日期",
        "新车购置价格",
        "市场价",
        "发动机型号",
        "排量",
        "档位数",
        "燃油类型",
        "燃油标号",
        "喷射方式",
        "最大功率 KW",
        "最大马力(Ps)",
        "轴距",
        "尺寸类型",
        "车身型式",
        "车体结构",
        "变速箱类型",
        "驱动方式",
        "前轮胎尺寸",
        "后轮胎尺寸",
        "前制动类型",
        "后制动类型",
        "驻车制动类型",
        "档位数",
        "座位数",
        "车门数",
        "气缸数",
        "长 mm",
        "宽",
        "高",
        "整备质量 kg",
        "是否是进口",
      ],
      t = [];
    return (
      e._.each(r, function (r) {
        var i = null,
          u = [];
        "发动机型号" === r
          ? (u = e._.filter(n, function (e) {
              return "发动机" === e.name || "发动机型号" === e.name;
            })).length > 0 && ((i = u[0]).name = "发动机型号")
          : "排量" === r
          ? (u = e._.filter(n, function (e) {
              return "排量 L" === e.name || "排量(mL)" === e.name;
            })).length > 0 && ((i = u[0]).name = "排量")
          : "变速箱类型" === r
          ? (u = e._.filter(n, function (e) {
              return "变速箱" === e.name || "变速箱类型" === e.name;
            })).length > 0 && ((i = u[0]).name = "变速箱类型")
          : (i = e._.find(n, function (e) {
              return e.name === r;
            })),
          i && t.push(i);
      }),
      (t = e._.concat(
        t,
        e._.filter(n, function (e) {
          return (
            r.indexOf(e.name) < 0 &&
            [
              "发动机",
              "发动机型号",
              "排量 L",
              "排量(mL)",
              "变速箱",
              "变速箱类型",
            ].indexOf(e.name) < 0
          );
        })
      ))
    );
  }),
  (exports.hasClickAgreement = function () {
    return !(
      !e.index.getStorageSync("hasClickAgreement") ||
      e.index.getStorageSync("hasClickAgreement") < 1
    );
  }),
  (exports.isSupportAliPay = function () {
    i.useState();
    return !1, !1;
  }),
  (exports.isSupportWeChatPay = function () {
    i.useState();
    return !0, !0;
  }),
  (exports.modifyVin = function (e) {
    var r = e.orderNo,
      i = e.vin;
    return (
      t.showLoading(),
      n.modifyOrderVin({ order_no: r, vin: i }).then(function () {
        t.showToast("修改成功"), o(r);
      })
    );
  }),
  (exports.ocrIdentifyVin = function () {
    return t.choosePhoto().then(function (e) {
      return (
        t.showLoading(),
        n.ocrUploadDrivingLicense({ filePath: e }).then(function (e) {
          return t.showToast("识别成功，请核对"), e ? e.vin : null;
        })
      );
    });
  }),
  (exports.openReport = function (e) {
    var i = e.orderNo,
      o = e.productId,
      a = e.status;
    t.showLoading();
    var c = null;
    o === r.ProductTypeEnum.INSURANCE_MAINTAIN &&
      (c =
        a === r.ProductStatusEnum.FAIL
          ? function () {
              return Promise.resolve({
                url: "/pages/insurance-maintain-blank/index",
              });
            }
          : function () {
              return Promise.resolve({
                url: "/pages/insurance-maintain-detail/index",
              });
            }),
      o === r.ProductTypeEnum.ACCIDENT &&
        (c =
          a === r.ProductStatusEnum.FAIL
            ? function () {
                return Promise.resolve({ url: "/pages/accident-blank/index" });
              }
            : function () {
                return n
                  .getReportDetail({ order_no: i, product_id: o })
                  .then(function (e) {
                    var n = e.report_url_our;
                    return {
                      url: n
                        ? "/pages/accident-web-view/index"
                        : "/pages/accident-detail/index",
                      reportUrl: n,
                    };
                  });
              }),
      o === r.ProductTypeEnum.COMMERICAL_INSURANCE &&
        (c = function () {
          return Promise.resolve({
            url: "/pages/commercial-insurance-detail/index",
          });
        }),
      o === r.ProductTypeEnum.VEHICLE_FIVE &&
        (c = function () {
          return Promise.resolve({ url: "/pages/vehicle-five-detail/index" });
        }),
      o === r.ProductTypeEnum.SALI &&
        (c = function () {
          return Promise.resolve({ url: "/pages/sali-detail/index" });
        }),
      o === r.ProductTypeEnum.SALI_CHECK &&
        (c = function () {
          return Promise.resolve({ url: "/pages/sali-check-detail/index" });
        }),
      o === r.ProductTypeEnum.VEHICLE_STATUS &&
        (c = function () {
          return Promise.resolve({ url: "/pages/vehicle-status-detail/index" });
        }),
      c
        ? c().then(function (e) {
            var n = e.url,
              r = e.reportUrl;
            t.hideLoading(),
              u.navigateTo({
                url: n,
                params: { order_no: i, product_id: o, url: r },
              });
          })
        : t.showToast("当前查询类型暂不支持");
  }),
  (exports.payForOrder = function (n) {
    var i = n.payMethod,
      u = n.data,
      a = u.orderNo;
    return (function (n) {
      var t = n.payMethod,
        i = n.data,
        u = null;
      return (
        t === r.PayMethodEnum.WECHAT_PAY &&
          (u = function () {
            return e.index.requestPayment({
              provider: "wxpay",
              timeStamp: String(i.timestamp),
              nonceStr: String(i.nonceStr),
              package: String(i.package),
              signType: String(i.signType),
              paySign: String(i.paySign),
            });
          }),
        t === r.PayMethodEnum.ALI_PAY &&
          (u = function () {
            return e.index.requestPayment({
              provider: "alipay",
              orderInfo: String(i.alipay),
            });
          }),
        u()
      );
    })({ payMethod: i, data: u })
      .then(function () {
        return Promise.resolve({ orderNo: a });
      })
      .catch(function () {
        return Promise.reject({ orderNo: a });
      })
      .finally(function () {
        o(a), t.hideLoading();
      });
  }),
  (exports.queryWithoutDrivingLicense = function (e) {
    var r = e.orderNo;
    return (
      t.showLoading(),
      n.noDrivingLicense({ order_no: r }).then(function () {
        o(r);
      })
    );
  });
