var e, t, a;
(e = getApp()),
  (t = getApp()),
  (a = require("../../utils/carcity.js")),
  Page({
    data: {
      page: 1,
      type: "22",
      regdate: "",
      mileage: "",
      carName: "",
      cityName: "",
      cityid: 0,
      provid: 0,
      carId: 0,
      banner: [],
      carHeadList: a.carHeadList,
      carKind: a.carKind,
      circular: 1500,
      conditions: [{ checked: !1, title: "不含4" }],
      hot_type: "任意号码",
      isAuthorized: !0,
      isHighBol: !1,
      letter: a.letter,
      license_plate_type: "",
      pickerArray: [],
      pickerBol: !1,
      piclerNum: [],
      query: {
        hot_type: "",
        lazy_typ: 0,
        license_plate: "",
        license_plate_code: "",
        license_plate_type: "",
        not_four_type: 1,
        pageIndex: 1,
        pageSize: 10,
        province_small: "",
      },
      rules: a.rules,
      typeName: { num: 0, title: "" },
    },
    change: function (e) {
      var t = this.data.query,
        a = e.detail.value,
        i = this.trim(a);
      (t.license_plate = i), this.setData({ query: t });
    },
    name: function (e) {
      var t = e.detail.value;
      this.setData({ name: t });
    },
    trim: function (e) {
      return (e = (e = e.replace(/\s+/gi, "")).replace(
        /\W+/,
        ""
      )).toUpperCase();
    },
    selectResult: function (e, t, a) {
      if (a)
        switch (a) {
          case 1:
            1 == t
              ? this.setData({ "query.license_plate_code": e.title })
              : this.setData({ "query.province_small": e.province_small });
            break;
          case 2:
            this.setData({
              "query.license_plate_type": e.id,
              license_plate_type: e.title,
            });
            break;
          case 3:
            this.setData({ "query.hot_type": e.id, hot_type: e.title });
        }
    },
    isGDCar: function (e) {
      var t = this.data,
        a = t.pickerArray,
        i = t.letter;
      try {
        -1 != a[0][e].province_small.indexOf("粤")
          ? (i = i.filter(function (e) {
              return "X" != e.title && "Y" != e.title;
            }))
          : "Y" != i[i.length - 1].title &&
            (i = i.concat([
              { checked: !1, title: "X" },
              { checked: !1, title: "Y" },
            ]));
      } catch (e) {
        "Y" != i[i.length - 1].title &&
          (i = i.concat([
            { checked: !1, title: "X" },
            { checked: !1, title: "Y" },
          ]));
      }
      (a[1] = i), this.setData({ letter: i, pickerArray: a });
    },
    onChange: function (e) {
      var t = e.detail.value[0];
      1 == this.data.typeName.num && this.isGDCar(t),
        this.setData({ piclerNum: e.detail.value });
    },
    openPick: function (e) {
      var t = this,
        a = this.data,
        i = a.carHeadList,
        n = a.letter,
        r = a.carKind,
        c = a.rules,
        o = a.piclerNum,
        s = a.typeName;
      if (e.currentTarget.dataset.index) {
        var l,
          d = parseInt(e.currentTarget.dataset.index);
        switch (((l = 4 == d ? this.data.pickerArray : []), d)) {
          case 1:
            (s.title = "选择车牌前缀"), (s.num = d), l.push(i), l.push(n);
            break;
          case 2:
            (s.title = "选择车牌种类"), (s.num = d), l.push(r);
            break;
          case 3:
            (s.title = "选择查找规则"), (s.num = d), l.push(c);
            break;
          case 4:
            l.forEach(function (e) {
              e.forEach(function (e) {
                e.checked = !1;
              });
            }),
              o.forEach(function (e, a) {
                (l[a][e].checked = !0), t.selectResult(l[a][e], a, s.num);
              });
        }
        var u = [];
        l.forEach(function (e, t) {
          (u[t] = 0),
            e.forEach(function (e, a) {
              e.checked && (u[t] = a);
            });
        }),
          this.setData({ pickerArray: l, piclerNum: u, typeName: s }),
          1 == d && this.isGDCar(u[0]);
      }
      this.setData({ pickerBol: !this.data.pickerBol });
    },
    mileageChanage: function (e) {
      this.setData({ mileage: e.detail.value });
    },
    sumbin: function () {
      this.tongzhi();
      var t = this.data.query;
      if (t.license_plate_code)
        if (t.license_plate_type)
          if (t.license_plate)
            if ("iosb" == e.getSystemPlatform())
              wx.showModal({
                title: "温馨提示",
                content: "iOS不支持小程序,请使用公众号查询",
                success: function (e) {
                  e.confirm
                    ? wx.navigateTo({
                        url:
                          "/pages/website/website?url=https://mp.weixin.qq.com/s?__biz=MzIwOTYxMTI2Nw==&mid=2247483888&idx=1&sn=1f5deda3e1a2d5e109dfaf8000520030&chksm=97707e9ca007f78a7ade8b1b57eda40183c6de47a6a115836fdb77748fc248c320a29e3309c6&token=1742855998&lang=zh_CN#rd&img=" +
                          wx.getStorageSync("gzhurl"),
                      })
                    : console.log("点击取消回调");
                },
              });
            else {
              var a = this,
                i = {
                  content:
                    a.data.mileage +
                    a.data.engine +
                    a.data.chepai +
                    a.data.name +
                    a.data.query.license_plate,
                };
              e.getdata(i, "checkContent").then((e) => {
                console.log("文本回调数据:", e),
                  0 == e.errcode
                    ? a.queryVin()
                    : wx.showModal({
                        title: "温馨提示",
                        content:
                          "你输入的文本检测存在违规,请检测文本内容后重新输入。",
                        success: function (e) {
                          e.confirm || console.log("点击取消回调");
                        },
                      });
              });
            }
          else
            wx.showToast({
              title: "请输入车牌号码",
              icon: "none",
              duration: 2e3,
            });
        else
          wx.showToast({
            title: "请选择车牌种类",
            icon: "none",
            duration: 2e3,
          });
      else
        wx.showToast({ title: "请选择车牌前缀", icon: "none", duration: 2e3 });
    },
    orderid: function () {
      let e = "";
      for (var t = 0; t < 8; t++) e += Math.floor(10 * Math.random());
      (e = "D" + new Date().getTime() + e), this.setData({ orderid: e });
    },
    queryVin: function () {
      if (wx.getStorageSync("uid")) {
        var e = this;
        e.orderid(),
          console.log(wx.getStorageSync("uid")),
          wx.getStorageSync("uid")
            ? (console.log("post数组", e.data),
              console.log(wx.getStorageSync("uid")),
              t.util.request({
                url: "entry/wxapp/paynum",
                method: "post",
                dataType: "json",
                data: {

                  type: "cpcx_money",
                  orderid: e.data.orderid,
                  uid: wx.getStorageSync("uid"),
                  postcardata: JSON.stringify(e.data),
                },
                success: function (a) {
                  a.data && a.data.data && 1e3 == a.data.message
                    ? t.util.request({
                        url: "entry/wxapp/Api",
                        data: {

                          uid: wx.getStorageSync("uid"),
                          r: "home.weizhang.paynum",
                          orderid: a.data.data.orderid,
                        },
                        success: function (t) {
                          wx.showModal({ content: t.data.message }),
                            e.setData({
                              weizhang_num: 1 * e.data.weizhang_num + 10,
                            }),
                            e.getDetailpay();
                        },
                      })
                    : a.data &&
                      a.data.data &&
                      a.data.code!=200 &&
                      wx.requestPayment({
                        timeStamp: a.data.data.timeStamp,
                        nonceStr: a.data.data.nonceStr,
                        package: a.data.data.package,
                        signType: "MD5",
                        paySign: a.data.data.paySign,
                        success: function (i) {
                          t.util.request({
                            url: "entry/wxapp/Api",
                            data: {

                              uid: wx.getStorageSync("uid"),
                              r: "home.weizhang.paynum",
                              orderid: a.data.data.orderid,
                            },
                            success: function (t) {
                              e.setData({
                                weizhang_num: 1 * e.data.weizhang_num + 10,
                              }),
                                wx.showModal({ content: t.data.message }),
                                e.getDetailpay();
                            },
                          });
                        },
                      });
                },
              }))
            : wx.showModal({
                title: "温馨提醒",
                content: "使用本功能请先登录后在使用~",
                showCancel: !1,
                success: function (e) {
                  e.confirm && wx.reLaunch({ url: "/pages/mine/index" });
                },
              });
      } else
        wx.showModal({
          title: "温馨提示",
          content: "请去个人中心授权登录用户信息",
          success: function (e) {
            e.confirm
              ? wx.reLaunch({ url: "/pages/mine/index" })
              : console.log("点击取消回调");
          },
        });
    },
    getDetailpay: function () {
      var t = this;
      this.setData({
        "query.uid": wx.getStorageSync("uid"),
        "query.orderid": t.data.orderid,
        "query.name": t.data.name,
      });
      var a = this.data.query;
      e.getdata(a, "cpcx").then((e) => {
        console.log("年检回调数据:", e.data),
          wx.navigateTo({ url: "../cpcx/carcxjl?orderid=" + t.data.orderid }),
          (e = e.data).data && t.setData({ order: e.data.result });
      });
    },
    tongzhi: function (t) {
      e.getdata({ type: "4" }, "getdyxx").then((t) => {
        console.log(t.data),
          wx.requestSubscribeMessage({
            tmplIds: [t.data],
            success(a) {
              "accept" == a[t.data]
                ? (wx.showToast({ title: "订阅成功" }),
                  e.util.request({
                    url: "entry/wxapp/addtemplateid",
                    data: { templateid: t.data, uid: wx.getStorageSync("uid") },
                    header: { "content-type": "application/json" },
                    success: function (e) {
                      console.log(e);
                    },
                  }))
                : wx.showToast({ title: "订阅失败" });
            },
          });
      });
    },
    toDetailExample: function () {
      wx.navigateTo({ url: "../cpcx/carcxjl?orderid=D167040911399614525814" });
    },
    toSelectCar: function () {
      wx.navigateTo({ url: "/pages/selectCar/selectCar" });
    },
    toSelectCity: function () {
      wx.navigateTo({ url: "/pages/selectCity/selectCity" });
    },
    toSelectTime: function () {
      wx.navigateTo({ url: "/pages/selectTime/selectTime" });
    },
    saoys: function (e) {
      wx.navigateTo({ url: "../xszsb/xszsb?type=2" });
    },
    onLoad: function (e) {
      wx.getStorageSync("uid") || getApp().wxlogin(),
        wx.removeStorageSync("cardata"),
        this.orderid(),
        wx.removeStorageSync("carvehicle"),
        wx.removeStorageSync("carprov"),
        wx.removeStorageSync("carcity"),
        wx.removeStorageSync("cartime"),
        wx.removeStorageSync("cardatawx");
    },
    onReady: function () {},
    onShow: function () {
      e.appdengl(), this.getDetail(1);
      var t = wx.getStorageSync("cardata");
      if ((console.log("行驶证数据", t), t)) {
        this.setData({
          "query.province_small": t.号牌号码.words.substring(0, 1),
          "query.license_plate_code": t.号牌号码.words.substring(1, 2),
          "query.license_plate": t.号牌号码.words.substring(2, 8),
          "query.name": t.所有人.words,
          name: t.所有人.words,
        });
        for (
          var a = t.车辆类型.words, i = this.data.carKind, n = 0;
          n < i.length;
          ++n
        )
          i[n].title == a &&
            this.setData({
              license_plate_type: i[n].title,
              "query.license_plate_type": i[n].id,
            });
      }
      var r = wx.getStorageSync("carvehicle"),
        c = wx.getStorageSync("carprov"),
        o = wx.getStorageSync("carcity"),
        s = wx.getStorageSync("cartime"),
        l = "";
      "" != o && null != o && (l = c.name + "-" + o.name),
        console.log("" == r),
        "" != r &&
          "" != s &&
          parseInt(s.split("-")[0]) < parseInt(r.makeyear) &&
          (s = ""),
        this.setData({
          carName: r.salesdesc,
          cityName: l,
          regdate: s,
          cityid: o.id,
          provid: c.id,
          carId: r.autohomeid,
        });
    },
    onPullDownRefresh: function () {
      this.clearCache(), this.getArticles(1);
    },
    onReachBottom: function () {
      console.log("加上"), this.getDetail(this.data.page);
    },
    clearCache: function () {
      this.setData({ repairList: [], page: 1 });
    },
    getDetail: function (t) {
      var a = this,
        i = { uid: wx.getStorageSync("uid"), type: a.data.type, page: t };
      e.getdata(i, "carqxcx").then((e) => {
        if ((console.log("回调数据:", e), e.data && 200 == e.code))
          if (1 == t) a.setData({ repairList: e.data, page: a.data.page + 1 });
          else {
            var i = a.data.repairList;
            i.push.apply(i, e.data),
              a.setData({ repairList: i, page: a.data.page + 1 });
          }
      });
    },
    onHide: function () {},
    onUnload: function () {},
    onShareAppMessage: function () {},
    showRenMsg: function () {
      wx.showToast({
        title: "人工查询中,请稍等",
        icon: "none",
        duration: 3e3,
      });
    },
    showGaoMsg: function () {
      wx.showToast({
        title: "查不到记录,建议使用高级出险查询。",
        icon: "none",
        duration: 3e3,
      });
    },
    getDangerDetail: function (e) {
      var t = e.currentTarget.dataset.orderid;
      wx.navigateTo({
        url: "/packageA/pages/cpcx/carcxjl?orderid=" + t,
        success: function () {},
      });
    },
  });