var a, t;
(a = getApp()),
  (t = getApp()),
  Page({
    data: {
      tags: [],
      tag_index: 0,
      list: [],
      banner_index: -1,
      page: 1,
      size: 30,
    },
    onLoad: function (a) {
      var e = wx.getStorageSync("orderInfo"),
        t = wx.getStorageSync("cardatawx");
      this.setData({ orderInfo: e, cardatawx: t }),
        this.orderid(),
        this.getmoney();
    },
    onReady: function () {},
    getmoney: function () {
      var a = this,
        e = { type: "weibaoa_money", uid: wx.getStorageSync("uid") };
      t.getdata(e, "getcarmoney").then((e) => {
        console.log("money", e.data),
          e.data &&
            t
              .getdata({ car: a.data.orderInfo.brand }, "wxjlcxmoney")
              .then((t) => {
                console.log("数据库价格", t.data);
                var n = Number(e.data) + Number(t.data.money);
                a.setData({
                  cbfee: Number(e.data),
                  middleAgentList: [
                    {
                      apiRequireLicense: 0,
                      brandAvgTime: "~",
                      isRequireCarNo: 0,
                      isRequireEngineNo: 0,
                      middleAgentUserId: "3837763",
                      orderSucRate: 1,
                      price: n,
                    },
                  ],
                }),
                  a.loadcbs();
              });
      });
    },
    loadcbs: function (e) {
      var t = this;
      a.util.request({
        url: "entry/wxapp/Api",
        data: {

          uid: a.getuid(),
          do: "cbs",
          vin: t.data.cardatawx.vin,
          type: 3,
        },
        success: function (a) {
          if ((console.log("茶博士", a), "1106" == a.data.Code)) {
            t.setData({
              middleAgentList: [
                {
                  apiRequireLicense: 0,
                  brandAvgTime: 0,
                  isRequireCarNo: 0,
                  isRequireEngineNo: 0,
                  middleAgentUserId: 88888,
                  orderSucRate: 1,
                  price: 18,
                },
              ],
            });
            const a = t.data.middleAgentList.length;
            for (let e = 0; e < a; ++e)
              (t.data.middleAgentList[e].price =
                t.data.middleAgentList[e].price + t.data.cbfee),
                t.setData({ middleAgentList: t.data.middleAgentList });
          } else t.loaddsf();
        },
      });
    },
    loaddsf: function (e) {
      var t = this;
      a.util.request({
        url: "entry/wxapp/Api",
        data: {

          uid: a.getuid(),
          do: "cbs",
          vin: t.data.cardatawx.vin,
          type: 1,
        },
        success: function (a) {
          if ((console.log("茶博士", a.data), "0" == a.data.Code)) {
            t.setData({ middleAgentList: a.data.middleAgentList });
            const e = t.data.middleAgentList.length;
            for (let a = 0; a < e; ++a)
              (t.data.middleAgentList[a].price =
                t.data.middleAgentList[a].price + t.data.cbfee),
                t.setData({ middleAgentList: t.data.middleAgentList });
          }
        },
      });
    },
    lower: function () {},
    changeTags: function (t) {
      e.buttonClicked(this);
      var n = t.currentTarget.dataset.index,
        d = this.data.tags[n].tag;
      this.setData({ tag_index: n, tag: d, banner_index: -1 }), a(this);
    },
    changeBanner: function (a) {
      var e = a.currentTarget.dataset.index,
        t = a.currentTarget.dataset.xszid;
      console.log(t),
        this.setData({
          xszid: t,
          banner_index: e,
          middleAgentUserId: a.currentTarget.dataset.midd,
          fee: a.currentTarget.dataset.fee,
        });
    },
    orderid: function () {
      let a = "";
      for (var e = 0; e < 8; e++) a += Math.floor(10 * Math.random());
      (a = "D" + new Date().getTime() + a), this.setData({ orderid: a });
    },
    onShow: function () {
      var a = wx.getStorageSync("cardata");
      console.log("行驶证数据", a),
        console.log("行驶证照片", wx.getStorageSync("xszimgurl")),
        a &&
          this.setData({
            mileage: a.车辆识别代号.words,
            engine: a.发动机号码.words,
            chepai: a.号牌号码.words,
            imageUrl: wx.getStorageSync("xszimgurl"),
          });
    },
    queryVin: function () {
      var e = this;
      if (e.data.middleAgentUserId) {
        if (1 == e.data.xszid && !e.data.imageUrl)
          return (
            t.showToast("渠道要求请上传行驶证"),
            void wx.showModal({
              title: "温馨提示",
              content: "渠道要求请上传行驶证，点确定上传行驶证",
              success: function (a) {
                a.confirm
                  ? wx.navigateTo({ url: "/packageA/pages/xszsb/xszsb?type=1" })
                  : console.log("点击取消回调");
              },
            })
          );
        console.log(wx.getStorageSync("uid")),
          wx.getStorageSync("uid")
            ? (console.log(wx.getStorageSync("uid")),
              a.util.request({
                url: "entry/wxapp/paynum",
                method: "post",
                dataType: "json",
                data: {

                  type: "weibaoa_money",
                  fee: e.data.fee,
                  midd: e.data.middleAgentUserId,
                  car: e.data.orderInfo.brand,
                  vin: e.data.cardatawx.vin,
                  chepai: e.data.cardatawx.chepai,
                  engine: e.data.cardatawx.engine,
                  cpimg: e.data.cardatawx.imageUrl,
                  orderid: e.data.orderid,
                  uid: wx.getStorageSync("uid"),
                  postcardata: JSON.stringify(e.data),
                },
                success: function (t) {
                  t.data && t.data.data && 1e3 == t.data.message
                    ? a.util.request({
                        url: "entry/wxapp/Api",
                        data: {

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

                              uid: wx.getStorageSync("uid"),
                              r: "home.weizhang.paynum",
                              orderid: t.data.data.orderid,
                            },
                            success: function (a) {
                              e.setData({
                                weizhang_num: 1 * e.data.weizhang_num + 10,
                              }),
                                wx.showModal({ content: a.data.message }),
                                e.getDetail();
                            },
                          });
                        },
                      });
                },
              }))
            : wx.showModal({
                title: "温馨提醒",
                content: "使用本功能请先登录后在使用~",
                showCancel: !1,
                success: function (a) {
                  a.confirm && wx.reLaunch({ url: "/pages/mine/index" });
                },
              });
      } else t.showToast("请先选择查询渠道");
    },
    getDetail: function () {
      wx.showModal({
        title: "温馨提醒",
        content:
          "在早上8-下午8点查询结果将在10-30分钟查到，其他时间需要到次日早上统一出结果，不成功自动退款~，点击确定后进入订单列表",
        showCancel: !1,
        success: function (a) {
          a.confirm &&
            wx.reLaunch({ url: "/pages/reporlist/reporlist?type=0" });
        },
      });
    },
    getDetailb: function () {
      var a = this,
        e = {
          uid: wx.getStorageSync("uid"),
          frameno: a.data.orderInfo.vin,
          logo: a.data.orderInfo.logo,
          car: a.data.orderInfo.brand,
          cars: a.data.orderInfo.typeName,
          orderid: a.data.orderid,
          chepai: a.data.cardatawx.chepai,
          engine: a.data.cardatawx.engine,
          xszimg: a.data.cardatawx.imageUrl,
          money: a.data.fee,
          fee: a.data.fee,
          midd: a.data.middleAgentUserId,
          vin: a.data.cardatawx.vin,
        };
      t.getdata(e, "wxjlcxcbs").then((e) => {
        console.log("回调数据：", e.data),
          wx.showModal({
            title: "查询成功",
            content:
              "在早上8-下午8点查询结果将在10-30分钟查到，其他时间需要到次日早上统一出结果，不成功自动退款~",
            showCancel: !1,
            success: function (a) {
              a.confirm &&
                wx.reLaunch({ url: "/pages/reporlist/reporlist?type=0" });
            },
          }),
          e.data && a.setData({ order: e.data });
      });
    },
    queryVinb: function () {
      var a = this.data.orderInfo.seriousNo,
        t = this.data.orderInfo.queryType,
        n = this.data.orderInfo.name;
      console.log("queryType:" + t),
        e.default
          .wxPay({
            seriousNo: a,
            openId: wx.getStorageSync("openId"),
            money: this.data.orderInfo.money,
          })
          .then(function (e) {
            wx.requestPayment({
              timeStamp: e.data.timeStamp,
              nonceStr: e.data.nonceStr,
              package: e.data.package,
              signType: e.data.signType,
              paySign: e.data.sign,
              success: function (e) {
                wx.navigateTo({
                  url:
                    "/pages/successPage/successPage?seriousNo=" +
                    a +
                    "&queryType=" +
                    t +
                    "&name=" +
                    n,
                });
              },
              fail: function (a) {
                console.log(a);
              },
            });
          });
    },
    toDisclaimers: function () {
      wx.navigateTo({ url: "/pages/disclaimers/disclaimers" });
    },
  });
