var t;
(t = getApp()),
  Page({
    data: {
      isShow: !1,
      invitationcode: '',
      is_ok: !1,
      banner: [],
      indicatorDots: !0,
      autoplay: !0,
      interval: 5e3,
      duration: 1e3,
      textJson: [],
      textIndex: 0,
      nav_choose: ["分类", "品牌", "年限", "公里数", "排序"],
      active_index: 0,
      sortArr: [
        "最新发布",
        "价格最低",
        "价格最高",
        "里程最少",
        "年龄最短",
        "距离最近",
      ],
      km_arr: [
        "0~3万",
        "3~5万",
        "5~10万",
        "10~15万",
        "15~20万",
        "20~30万",
        "30~50万",
        "50万以上",
      ],
      year_arr: ["全新车", "1~3年", "3~5年", "5~9年", "10年以上"],
      index: 0,
      fenlei_id: 0,
      pinpai_id: 0,
      nianxian_id: 0,
      km_id: 0,
      sort_id: 0,
      car_year: "",
      car_brand: "",
      car_km: "",
      car_class: "",
      search_arr: [],
      market: [],
      brand: [],
      check_name: "",
      carList: [],
      sort_show: !1,
      leftid: 1,
      show_new: !0,
      brand_show: !1,
      recom: 0,
      home_arr: [],
      brandname: "",
      selectbrand: "",
      brand_status: 0,
      plate_type: 1,
      scanReachBottom: !1,
      unitid: 123,
      latitude: 0,
      longitude: 0,
      region: ["", "", ""],
    },
    onLoad: function (a) {
      console.log("uid", wx.getStorageSync("uid"));
      var e = this;
      a &&
        a.scene &&
        (e.setData({ invitationcode: a.scene }),
          t.util.getUserInfo(function (t) {
            wx.setStorageSync("uid", t.memberInfo.uid),
              t.memberInfo ? e.firstin(t.memberInfo) : e.setData({ isShow: !0 });
          })),
        this._list(1),
        this._notice(),
        this._info_set(0);
    },
    changeurl: function (t) {
      let a = {};
      return (
        t.replace(/([^?&]+)=([^?&]+)/g, function (t, e, i) {
          return (a[e] = decodeURIComponent(i)), i + "=" + e;
        }),
        a
      );
    },
    bindRegionChange: function (t) {
      this.setData({ region: t.detail.value }), this._list(2);
    },
    hideDialog: function () {
      this.setData({ isShow: !this.data.isShow });
    },
    updateUserInfo: function (a) {
      var e = this;
      t.util.getUserInfo(function (t) {
        e.hideDialog(), e.firstin(t.memberInfo);
      }, a.detail);
    },
    firstin: function (a) {
      t.util.request({
        url: "entry/wxapp/Api",
        data: {

          r: "me.binding",
          uid: a.uid,
          head_image: a.avatar,
          nickname: a.nickname,
          invitationcode: this.data.invitationcode,
        },
        success: function (t) { },
      });
    },
    _info_set: function () {
      var a = this;
      t.util.request({
        url: "entry/wxapp/Api",
        data: { r: "home.index.info_set" },
        cachetime: "0",
        success: function (t) {
          console.log(t),
            2 == t.data.data.head_flow &&
            "" != t.data.data.head_flow_id &&
            a.setData({ unitid: t.data.data.head_flow_id });
        },
      });
    },
    _notice: function () {
      var a = this;
      t.util.request({
        url: "entry/wxapp/Api",
        data: { r: "home.index.home" },
        cachetime: "0",
        success: function (t) {
          t.data.data.info_name.name && wx.setNavigationBarTitle({ title: t.data.data.info_name.name + "" }),
            1 == t.data.data.info_name.recom && a.is_home(),
            2 == t.data.data.info_name.plate_type && a.setData({ plate_type: 2 }),
            a.setData({
              banner: t.data.data.banner,
              market: t.data.data.market,
              brand: t.data.data.brand,
              textJson: t.data.data.notice,
              info_name: t.data.data.info_name.name,
              recom: t.data.data.info_name.recom,
            });
        },
      });
    },
    ok: function () {
      this.setData({ is_ok: !1 });
    },
    banner: function (a) {
      var e = t.getAttr(a, "id"),
        i = t.getAttr(a, "type");
      console.log(i),
        4 == i ? wx.navigateTo({ url: "/pages/mine/sale/index" }) : 5 == i ? wx.navigateTo({ url: "/pages/enter/enter" }) : 6 == i || (0 != e && wx.navigateTo({
          url: "/pages/home/carMessage/carMessage?id=" + e,
        }));
    },
    market_class: function (a) {
      var e = t.getAttr(a, "active_index"),
        i = !1;
      this.data.active_index == e && ((e = 0), (i = !0)),
        this.setData({
          car_type: this.data.market,
          brand_show: !1,
          sort_show: !1,
          active_index: e,
          show_new: i,
        });
    },
    market_brand: function (t) {
      wx.navigateTo({ url: "../selectscards/index" });
    },
    car_detail: function (a) {
      var e = !1,
        i = t.getAttr(a, "active_index");
      this.data.active_index == i && ((i = 0), (e = !0)),
        this.setData({
          is_ok: !0,
          car_type: this.data.km_arr,
          sort_show: !1,
          show_new: e,
          brand_show: !1,
          active_index: i,
        });
    },
    car_yer: function (a) {
      var e = t.getAttr(a, "active_index");
      this.data.active_index == e && (e = 0),
        this.setData({
          sort_show: !1,
          car_type: this.data.year_arr,
          active_index: e,
          show_new: !1,
          brand_show: !1,
        });
    },
    navto: function (t) {
      console.log(t);
      var a = t.currentTarget.dataset.url;
      wx.navigateTo({ url: a });
    },
    carList: function (a) {
      var e = t.getAttr(a, "name"),
        i = t.getAttr(a, "id");
      if (1 == this.data.active_index)
        (n = {
          fenlei_id: i,
          car_class: e,
          active_index: 1,
          mark: (d = "active_index1"),
          check_name: e,
        }),
          (o = this.data.search_arr.filter(function (t) {
            return t.mark != d;
          })).push(n),
          this.setData({
            car_class: e,
            fenlei_id: i,
            check_name: e,
            search_arr: o,
            leftid: 1,
            show_new: !0,
          });
      else if (2 == this.data.active_index) {
        e = t.getAttr(a, "name");
        var n = {
          pinpai_id: (i = t.getAttr(a, "id")),
          car_brand: e,
          active_index: 2,
          mark: (d = "active_index2"),
          check_name: e,
        };
        (o = this.data.search_arr.filter(function (t) {
          return t.mark != d;
        })).push(n),
          this.setData({
            is_ok: !1,
            car_brand: e,
            pinpai_id: i,
            search_arr: o,
            leftid: 1,
            show_new: !0,
            brand_show: !1,
          });
      } else if (3 == this.data.active_index) {
        var r = t.getAttr(a, "year");
        (n = {
          nianxian_id: (i = t.getAttr(a, "index")),
          car_year: r,
          active_index: 3,
          mark: (d = "active_index3"),
          check_name: r,
        }),
          (o = this.data.search_arr.filter(function (t) {
            return t.mark != d;
          })).push(n),
          this.setData({
            is_ok: !1,
            car_year: r,
            nianxian_id: 1 + parseInt(i),
            search_arr: o,
            leftid: 1,
            show_new: !0,
          });
      } else if (4 == this.data.active_index) {
        var s = t.getAttr(a, "km"),
          d = "active_index4",
          o =
            ((n = {
              km_id: (i = t.getAttr(a, "index")),
              car_km: s,
              active_index: 4,
              mark: d,
              check_name: s,
            }),
              this.data.search_arr.filter(function (t) {
                return t.mark != d;
              }));
        o.push(n),
          this.setData({
            is_ok: !1,
            car_km: s,
            km_id: 1 + parseInt(i),
            search_arr: o,
            leftid: 1,
            show_new: !0,
          });
      }
      this._list(1);
    },
    _list: function (a) {
      var e = this;
      1 == a
        ? this.setData({ carList: [] })
        : 2 == a && this.setData({ carList: [], leftid: 1, show_new: !0 }),
        this.setData({ active_index: 0 }),
        t.util.request({
          url: "entry/wxapp/Api",
          data: {
            r: "home.index.carList",
            fenlei_id: this.data.fenlei_id,
            pinpai_id: this.data.pinpai_id,
            nianxian_id: this.data.nianxian_id,
            km_id: parseInt(this.data.km_id),
            sort_id: this.data.sort_id,
            leftid: this.data.leftid++,
            latitude: this.data.latitude,
            longitude: this.data.longitude,
            province: this.data.region[0],
            city: this.data.region[1],
            district: this.data.region[2],
          },
          cachetime: "0",
          success: function (t) {
            var a;
            t.data.data.length > 0
              ? ((a = e.data.carList).push.apply(
                a,
                (function (t) {
                  if (Array.isArray(t)) {
                    for (var a = 0, e = Array(t.length); a < t.length; a++)
                      e[a] = t[a];
                    return e;
                  }
                  return Array.from(t);
                })(t.data.data)
              ),
                e.setData({ scanReachBottom: !1 }),
                e.setData({ is_ok: !1, carList: e.data.carList }))
              : (e.setData({ scanReachBottom: !0 }), (e.data.show_new = !1));
          },
        });
    },
    clone: function (a) {
      var e = t.getAttr(a, "index"),
        i = this.data.search_arr;
      1 == i[e].active_index
        ? this.setData({ fenlei_id: 0, check_name: "" })
        : 2 == i[e].active_index
          ? this.setData({ pinpai_id: 0, car_brand: "" })
          : 3 == i[e].active_index
            ? (this.setData({ nianxian_id: 0, car_year: "" }),
              (this.data.nianxian_id = 0))
            : 4 == i[e].active_index &&
            (this.setData({ km_id: 0, car_km: "" }), (this.data.km_id = 0)),
        i.splice(e, 1),
        this.setData({ search_arr: i, active_index: 0, leftid: 1 }),
        this._list(2);
    },
    active_nav: function (a) {
      var e = t.getAttr(a, "active_index");
      this.data.active_index != e
        ? this.setData({
          sort_show: !0,
          show_new: !1,
          active_index: e,
          brand_show: !1,
        })
        : this.setData({ sort_show: !1, active_index: 0, show_new: !1 });
    },
    sort_car: function (a) {
      var e = t.getAttr(a, "index");
      if ((this.setData({ sort_show: !1, is_ok: !1 }), 5 == e))
        return this._distanceSort(e), !1;
      this.setData({ sort_id: e }), this._list(2);
    },
    _distanceSort: function (t) {
      var a = this;
      if (
        (a.setData({ active_index: 0 }),
          0 !== a.data.latitude && 0 !== a.data.longitude)
      )
        return a.setData({ sort_id: t }), a._list(2), !1;
      wx.gLn({
        type: "gcj02",
        success: function (e) {
          a.setData({
            latitude: e.latitude,
            longitude: e.longitude,
            sort_id: t,
          }),
            a._list(2);
        },
        fail: function (e) {
          wx.openSetting({
            success: function (e) {
              e.authSetting["scope.userLocation"]
                ? wx.gLn({
                  type: "gcj02",
                  success: function (e) {
                    a.setData({
                      latitude: e.latitude,
                      longitude: e.longitude,
                      sort_id: t,
                    }),
                      a._list(2);
                  },
                })
                : wx.showModal({
                  content: "您未授权获取当前位置无法使用距离排序!",
                  showCancel: !1,
                });
            },
          });
        },
      });
    },
    search: function () {
      wx.navigateTo({ url: "../home/searchShop/searchShop" });
    },
    previewImage: function (a) {
      var e = t.getAttr(a, "src"),
        i = t.getAttr(a, "index"),
        n = [],
        r = !0,
        s = !1,
        d = void 0;
      try {
        for (
          var o, c = this.data.carList[i].image[Symbol.iterator]();
          !(r = (o = c.next()).done);
          r = !0
        ) {
          var _ = o.value;
          n.push(_.img_patch);
        }
      } catch (a) {
        (s = !0), (d = a);
      } finally {
        try {
          !r && c.return && c.return();
        } finally {
          if (s) throw d;
        }
      }
      wx.previewImage({ current: e, urls: n });
    },
    detile: function (a) {
      var e = t.getAttr(a, "id");
      wx.navigateTo({ url: "/pages/home/carMessage/carMessage?id=" + e });
    },
    onReachBottom: function () {
      this.data.show_new && this._list(0);
    },
    onPullDownRefresh: function () {
      var t = this;
      setTimeout(function () {
        wx.stopPullDownRefresh(),
          t.setData({
            is_ok: !1,
            banner: [],
            indicatorDots: !0,
            autoplay: !0,
            interval: 5e3,
            duration: 1e3,
            textJson: [],
            textIndex: 0,
            active_index: 0,
            index: 0,
            fenlei_id: 0,
            pinpai_id: 0,
            nianxian_id: 0,
            km_id: 0,
            sort_id: 0,
            market: [],
            brand: [],
            car_year: "",
            car_brand: "",
            car_km: "",
            car_class: "",
            search_arr: [],
            check_name: "",
            carList: [],
            sort_show: !1,
            leftid: 1,
            show_new: !0,
            brand_show: !1,
          }),
          t.onLoad();
      }, 1500);
    },
    can_1: function () {
      this.setData({
        is_ok: !1,
        sort_show: !1,
        active_index: 0,
        show_new: !0,
        brand_show: !1,
      });
    },
    info_notice: function () {
      wx.navigateTo({ url: "../dting/index" });
    },
    store: function (a) {
      var e = t.getAttr(a, "uid");
      wx.navigateTo({ url: "../store/index?uid=" + e });
    },
    onShareAppMessage: function (t) {
      return {
        title: this.data.info_name + "",
        path: "/pages/index/index",
        success: function (t) { },
        fail: function (t) { },
      };
    },
    is_home: function () {
      var a = this;
      t.util.request({
        url: "entry/wxapp/Api",
        data: { r: "home.index.is_home" },
        cachetime: "0",
        success: function (t) {
          t.data.data.length > 0 && a.setData({ home_arr: t.data.data });
        },
      });
    },
    onShow: function () {
      var t = this;
      if (
        (this.setData({ region: ["", "", ""] }),
          "" != t.data.brandid &&
          "" != t.data.brandname &&
          1 == t.data.brand_status)
      ) {
        var a = t.data.brandname,
          e = t.data.brandid,
          i = "active_index2",
          n = {
            pinpai_id: e,
            car_brand: a,
            active_index: 2,
            mark: i,
            check_name: a,
          },
          r = this.data.search_arr.filter(function (t) {
            return t.mark != i;
          });
        r.push(n),
          this.setData({
            region: [],
            is_ok: !1,
            car_brand: a,
            pinpai_id: e,
            search_arr: r,
            leftid: 1,
            show_new: !0,
            brand_show: !1,
            brandid: 0,
            brandname: "",
          }),
          this._list(1);
      }
    },
  });