var t;
(t = getApp()),
  Page({
    data: {
      isShow: !1,
      buttscan: !1,
      date: "请选择时间",
      address: "",
      cartype: "",
      licheng: "",
      userphone: "",
      carsimgs: [],
    },
    release: function (e) {
      var a = this,
        i = wx.getStorageSync("uid");
      if (i) {
        if (!a.data.buttscan) {
          a.setData({ buttscan: !0 });
          var s = e.detail.value.address;
          if ("" == s || "undefined" == s || "请输入卖车地点" == s)
            return (
              t.util.message({ title: "请输入卖车地点", type: "error" }),
              void a.setData({ buttscan: !1 })
            );
          var n = e.detail.value.cartype;
          if ("" == n || "undefined" == n || "请输入品牌车型" == n)
            return (
              t.util.message({ title: "请输入品牌车型", type: "error" }),
              void a.setData({ buttscan: !1 })
            );
          var r = a.data.date;
          if ("请选择时间" == r || "undefined" == r || "" == r)
            return (
              t.util.message({ title: "请选择上牌时间", type: "error" }),
              void a.setData({ buttscan: !1 })
            );
          var o = e.detail.value.licheng;
          if ("" == o || "undefined" == o || "请输入行驶里程" == o)
            return (
              t.util.message({ title: "请输入行驶里程", type: "error" }),
              void a.setData({ buttscan: !1 })
            );
          var u = e.detail.value.phone;
          if ("" == u || "undefined" == u)
            return (
              t.util.message({
                title: "请填写联系电话，或点击电话授权",
                type: "error",
              }),
              void a.setData({ buttscan: !1 })
            );
          var c = a.data.carsimgs;
          if (c.length < 1)
            return (
              t.util.message({ title: "请至少添加1个车辆图片", type: "error" }),
              void a.setData({ buttscan: !1 })
            );
          var d = [];
          for (var l in c)
            "" != c[l].imgshort &&
              "" != c[l].img &&
              (console.log(c[l]), console.log(c[l].imgshort), d.push(c[l]));
          var g = {
            r: "sale.index.ingujia",

            fomid: e.detail.formId,
            uid: i,
            address: s,
            topdate: r,
            cartype: n,
            phone: u,
            licheng: o,
            carimages: d,
          };
          t.util.request({
            url: "entry/wxapp/Api",
            data: g,
            cachetime: "0",
            success: function (t) {
              200 == t.data.message
                ? (wx.showToast({
                    title: "提交成功",
                    icon: "success",
                    duration: 2e3,
                  }),
                  a.setData({ buttscan: !1 }))
                : (console.log(t.data),
                  wx.showToast({
                    title: "提交失败请稍后再试",
                    icon: "none",
                    duration: 2e3,
                  }),
                  a.setData({ buttscan: !1 }));
            },
            fail: function (t) {
              a.setData({ buttscan: !1 });
            },
          });
        }
      } else a.setData({ isShow: !0 });
    },
    getPhoneNumber: function (e) {
      console.log(e);
      var a = this;
      t.util.request({
        url: "entry/wxapp/Api",
        data: {
          r: "sale.index.userphone",

          iv: e.detail.iv,
          encryptedData: e.detail.encryptedData,
        },
        cachetime: "0",
        success: function (t) {
          a.setData({ userphone: t.data.data });
        },
      });
    },
    upcarsimgs: function (e) {
      var a = this;
      a.data.carsimgs.length >= 3
        ? t.util.message({ title: "您添加的图片已经很多了", type: "error" })
        : t.upimgs({
            scannums: 3,
            filename: "cars",
            success: function (t) {
              for (var e in t) a.addinimgs(t[e]);
            },
          });
    },
    addinimgs: function (t) {
      var e = this.data.carsimgs,
        a = { img: t.all, imgshort: t.short };
      e.push(a), this.setData({ carsimgs: e });
    },
    showimgs: function (t) {
      var e = t.currentTarget.dataset.index,
        a = this.data.carsimgs;
      wx.previewImage({ current: a[e].img, urls: [a[e].img] });
    },
    upthiscarsimgs: function (e) {
      var a = e.currentTarget.dataset.index,
        i = this.data.carsimgs;
      t.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_sharing",
          uid: t.getuid(),
          imgurl: i[a].img,
          r: "Upimg.delImg",
        },
      }),
        i.splice(a, 1),
        this.setData({ carsimgs: i });
    },
    onLoad: function (t) {},
    bindDateChange: function (t) {
      console.log("picker发送选择改变，携带值为", t.detail.value),
        this.setData({ date: t.detail.value });
    },
    onReady: function () {},
    onShow: function () {},
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    onShareAppMessage: function () {},
  });
