index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. if (!Array) {
  4. const _easycom_up_tabs2 = common_vendor.resolveComponent("up-tabs");
  5. const _easycom_up_empty2 = common_vendor.resolveComponent("up-empty");
  6. const _easycom_up_overlay2 = common_vendor.resolveComponent("up-overlay");
  7. (_easycom_up_tabs2 + _easycom_up_empty2 + _easycom_up_overlay2)();
  8. }
  9. const _easycom_up_tabs = () => "../../node-modules/uview-plus/components/u-tabs/u-tabs.js";
  10. const _easycom_up_empty = () => "../../node-modules/uview-plus/components/u-empty/u-empty.js";
  11. const _easycom_up_overlay = () => "../../node-modules/uview-plus/components/u-overlay/u-overlay.js";
  12. if (!Math) {
  13. (_easycom_up_tabs + _easycom_up_empty + login + _easycom_up_overlay)();
  14. }
  15. const login = () => "../../components/login.js";
  16. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  17. __name: "index",
  18. setup(__props) {
  19. const $api = common_vendor.inject("$api");
  20. const config = common_vendor.ref({ logo: [], file: [] });
  21. const active = common_vendor.ref(0);
  22. const type = common_vendor.ref("");
  23. const subject = common_vendor.ref("-1");
  24. const grade = common_vendor.ref("-1");
  25. const list = common_vendor.ref([]);
  26. const total = common_vendor.ref(0);
  27. const skip = common_vendor.ref(0);
  28. const limit = common_vendor.ref(5);
  29. const page = common_vendor.ref(0);
  30. const is_bottom = common_vendor.ref(false);
  31. const scrollTop = common_vendor.ref(0);
  32. const show = common_vendor.ref(false);
  33. const nick_name = common_vendor.ref("");
  34. const subjectList = common_vendor.ref([]);
  35. const gradeList = common_vendor.ref([]);
  36. const user = common_vendor.computed(() => {
  37. return common_vendor.index.getStorageSync("user");
  38. });
  39. common_vendor.onLoad(async (options) => {
  40. type.value = options && options.type;
  41. common_vendor.index.setNavigationBarTitle({
  42. title: options && options.name + "课程" || "课程"
  43. });
  44. });
  45. common_vendor.onShow(async () => {
  46. await searchConfig();
  47. await searchOther();
  48. await clearPage();
  49. await search();
  50. if (!user.value)
  51. show.value = true;
  52. });
  53. common_vendor.onPullDownRefresh(async () => {
  54. await clearPage();
  55. await search();
  56. common_vendor.index.stopPullDownRefresh();
  57. });
  58. const searchConfig = async () => {
  59. config.value = common_vendor.index.getStorageSync("config");
  60. };
  61. const searchOther = async () => {
  62. let res;
  63. res = await $api(`dictData`, "GET", { code: "subject", is_use: "0" });
  64. if (res.errcode === 0)
  65. subjectList.value = res.data;
  66. subjectList.value.unshift({ label: "全部", value: "-1" });
  67. res = await $api(`dictData`, "GET", { code: "grade", is_use: "0" });
  68. if (res.errcode === 0)
  69. gradeList.value = res.data;
  70. gradeList.value.unshift({ label: "全部", value: "-1" });
  71. };
  72. const searchInfo = async () => {
  73. await clearPage();
  74. await search();
  75. };
  76. const search = async () => {
  77. const info = {
  78. skip: skip.value,
  79. limit: limit.value,
  80. status: "1",
  81. is_show: "0",
  82. type: type.value
  83. };
  84. if (nick_name.value)
  85. info.name = nick_name.value;
  86. if (subject.value && subject.value !== "-1")
  87. info.subject = subject.value;
  88. if (grade.value && grade.value !== "-1")
  89. info.grade = grade.value;
  90. const res = await $api("course/appHome", "GET", info);
  91. if (res.errcode === 0) {
  92. list.value = list.value.concat(res.data);
  93. total.value = res.total;
  94. } else {
  95. common_vendor.index.showToast({
  96. title: res.errmsg || "",
  97. icon: "error"
  98. });
  99. }
  100. };
  101. const showChange = () => {
  102. show.value = false;
  103. };
  104. const toChange = async (index, e) => {
  105. console.log(index, e);
  106. active.value = index;
  107. subject.value = e.value;
  108. await clearPage();
  109. await search();
  110. };
  111. const toTab = async (data) => {
  112. grade.value = data.value;
  113. await clearPage();
  114. await search();
  115. };
  116. const toPage = () => {
  117. if (total.value > list.value.length) {
  118. common_vendor.index.showLoading({
  119. title: "加载中",
  120. mask: true
  121. });
  122. page.value = page.value + 1;
  123. skip.value = page.value * limit.value;
  124. search();
  125. common_vendor.index.hideLoading();
  126. } else
  127. is_bottom.value = true;
  128. };
  129. const toScroll = (e) => {
  130. let up = scrollTop.value;
  131. scrollTop.value = e.detail.scrollTop;
  132. let num = Math.sign(up - e.detail.scrollTop);
  133. if (num == 1)
  134. is_bottom.value = false;
  135. };
  136. const clearPage = () => {
  137. list.value = [];
  138. skip.value = 0;
  139. limit.value = 6;
  140. page.value = 0;
  141. };
  142. return (_ctx, _cache) => {
  143. return common_vendor.e({
  144. a: nick_name.value,
  145. b: common_vendor.o(($event) => nick_name.value = $event.detail.value),
  146. c: common_vendor.o(searchInfo),
  147. d: common_vendor.f(subjectList.value, (item, index, i0) => {
  148. return {
  149. a: common_vendor.t(item.label),
  150. b: common_vendor.n(active.value == index ? "listActive" : ""),
  151. c: index,
  152. d: common_vendor.o(($event) => toChange(index, item), index)
  153. };
  154. }),
  155. e: common_vendor.o(toTab),
  156. f: common_vendor.p({
  157. list: gradeList.value,
  158. keyName: "label"
  159. }),
  160. g: total.value > 0
  161. }, total.value > 0 ? common_vendor.e({
  162. h: common_vendor.f(list.value, (item, index, i0) => {
  163. return common_vendor.e({
  164. a: item.icon && item.icon.length > 0 && item.icon
  165. }, item.icon && item.icon.length > 0 && item.icon ? {
  166. b: item.icon[0].url
  167. } : {
  168. c: config.value.icon[0].url
  169. }, {
  170. d: common_vendor.t(item.name || "暂无"),
  171. e: common_vendor.t(item.teacher_name || "暂无"),
  172. f: common_vendor.t(item.start_time || "休息中"),
  173. g: common_vendor.t(item.money || "免费"),
  174. h: common_vendor.o(($event) => _ctx.toBuy(item), index),
  175. i: index,
  176. j: common_vendor.o(($event) => _ctx.toBuy(_ctx.tag), index)
  177. });
  178. }),
  179. i: is_bottom.value
  180. }, is_bottom.value ? {
  181. j: common_vendor.t(config.value.bottom_title)
  182. } : {}, {
  183. k: common_vendor.o(toPage),
  184. l: common_vendor.o(toScroll)
  185. }) : {
  186. m: common_vendor.p({
  187. mode: "list",
  188. icon: "/static/list.png"
  189. })
  190. }, {
  191. n: common_vendor.o(showChange),
  192. o: common_vendor.p({
  193. show: show.value
  194. })
  195. });
  196. };
  197. }
  198. });
  199. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-db68cfa6"], ["__file", "D:/project/学吧/learn_applet/pagesHome/list/index.vue"]]);
  200. wx.createPage(MiniProgramPage);