index.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. if (!Array) {
  4. const _easycom_up_list_item2 = common_vendor.resolveComponent("up-list-item");
  5. const _easycom_up_list2 = common_vendor.resolveComponent("up-list");
  6. const _easycom_up_empty2 = common_vendor.resolveComponent("up-empty");
  7. (_easycom_up_list_item2 + _easycom_up_list2 + _easycom_up_empty2)();
  8. }
  9. const _easycom_up_list_item = () => "../../node-modules/uview-plus/components/u-list-item/u-list-item.js";
  10. const _easycom_up_list = () => "../../node-modules/uview-plus/components/u-list/u-list.js";
  11. const _easycom_up_empty = () => "../../node-modules/uview-plus/components/u-empty/u-empty.js";
  12. if (!Math) {
  13. (_easycom_up_list_item + _easycom_up_list + _easycom_up_empty)();
  14. }
  15. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  16. __name: "index",
  17. setup(__props) {
  18. const $api = common_vendor.inject("$api");
  19. const config = common_vendor.ref({ logo: [], file: [] });
  20. const list = common_vendor.ref([]);
  21. const total = common_vendor.ref(0);
  22. const skip = common_vendor.ref(0);
  23. const limit = common_vendor.ref(5);
  24. const page = common_vendor.ref(0);
  25. const is_bottom = common_vendor.ref(false);
  26. const name = common_vendor.ref("");
  27. const subjectList = common_vendor.ref([]);
  28. const gradeList = common_vendor.ref([]);
  29. const showList = common_vendor.ref([]);
  30. const typeList = common_vendor.ref([]);
  31. const statusList = common_vendor.ref([]);
  32. const user = common_vendor.computed(() => {
  33. return common_vendor.index.getStorageSync("user");
  34. });
  35. common_vendor.onShow(async () => {
  36. await searchConfig();
  37. await searchOther();
  38. await clearPage();
  39. await search();
  40. });
  41. common_vendor.onPullDownRefresh(async () => {
  42. await clearPage();
  43. await search();
  44. common_vendor.index.stopPullDownRefresh();
  45. });
  46. const searchConfig = async () => {
  47. config.value = common_vendor.index.getStorageSync("config");
  48. };
  49. const searchOther = async () => {
  50. let res;
  51. res = await $api(`dictData`, "GET", { code: "subject", is_use: "0" });
  52. if (res.errcode === 0)
  53. subjectList.value = res.data;
  54. res = await $api(`dictData`, "GET", { code: "grade", is_use: "0" });
  55. if (res.errcode === 0)
  56. gradeList.value = res.data;
  57. res = await $api(`dictData`, "GET", { code: "courseType", is_use: "0" });
  58. if (res.errcode === 0)
  59. typeList.value = res.data;
  60. res = await $api(`dictData`, "GET", { code: "courseStatus", is_use: "0" });
  61. if (res.errcode === 0)
  62. statusList.value = res.data;
  63. res = await $api(`dictData`, "GET", { code: "show", is_use: "0" });
  64. if (res.errcode === 0)
  65. showList.value = res.data;
  66. };
  67. const search = async () => {
  68. const info = {
  69. skip: skip.value,
  70. limit: limit.value,
  71. teacher: user.value._id,
  72. is_show: "0"
  73. };
  74. if (name.value)
  75. info.name = name.value;
  76. const res = await $api("course", "GET", info);
  77. if (res.errcode === 0) {
  78. list.value = list.value.concat(res.data);
  79. total.value = res.total;
  80. } else {
  81. common_vendor.index.showToast({
  82. title: res.errmsg || "",
  83. icon: "error"
  84. });
  85. }
  86. };
  87. const getDict = (data, model) => {
  88. let res;
  89. if (model == "subject")
  90. res = subjectList.value.find((f) => f.value == data);
  91. else if (model == "grade")
  92. res = gradeList.value.find((f) => f.value == data);
  93. else if (model == "type")
  94. res = typeList.value.find((f) => f.value == data);
  95. else if (model == "status")
  96. res = statusList.value.find((f) => f.value == data);
  97. return res.label || "暂无";
  98. };
  99. const toInput = async (e2) => {
  100. await clearPage();
  101. await search();
  102. };
  103. const toAdd = async () => {
  104. common_vendor.index.navigateTo({
  105. url: `/pagesMy/course/add`
  106. });
  107. };
  108. const toEdit = async (item) => {
  109. common_vendor.index.navigateTo({
  110. url: `/pagesMy/course/add?id=${item.id || item._id}`
  111. });
  112. };
  113. const toDelete = async () => {
  114. common_vendor.index.showModal({
  115. title: "提示",
  116. content: "确定删除该课程吗?",
  117. success: async function(res) {
  118. if (res.confirm) {
  119. const arr = await $api(`course/${e._id}`, "DELETE");
  120. if (arr.errcode == "0") {
  121. common_vendor.index.showToast({
  122. title: "删除信息成功",
  123. icon: "none"
  124. });
  125. await clearPage();
  126. await search();
  127. } else {
  128. common_vendor.index.showToast({
  129. title: arr.errmsg,
  130. icon: "none"
  131. });
  132. }
  133. }
  134. }
  135. });
  136. };
  137. const scrolltolower = () => {
  138. if (total.value > list.value.length) {
  139. common_vendor.index.showLoading({
  140. title: "加载中",
  141. mask: true
  142. });
  143. page.value = page.value + 1;
  144. skip.value = page.value * limit.value;
  145. search();
  146. common_vendor.index.hideLoading();
  147. } else
  148. is_bottom.value = true;
  149. };
  150. const clearPage = () => {
  151. list.value = [];
  152. skip.value = 0;
  153. limit.value = 6;
  154. page.value = 0;
  155. };
  156. return (_ctx, _cache) => {
  157. return common_vendor.e({
  158. a: common_vendor.o([($event) => name.value = $event.detail.value, toInput]),
  159. b: name.value,
  160. c: common_vendor.o(toAdd),
  161. d: total.value > 0
  162. }, total.value > 0 ? {
  163. e: common_vendor.f(list.value, (item, index, i0) => {
  164. return common_vendor.e({
  165. a: common_vendor.t(item.name || "暂无"),
  166. b: common_vendor.t(getDict(item.type, "type")),
  167. c: common_vendor.t(getDict(item.subject, "subject")),
  168. d: common_vendor.t(getDict(item.grade, "grade")),
  169. e: common_vendor.t(item.money || "免费"),
  170. f: common_vendor.t(item.start_time),
  171. g: common_vendor.t(item.end_time),
  172. h: common_vendor.t(getDict(item.status, "status")),
  173. i: common_vendor.n(item.status == "0" ? "red" : ""),
  174. j: common_vendor.o(($event) => toEdit(item), index),
  175. k: item.status == "0"
  176. }, item.status == "0" ? {
  177. l: common_vendor.o(($event) => toDelete(), index)
  178. } : {}, {
  179. m: index,
  180. n: "5cb065a7-1-" + i0 + ",5cb065a7-0"
  181. });
  182. }),
  183. f: common_vendor.o(scrolltolower)
  184. } : {
  185. g: common_vendor.p({
  186. mode: "list",
  187. icon: "/static/list.png"
  188. })
  189. }, {
  190. h: is_bottom.value
  191. }, is_bottom.value ? {
  192. i: common_vendor.t(config.value.bottom_title || "没有更多了!")
  193. } : {});
  194. };
  195. }
  196. });
  197. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-5cb065a7"], ["__file", "D:/project/学吧/learn_applet/pagesMy/course/index.vue"]]);
  198. wx.createPage(MiniProgramPage);