"use strict";
const common_vendor = require("../../common/vendor.js");
if (!Array) {
  const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  const _easycom_u_form_item2 = common_vendor.resolveComponent("u-form-item");
  const _easycom_u__form2 = common_vendor.resolveComponent("u--form");
  (_easycom_u_icon2 + _easycom_u_form_item2 + _easycom_u__form2)();
}
const _easycom_u_icon = () => "../../node-modules/uview-plus/components/u-icon/u-icon.js";
const _easycom_u_form_item = () => "../../node-modules/uview-plus/components/u-form-item/u-form-item.js";
const _easycom_u__form = () => "../../node-modules/uview-plus/components/u-form/u-form.js";
if (!Math) {
  (_easycom_u_icon + _easycom_u_form_item + _easycom_u__form)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  setup(__props) {
    var _a, _b;
    const $api = (_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.appContext.config.globalProperties.$api;
    (_b = common_vendor.getCurrentInstance()) == null ? void 0 : _b.appContext.config.globalProperties.$config;
    const config = common_vendor.ref({});
    const agree = common_vendor.ref(false);
    common_vendor.ref({});
    const form = common_vendor.ref({ brand: "", bank: "", type: "", start: "", course: "", place: "", city: "", tel: "" });
    const rules = {
      "bank": {
        type: "string",
        required: true,
        message: "请输入车辆车系",
        trigger: ["blur", "change"]
      },
      "type": {
        type: "string",
        required: true,
        message: "请输入车辆车型",
        trigger: ["blur", "change"]
      },
      "start": {
        type: "string",
        required: true,
        message: "请选择上牌日期",
        trigger: ["blur", "change"]
      },
      "course": {
        type: "string",
        required: true,
        message: "请选择行驶里程",
        trigger: ["blur", "change"]
      },
      "tel": {
        type: "string",
        required: true,
        message: "请输入手机号",
        trigger: ["blur", "change"]
      }
    };
    const uForm = common_vendor.ref(null);
    const openid = common_vendor.computed(() => {
      return common_vendor.index.getStorageSync("openid");
    });
    const courseList = common_vendor.ref([{ value: "1", label: "1万公里" }, { value: "2", label: "2万公里" }, { value: "3", label: "3万公里" }, { value: "4", label: "4万公里" }, { value: "5", label: "5万公里" }]);
    common_vendor.onLoad(async () => {
      await searchConfig();
    });
    common_vendor.onShow(() => {
      common_vendor.index.$on("toRoute", function(data) {
        form.value.brand = data.name;
      });
      common_vendor.index.$on("toCity", function(data) {
        form.value[data.field] = data.name;
      });
    });
    const searchConfig = async () => {
      config.value = common_vendor.index.getStorageSync("config");
    };
    const dateChange = (e) => {
      form.value.start = e.target.value;
    };
    const courseChange = (e) => {
      const data = courseList.value[e.detail.value];
      if (data)
        form.value.course = data.label;
    };
    const toCity = () => {
      common_vendor.index.navigateTo({
        url: `/pagesHome/city/index?field=${"city"}`
      });
    };
    const toPlace = () => {
      common_vendor.index.navigateTo({
        url: `/pagesHome/city/index?field=${"place"}`
      });
    };
    const toSelect = () => {
      common_vendor.index.navigateTo({
        url: `/pagesHome/brand/index`
      });
    };
    const toEvaluate = async () => {
      if (agree.value) {
        if (openid.value) {
          uForm.value.validate().then(async (res) => {
            if (form.value.place || form.value.city) {
              form.value.openid = openid.value;
              const res2 = await $api(`estimate`, "POST", form.value);
              if (res2.errcode == 0) {
                common_vendor.index.showToast({
                  title: "免费估价申请成功",
                  icon: "none"
                });
                common_vendor.index.navigateBack({
                  delta: 1
                });
              } else {
                common_vendor.index.showToast({
                  title: res2.errmsg,
                  icon: "none"
                });
              }
            } else {
              common_vendor.index.showToast({
                title: "缺少城市信息",
                icon: "none"
              });
            }
          }).catch((err) => {
            console.log(err, "校验失败");
          });
        } else {
          common_vendor.index.showToast({
            title: "系统更新中，请稍后再试!",
            icon: "none"
          });
        }
      } else {
        common_vendor.index.showToast({
          title: "请阅读并同意用户协议和隐私政策",
          icon: "none"
        });
      }
    };
    const toAgree = () => {
      common_vendor.index.navigateTo({
        url: `/pagesHome/agree/index`
      });
    };
    const changeAgree = () => {
      agree.value = !agree.value;
    };
    return (_ctx, _cache) => {
      var _a2, _b2, _c, _d, _e;
      return common_vendor.e({
        a: !form.value.brand && !((_a2 = form.value.brand) == null ? void 0 : _a2.title)
      }, !form.value.brand && !((_b2 = form.value.brand) == null ? void 0 : _b2.title) ? {
        b: common_vendor.p({
          name: "plus-circle-fill",
          size: "20",
          color: "#2979ff"
        }),
        c: common_vendor.o(toSelect)
      } : {
        d: ((_c = form.value.brand) == null ? void 0 : _c.url) && ((_d = form.value.brand) == null ? void 0 : _d.url.length) > 0 ? (_e = form.value.brand) == null ? void 0 : _e.url[0].url : "/static/logo.png",
        e: common_vendor.t(form.value.brand),
        f: common_vendor.p({
          name: "arrow-right"
        }),
        g: common_vendor.o(toSelect)
      }, {
        h: form.value.bank,
        i: common_vendor.o(($event) => form.value.bank = $event.detail.value),
        j: common_vendor.p({
          name: "arrow-right"
        }),
        k: common_vendor.p({
          label: "车辆车系",
          prop: "bank"
        }),
        l: form.value.type,
        m: common_vendor.o(($event) => form.value.type = $event.detail.value),
        n: common_vendor.p({
          name: "arrow-right"
        }),
        o: common_vendor.p({
          label: "车辆车型",
          prop: "type"
        }),
        p: common_vendor.t(form.value.start || "请选择"),
        q: common_vendor.o(dateChange),
        r: common_vendor.p({
          name: "arrow-right"
        }),
        s: common_vendor.p({
          label: "上牌日期",
          prop: "start"
        }),
        t: common_vendor.t(form.value.course || "请选择"),
        v: common_vendor.o(courseChange),
        w: _ctx.index,
        x: courseList.value,
        y: common_vendor.p({
          name: "arrow-right"
        }),
        z: common_vendor.p({
          label: "行驶里程",
          prop: "course"
        }),
        A: common_vendor.t(form.value.city || "请选择"),
        B: common_vendor.o(toCity),
        C: common_vendor.p({
          name: "arrow-right"
        }),
        D: common_vendor.p({
          label: "上牌城市",
          prop: "city"
        }),
        E: common_vendor.t(form.value.place || "请选择"),
        F: common_vendor.o(toPlace),
        G: common_vendor.p({
          name: "arrow-right"
        }),
        H: common_vendor.p({
          label: "估值地区",
          prop: "place"
        }),
        I: form.value.contacts,
        J: common_vendor.o(($event) => form.value.contacts = $event.detail.value),
        K: common_vendor.p({
          label: "联系人",
          prop: "contacts"
        }),
        L: form.value.tel,
        M: common_vendor.o(($event) => form.value.tel = $event.detail.value),
        N: common_vendor.p({
          label: "联系电话",
          prop: "tel"
        }),
        O: common_vendor.sr(uForm, "1d378803-2", {
          "k": "uForm"
        }),
        P: common_vendor.p({
          model: form.value,
          rules,
          labelWidth: "65",
          ["border-bottom"]: true
        }),
        Q: common_vendor.o(toEvaluate),
        R: agree.value,
        S: common_vendor.o(toAgree),
        T: common_vendor.o(changeAgree)
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1d378803"], ["__file", "D:/project/赋强公证/notarization_applet/pagesHome/sell/index.vue"]]);
wx.createPage(MiniProgramPage);
