"use strict";
const common_vendor = require("../../common/vendor.js");
if (!Array) {
  const _easycom_up_list_item2 = common_vendor.resolveComponent("up-list-item");
  const _easycom_up_list2 = common_vendor.resolveComponent("up-list");
  const _easycom_up_empty2 = common_vendor.resolveComponent("up-empty");
  const _easycom_up_overlay2 = common_vendor.resolveComponent("up-overlay");
  (_easycom_up_list_item2 + _easycom_up_list2 + _easycom_up_empty2 + _easycom_up_overlay2)();
}
const _easycom_up_list_item = () => "../../node-modules/uview-plus/components/u-list-item/u-list-item.js";
const _easycom_up_list = () => "../../node-modules/uview-plus/components/u-list/u-list.js";
const _easycom_up_empty = () => "../../node-modules/uview-plus/components/u-empty/u-empty.js";
const _easycom_up_overlay = () => "../../node-modules/uview-plus/components/u-overlay/u-overlay.js";
if (!Math) {
  (_easycom_up_list_item + _easycom_up_list + _easycom_up_empty + login + _easycom_up_overlay)();
}
const login = () => "../../components/login.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  setup(__props) {
    const $api = common_vendor.inject("$api");
    const config = common_vendor.ref({ logo: [], file: [] });
    const list = common_vendor.ref([]);
    const total = common_vendor.ref(0);
    const skip = common_vendor.ref(0);
    const limit = common_vendor.ref(5);
    const page = common_vendor.ref(0);
    const is_bottom = common_vendor.ref(false);
    const show = common_vendor.ref(false);
    const educationList = common_vendor.ref([]);
    const nick_name = common_vendor.ref("");
    const user = common_vendor.computed(() => {
      return common_vendor.index.getStorageSync("user");
    });
    common_vendor.onShow(async () => {
      await searchConfig();
      await searchOther();
      await clearPage();
      await search();
      if (!user.value)
        show.value = true;
    });
    common_vendor.onPullDownRefresh(async () => {
      await clearPage();
      await search();
      common_vendor.index.stopPullDownRefresh();
    });
    const searchConfig = async () => {
      config.value = common_vendor.index.getStorageSync("config");
    };
    const searchOther = async () => {
      let res;
      res = await $api(`dictData`, "GET", { code: "education", is_use: "0" });
      if (res.errcode === 0)
        educationList.value = res.data;
    };
    const searchInfo = async () => {
      await clearPage();
      await search();
    };
    const search = async () => {
      const info = {
        skip: skip.value,
        limit: limit.value,
        status: "1",
        is_show: "0"
      };
      if (nick_name.value)
        info.nick_name = nick_name.value;
      const res = await $api("teacher", "GET", info);
      if (res.errcode === 0) {
        list.value = list.value.concat(res.data);
        total.value = res.total;
      } else {
        common_vendor.index.showToast({
          title: res.errmsg || "",
          icon: "error"
        });
      }
    };
    const showChange = () => {
      show.value = false;
    };
    const getDict = (data, model) => {
      let res;
      if (model == "education")
        res = educationList.value.find((f) => f.value == data);
      return res.label || "暂无";
    };
    const toBuy = (item) => {
      common_vendor.index.navigateTo({
        url: `/pagesHome/teacher/index?id=${item._id}`
      });
    };
    const scrolltolower = () => {
      if (total.value > list.value.length) {
        common_vendor.index.showLoading({
          title: "加载中",
          mask: true
        });
        page.value = page.value + 1;
        skip.value = page.value * limit.value;
        search();
        common_vendor.index.hideLoading();
      } else
        is_bottom.value = true;
    };
    const clearPage = () => {
      list.value = [];
      skip.value = 0;
      limit.value = 6;
      page.value = 0;
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: nick_name.value,
        b: common_vendor.o(($event) => nick_name.value = $event.detail.value),
        c: common_vendor.o(searchInfo),
        d: total.value > 0
      }, total.value > 0 ? {
        e: common_vendor.f(list.value, (item, index, i0) => {
          return common_vendor.e({
            a: item.icon && item.icon.length > 0 && item.icon
          }, item.icon && item.icon.length > 0 && item.icon ? {
            b: item.icon[0].url
          } : {
            c: config.value.icon[0].url
          }, {
            d: common_vendor.t(item.nick_name || "暂无昵称"),
            e: common_vendor.t(item.time || "休息中"),
            f: common_vendor.t(item.college || "暂无"),
            g: common_vendor.t(getDict(item.education, "education")),
            h: common_vendor.t(item.money || "免费"),
            i: common_vendor.o(($event) => toBuy(item), index),
            j: index,
            k: "f3506c63-1-" + i0 + ",f3506c63-0"
          });
        }),
        f: common_vendor.o(scrolltolower)
      } : {
        g: common_vendor.p({
          mode: "list",
          icon: "/static/list.png"
        })
      }, {
        h: is_bottom.value
      }, is_bottom.value ? {
        i: common_vendor.t(config.value.bottom_title || "没有更多了！")
      } : {}, {
        j: common_vendor.o(showChange),
        k: common_vendor.p({
          show: show.value
        })
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f3506c63"], ["__file", "D:/project/学吧/learn_applet/pages/teacher/index.vue"]]);
wx.createPage(MiniProgramPage);
