index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  4. __name: "index",
  5. setup(__props) {
  6. var _a;
  7. const $api = (_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.appContext.config.globalProperties.$api;
  8. const user = common_vendor.ref({});
  9. const config = common_vendor.ref({ bottomTitle: "", logoUrl: "" });
  10. const searchInfo = common_vendor.ref({ name: "" });
  11. const list = common_vendor.ref([{ id: 1, name: "测试球队" }, { id: 1, name: "肝帝集团队" }]);
  12. const pageNum = common_vendor.ref(1);
  13. const pageSize = common_vendor.ref(10);
  14. const total = common_vendor.ref(0);
  15. const statusList = common_vendor.ref([]);
  16. const scrollTop = common_vendor.ref(0);
  17. const is_bottom = common_vendor.ref(false);
  18. common_vendor.onShow(async () => {
  19. await searchUser();
  20. await searchConfig();
  21. await search();
  22. });
  23. const searchUser = async () => {
  24. user.value = common_vendor.index.getStorageSync("user");
  25. let res;
  26. res = await $api(`dict/data/list`, "GET", { dictType: "sys_game_status", status: "0" });
  27. if (res.code === 200 && res.total > 0)
  28. statusList.value = res.rows;
  29. };
  30. const searchConfig = async () => {
  31. config.value = common_vendor.index.getStorageSync("config");
  32. };
  33. const search = async () => {
  34. const info = {
  35. pageNum: pageNum.value,
  36. pageSize: pageSize.value,
  37. userId: user.value.id
  38. };
  39. const res = await $api("game/list", "GET", {
  40. ...info,
  41. ...searchInfo.value
  42. });
  43. if (res.code === 200) {
  44. list.value = res.rows;
  45. total.value = res.total;
  46. } else {
  47. common_vendor.index.showToast({
  48. title: res.msg || "",
  49. icon: "error"
  50. });
  51. }
  52. };
  53. const toInput = (e) => {
  54. if (searchInfo.value.name)
  55. searchInfo.value.name = e.detail.value;
  56. searchInfo.value = { name: "" };
  57. clearPage();
  58. search();
  59. };
  60. const toInfo = (item) => {
  61. common_vendor.index.navigateTo({
  62. url: `/pagesHome/activity/info?id=${item._id || item.id}&name=${item.name || ""}`
  63. });
  64. };
  65. const getDayOfWeek = (dateString) => {
  66. if (dateString) {
  67. const date = new Date(dateString);
  68. const dayOfWeek = date.getDay();
  69. const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  70. return weekdays[dayOfWeek];
  71. } else
  72. return "暂无日期";
  73. };
  74. const getStatus = (value) => {
  75. if (value) {
  76. const data = statusList.value.find((i) => i.dictValue == value);
  77. if (data)
  78. return data.dictLabel;
  79. } else
  80. return "暂无状态";
  81. };
  82. const toPage = () => {
  83. if (total.value > list.value.length) {
  84. common_vendor.index.showLoading({
  85. title: "加载中",
  86. mask: true
  87. });
  88. pageNum.value = pageNum.value + 1;
  89. pageSize.value = pageNum.value * 10;
  90. search();
  91. common_vendor.index.hideLoading();
  92. } else
  93. is_bottom.value = true;
  94. };
  95. const toScroll = (e) => {
  96. let up = scrollTop.value;
  97. scrollTop.value = e.detail.scrollTop;
  98. let num = Math.sign(up - e.detail.scrollTop);
  99. if (num == 1)
  100. is_bottom.value = false;
  101. };
  102. const clearPage = () => {
  103. list.value = [];
  104. pageNum.value = 1;
  105. pageSize.value = 10;
  106. };
  107. return (_ctx, _cache) => {
  108. return common_vendor.e({
  109. a: common_vendor.o([($event) => searchInfo.value.name = $event.detail.value, toInput]),
  110. b: searchInfo.value.name,
  111. c: common_vendor.f(list.value, (item, index, i0) => {
  112. return {
  113. a: index
  114. };
  115. }),
  116. d: common_vendor.f(list.value, (item, index, i0) => {
  117. var _a2, _b, _c, _d, _e, _f;
  118. return common_vendor.e({
  119. a: common_vendor.t(common_vendor.unref(common_vendor.hooks)(item.startTime).format("MM-DD") || "暂无日期"),
  120. b: common_vendor.t(getDayOfWeek(item.startTime)),
  121. c: common_vendor.t(getStatus(item.status)),
  122. d: common_vendor.n(item.status == "0" ? "status0" : item.status == "1" ? "status1" : item.status == "2" ? "status2" : "status3"),
  123. e: item.type == "0"
  124. }, item.type == "0" ? {
  125. f: common_vendor.t(((_a2 = item == null ? void 0 : item.matchInfo) == null ? void 0 : _a2.title) || "友谊赛")
  126. } : {
  127. g: common_vendor.t(((_b = item == null ? void 0 : item.leagueInfo) == null ? void 0 : _b.title) || "联赛")
  128. }, {
  129. h: common_vendor.t(((_c = item == null ? void 0 : item.redInfo) == null ? void 0 : _c.name) || "暂无红方名称"),
  130. i: ((_d = item == null ? void 0 : item.redInfo) == null ? void 0 : _d.logo) || config.value.logoUrl,
  131. j: common_vendor.t(item.redScore || 0),
  132. k: common_vendor.t(item.blueScore || 0),
  133. l: ((_e = item == null ? void 0 : item.blueInfo) == null ? void 0 : _e.logo) || config.value.logoUrl,
  134. m: common_vendor.t(((_f = item == null ? void 0 : item.blueInfo) == null ? void 0 : _f.name) || "暂无蓝方名称"),
  135. n: index,
  136. o: common_vendor.o(($event) => toInfo(item), index)
  137. });
  138. }),
  139. e: is_bottom.value
  140. }, is_bottom.value ? {
  141. f: common_vendor.t(config.value.bottomTitle || "到底了!")
  142. } : {}, {
  143. g: common_vendor.o(toPage),
  144. h: common_vendor.o(toScroll)
  145. });
  146. };
  147. }
  148. });
  149. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2863df91"], ["__file", "D:/project/足球比赛/match_applet/pagesHome/activity/index.vue"]]);
  150. wx.createPage(MiniProgramPage);