var t;
(t = getApp()),
  Page({
    data: {
      showLetter: "",
      winHeight: 0,
      tHeight: 0,
      bHeight: 0,
      startPageY: 0,
      carList: [],
      isShowLetter: !1,
      scrollTop: 0,
      three_none: "none",
      two_none: "none",
      hasback: "none",
      car_series: [],
      car_ser: null,
      searchLetter: [
        "*",
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "J",
        "K",
        "L",
        "M",
        "N",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "W",
        "X",
        "Y",
        "Z",
      ],
      car_vend_ser: [],
    },
    onLoad: function () {
      var e = this;
      wx.showLoading({ title: "请求中" }),
        t.getdata({ type: 1, pid: 0 }, "carallnew").then((t) => {
          var a = t.data;
          console.log("回调数据汽车：", t), e.crCarList(a);
        });
      for (
        var a = e.data.searchLetter,
          n = wx.getSystemInfoSync().windowHeight,
          o = n / a.length,
          r = [],
          s = 0;
        s < a.length;
        s++
      ) {
        var i = {};
        (i.name = a[s]),
          (i.tHeight = s * o),
          (i.bHeight = (s + 1) * o),
          r.push(i);
      }
      e.setData({ winHeight: n, itemH: o, searchLetter: r });
    },
    searchStart: function (t) {
      var e = t.currentTarget.dataset.letter,
        a = t.touches[0].pageY;
      this.setScrollTop(this, e),
        this.nowLetter(a, this),
        this.setData({ showLetter: e, startPageY: a, isShowLetter: !0 });
    },
    searchMove: function (t) {
      var e = t.touches[0].pageY,
        a = this.data.startPageY,
        n = this.data.tHeight,
        o = this.data.bHeight;
      console.log(e),
        a - e > 0
          ? e < n && this.nowLetter(e, this)
          : e > o && this.nowLetter(e, this);
    },
    searchEnd: function (t) {
      var e = this;
      setTimeout(function () {
        e.setData({ isShowLetter: !1 });
      }, 1e3);
    },
    nowLetter: function (t, e) {
      for (
        var a = this.data.searchLetter, n = 0, o = 0, r = "", s = 0;
        s < a.length;
        s++
      )
        if (a[s].tHeight <= t && t <= a[s].bHeight) {
          (n = a[s].bHeight), (o = a[s].tHeight), (r = a[s].name);
          break;
        }
      this.setScrollTop(e, r),
        e.setData({ bHeight: n, tHeight: o, showLetter: r, startPageY: t });
    },
    setScrollTop: function (t, e) {
      for (
        var a = 0, n = t.data.carList, o = 0, r = 0, s = 0;
        s < n.length;
        s++
      ) {
        if (e == n[s].shou_zm) {
          a = 30 * r + 41 * o;
          break;
        }
        console.log("数字", s),
          console.log(n[s]),
          r++,
          (o += n[s].carInfo.length);
      }
      t.setData({ scrollTop: a });
    },
    btn_pinpai: function (e) {
      var a = this,
        n = { type: 2, pid: e.currentTarget.dataset.brand };
      t.getdata(n, "carallnew").then((t) => {
        var e = t.data;
        console.log("回调数据汽车：", e),
          a.setData({
            three_none: "none",
            two_none: "block",
            hasback: "block",
            car_series: e,
          });
      });
    },
    btn_name: function (e) {
      var a = this,
        n = { type: 3, pid: e.currentTarget.dataset.familyid };
      t.getdata(n, "carallnew").then((t) => {
        var e = t.data;
        console.log("回调数据汽车xiang：", e),
          a.setData({ three_none: "block", hasback: "block", car_vend_ser: e });
      });
    },
    btn_sel_name: function (t) {
      var e = t.currentTarget.dataset.item;
      console.log(e),
        wx.setStorageSync("carvehicle", e),
        wx.navigateBack({ delta: 1 });
    },
    crCarList: function (t) {
      for (var e = this.data.searchLetter, a = [], n = 1; n < e.length; n++) {
        var o = e[n].name,
          r = [],
          s = {};
        s.shou_zm = o;
        for (var i = 0; i < t.length; i++) o == t[i].sort && r.push(t[i]);
        (s.carInfo = r), a.push(s);
      }
      this.setData({ carList: a }), wx.hideLoading();
    },
    crFamilyList: function (t) {
      var e = {};
      for (var a in (console.log(t), t)) {
        var n = t[a].factory;
        null == e[n] ? (e[n] = [t[a]]) : e[n].push(t[a]);
      }
      console.log(e), this.setData({ car_series: e });
    },
    goback: function () {
      "block" == this.data.three_none
        ? this.setData({ three_none: "none" })
        : "block" == this.data.two_none
        ? this.setData({ two_none: "none", hasback: "none" })
        : this.setData({ hasback: "none" });
    },
  });
